CentOS7 虚拟机docker安装宝塔及端口映射

启动docker服务
systemctl start docker
列出所有的容器 ID
docker ps -aq
[[email protected] ~]# docker pull centos
[[email protected] ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/nginx     latest              5a9061639d0a        5 days ago          126 MB
docker.io/centos    latest              0f3e07c0138f        2 weeks ago         220 MB

启动镜像,映射主机与容器内8888端口

docker run -d -it -p 8088:8088 centos

若要映射多个端口,可如下(该方法是在新容器新增映射端口,若想在当前容器修改新增映射端口在文章末尾):

若端口被占用(已映射过),检查下

查看容器id及开启的映射端口,进入容器

[[email protected] ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
ae3bc57f521b        centos              "/bin/bash"              17 minutes ago      Up 17 minutes       0.0.0.0:8088->8088/tcp   practical_brown
2c4cb516025a        nginx               "nginx -g ‘daemon ..."   18 hours ago        Up 18 hours         0.0.0.0:80->80/tcp       wonderful_haibt
[[email protected] ~]# docker port ae3bc57f521b
8088/tcp -> 0.0.0.0:8088
[[email protected] ~]# docker exec -it ae3bc57f521b /bin/bash
[[email protected] /]# 

执行安装命令:

Centos安装脚本 yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh
Ubuntu/Deepin安装脚本 wget -O install.sh http://download.bt.cn/install/install-ubuntu_6.0.sh && sudo bash install.sh
Debian安装脚本 wget -O install.sh http://download.bt.cn/install/install-ubuntu_6.0.sh && bash install.sh
Fedora安装脚本 wget -O install.sh http://download.bt.cn/install/install_6.0.sh && bash install.sh

Bt-Panel: http://222.85.178.178:8888/d4748e88
username: zor1lp17
password: afd9f236

 

ctrl+d可以直接退出容器

[[email protected] /]# exit
[[email protected] ~]#

新启一个容器

[[email protected] ~]# docker run -d -it centos
da5ccb809d79334bf999486e38c6a775515c8079f6080a7f2b2e389ea02d0c68
[[email protected] ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
da5ccb809d79        centos              "/bin/bash"         7 seconds ago       Up 4 seconds                            upbeat_payne

启动已有容器

[[email protected] ~]# docker start ae3bc57f521b
ae3bc57f521b
[[email protected] ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                    NAMES
ae3bc57f521b        centos              "/bin/bash"         27 hours ago        Up 3 seconds        0.0.0.0:8088->8088/tcp   practical_brown

列出所有容器

[[email protected] ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS                    NAMES
da5ccb809d79        centos              "/bin/bash"              19 minutes ago      Exited (0) 10 minutes ago                            upbeat_payne
3a4b31e8f1d8        centos              "/bin/bash"              25 hours ago        Exited (127) 25 hours ago                            boring_morse
28370a2ccfb0        centos              "/bin/bash"              25 hours ago        Exited (255) 17 hours ago   0.0.0.0:81->8888/tcp     suspicious_mclean
49842b304d04        centos              "/bin/bash"              25 hours ago        Created                                              naughty_bartik
50c2dd5365ef        centos              "/bin/bash"              25 hours ago        Created                                              heuristic_pare
2a498ab94de6        centos              "/bin/bash"              25 hours ago        Created                                              priceless_wilson
b5d32605940c        centos              "/bin/bash"              25 hours ago        Created                                              elated_shaw
8317de502b62        centos              "/bin/bash"              25 hours ago        Created                                              angry_ardinghelli
dd78c85618c1        centos              "/bin/bash"              25 hours ago        Created                                              distracted_albattani
0d02c2565a3e        centos              "/bin/bash"              25 hours ago        Created                                              adoring_torvalds
3520c4caa203        centos              "/bin/bash"              25 hours ago        Created                                              wonderful_golick
22d6f9f88a37        centos              "/bin/bash"              26 hours ago        Created                                              flamboyant_wright
9200de9080e9        centos              "/bin/bash"              26 hours ago        Exited (0) 25 hours ago                              sad_sammet
682524e1b5ca        centos              "/bin/bash"              27 hours ago        Exited (0) 25 hours ago                              naughty_kalam
a2552c96ccba        centos              "/bin/bash"              27 hours ago        Created                                              vibrant_swirles
0f8339fcfc31        centos              "/bin/bash"              27 hours ago        Created                                              goofy_meninsky
8835359db7b9        centos              "/bin/bash"              27 hours ago        Created                                              musing_bardeen
ae3bc57f521b        centos              "/bin/bash"              28 hours ago        Up 5 minutes                0.0.0.0:8088->8088/tcp   practical_brown
2c4cb516025a        nginx               "nginx -g ‘daemon ..."   46 hours ago        Exited (0) 25 hours ago                              wonderful_haibt

进入容器

[[email protected] ~]# docker exec -it ae3bc57f521b /bin/bash

启动宝塔

[[email protected] /]# /etc/init.d/bt restart
Stopping Bt-Tasks...	done
Stopping Bt-Panel...	done
Starting Bt-Panel.......	done
Starting Bt-Tasks... 	done

修改映射ip

[[email protected] ~]# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                    NAMES
ae3bc57f521b        centos              "/bin/bash"         28 hours ago        Up 35 minutes       0.0.0.0:8088->8088/tcp   practical_brown

查看ip

也可通过下面方法

[[email protected] ~]# docker inspect ae3bc57f521b

在hostconfig.json文件中找到PortBindings并对其中参数进行修改

{"Binds":null,"ContainerIDFile":"","LogConfig":{"Type":"journald","Config":{}},"NetworkMode":"default","PortBindings":{"8088/tcp":[{"HostIp":"","HostPort":"8088"}]},"RestartPolicy":
{"Name":"no","MaximumRetryCount":0},"AutoRemove":false,"VolumeDriver":"","VolumesFrom":null,"CapAdd":null,"CapDrop":null,"Dns":[],"DnsOptions":[],"DnsSearch":[],"ExtraHosts":null,"G
roupAdd":null,"IpcMode":"","Cgroup":"","Links":[],"OomScoreAdj":0,"PidMode":"","Privileged":false,"PublishAllPorts":false,"ReadonlyRootfs":false,"SecurityOpt":null,"UTSMode":"","Use
rnsMode":"","ShmSize":67108864,"Runtime":"docker-runc","ConsoleSize":[0,0],"Isolation":"","CpuShares":0,"Memory":0,"NanoCpus":0,"CgroupParent":"","BlkioWeight":0,"BlkioWeightDevice"
:null,"BlkioDeviceReadBps":null,"BlkioDeviceWriteBps":null,"BlkioDeviceReadIOps":null,"BlkioDeviceWriteIOps":null,"CpuPeriod":0,"CpuQuota":0,"CpuRealtimePeriod":0,"CpuRealtimeRuntim
e":0,"CpusetCpus":"","CpusetMems":"","Devices":[],"DiskQuota":0,"KernelMemory":0,"MemoryReservation":0,"MemorySwap":0,"MemorySwappiness":-1,"OomKillDisable":false,"PidsLimit":0,"Uli
mits":null,"CpuCount":0,"CpuPercent":0,"IOMaximumIOps":0,"IOMaximumBandwidth":0}

修改后

{"Binds":null,"ContainerIDFile":"","LogConfig":{"Type":"journald","Config":{}},"NetworkMode":"default","PortBindings":{"8088/tcp":[{"HostIp":"","HostPort":"8088"}],"8888/tcp":[{"Hos
tIp":"","HostPort":"8888"}]},"RestartPolicy":{"Name":"no","MaximumRetryCount":0},"AutoRemove":false,"VolumeDriver":"","VolumesFrom":null,"CapAdd":null,"CapDrop":null,"Dns":[],"DnsOp
tions":[],"DnsSearch":[],"ExtraHosts":null,"GroupAdd":null,"IpcMode":"","Cgroup":"","Links":[],"OomScoreAdj":0,"PidMode":"","Privileged":false,"PublishAllPorts":false,"ReadonlyRootf
s":false,"SecurityOpt":null,"UTSMode":"","UsernsMode":"","ShmSize":67108864,"Runtime":"docker-runc","ConsoleSize":[0,0],"Isolation":"","CpuShares":0,"Memory":0,"NanoCpus":0,"CgroupP
arent":"","BlkioWeight":0,"BlkioWeightDevice":null,"BlkioDeviceReadBps":null,"BlkioDeviceWriteBps":null,"BlkioDeviceReadIOps":null,"BlkioDeviceWriteIOps":null,"CpuPeriod":0,"CpuQuot
a":0,"CpuRealtimePeriod":0,"CpuRealtimeRuntime":0,"CpusetCpus":"","CpusetMems":"","Devices":[],"DiskQuota":0,"KernelMemory":0,"MemoryReservation":0,"MemorySwap":0,"MemorySwappiness"
:-1,"OomKillDisable":false,"PidsLimit":0,"Ulimits":null,"CpuCount":0,"CpuPercent":0,"IOMaximumIOps":0,"IOMaximumBandwidth":0}  config.v2.json文件里边

修改完hostconfig.json->PortBindings然后查看config.v2.json文件中的ExposedPorts 和 networsettings端口参数并修改

config.v2.json

修改值 : config->ExposedPorts 和 networsettings->Ports ,

我只找到一个,就只修改一个

{"StreamConfig":{},"State":{"Running":false,"Paused":false,"Restarting":false,"OOMKilled":false,"RemovalInProgress":false,"Dead":false,"Pid":0,"ExitCode":0,"Error":"","StartedAt":"2
019-10-24T02:23:02.237856787Z","FinishedAt":"2019-10-24T03:33:19.19059869Z","Health":null},"ID":"ae3bc57f521ba06c93f3f4760d42990ae14564ea08c9ef1f47ce7d2187296f06","Created":"2019-10
-22T22:27:03.780195819Z","Managed":false,"Path":"/bin/bash","Args":[],"Config":{"Hostname":"ae3bc57f521b","Domainname":"","User":"","AttachStdin":false,"AttachStdout":false,"AttachS
tderr":false,"ExposedPorts":{"8088/tcp":{},"8888/tcp":{}},"Tty":true,"OpenStdin":true,"StdinOnce":false,"Env":["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],"
Cmd":["/bin/bash"],"ArgsEscaped":true,"Image":"centos","Volumes":null,"WorkingDir":"","Entrypoint":null,"OnBuild":null,"Labels":{"org.label-schema.build-date":"20190927","org.label-
schema.license":"GPLv2","org.label-schema.name":"CentOS Base Image","org.label-schema.schema-version":"1.0","org.label-schema.vendor":"CentOS"}},"Image":"sha256:0f3e07c0138fbe05abcb
7a9cc7d63d9bd4c980c3f61fea5efa32e7c4217ef4da","NetworkSettings":{"Bridge":"","SandboxID":"83c66d1b035742a79311643b7f9f0e096f5c79d094242cddb2a86dc29cc22cb1","HairpinMode":false,"Link
LocalIPv6Address":"","LinkLocalIPv6PrefixLen":0,"Networks":{"bridge":{"IPAMConfig":null,"Links":null,"Aliases":null,"NetworkID":"3bc6812d28f49bf0fb2f2dcb3f9f61d1630626fc8771e956cd73
870f97ae4429","EndpointID":"","Gateway":"","IPAddress":"","IPPrefixLen":0,"IPv6Gateway":"","GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"MacAddress":"","IPAMOperational":false}},"
Service":null,"Ports":null,"SandboxKey":"/var/run/docker/netns/83c66d1b0357","SecondaryIPAddresses":null,"SecondaryIPv6Addresses":null,"IsAnonymousEndpoint":true,"HasSwarmEndpoint":
false},"LogPath":"","Name":"/practical_brown","Driver":"overlay2","MountLabel":"system_u:object_r:svirt_sandbox_file_t:s0:c340,c534","ProcessLabel":"system_u:system_r:svirt_lxc_net_
t:s0:c340,c534","RestartCount":0,"HasBeenStartedBefore":true,"HasBeenManuallyStopped":true,"MountPoints":{},"SecretReferences":null,"AppArmorProfile":"","HostnamePath":"/var/lib/doc
ker/containers/ae3bc57f521ba06c93f3f4760d42990ae14564ea08c9ef1f47ce7d2187296f06/hostname","HostsPath":"/var/lib/docker/containers/ae3bc57f521ba06c93f3f4760d42990ae14564ea08c9ef1f47c
e7d2187296f06/hosts","ShmPath":"/var/lib/docker/containers/ae3bc57f521ba06c93f3f4760d42990ae14564ea08c9ef1f47ce7d2187296f06/shm","ResolvConfPath":"/var/lib/docker/containers/ae3bc57
f521ba06c93f3f4760d42990ae14564ea08c9ef1f47ce7d2187296f06/resolv.conf","SeccompProfile":"","NoNewPrivileges":false}

  重启docker和容器,查看映射端口,已设置成功

启动宝塔

物理机访问

原文地址:https://www.cnblogs.com/dnoir/p/11724138.html

时间: 2024-11-05 22:32:44

CentOS7 虚拟机docker安装宝塔及端口映射的相关文章

centos7主要特性 ---docker安装测试

红帽日前正式发布了企业版Linux 7,满足企业当前对数据中心的需求和对下一代的云服务.Containers.大数据的需求,为用户提供军用级安全以及稳定.易用.高效的管理.社区发行版CentOS 7也已经发布出来了,抢先体验docker1.0. rpm -Uvh http://dl.Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm 安装docker      yum install docker-io 启动服务    

Docker修改容器的端口映射和挂载路径

原文:Docker修改容器的端口映射和挂载路径 有时候因为某些原因需要修改容器的配置,如端口映射和挂载路径,但是如果删除容器后再重新运行,那么之前在容器内所做的修改就丢失了,本文提供了两种方法,可以在保留修改的同时修改配置参数. 方法一:将容器保存为镜像 1.停止容器 docker stop CONTAINER 2.将容器保存为新的镜像 docker commit CONTAINER NEWIMAGE:TAG 3.启动新的镜像,此时可以重新指定参数 docker run --name CONTA

Centos7使用Docker安装Gogs源码git仓库

gihub地址:https://github.com/gogs/gogs gogs官网:https://gogs.io/ gihub官方docker安装gogs方法:https://github.com/gogs/gogs/tree/master/docker 我这边另外一篇centos7安装docker的文章:https://www.cnblogs.com/Sungeek/p/9182433.html 搭建环境:centos7+docker+git+Mariadb 最近公司内部需要搭建一个gi

Centos7通过Docker安装Sentry(哨兵)

Docker介绍 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化.容器是完全使用沙箱机制,相互之间不会有任何接口. Docker主要解决什么问题?Docker通过将运行环境和应用程序打包到一起,来解决部署环境依赖问题,真正做到跨平台的分发和使用. 镜像(Image)Docker镜像是一个容器的文件系统,提供容器运行时所需的程序.库.资源.配置等文件和运行时需要的一些配置参数( 如匿名卷.

docker的网络、端口映射和容器间通信

docker作为服务器内部的一个容器单位,对外的通信也就有了困难.这里提供了一些几个解决方案. 1.Docker独立IP 简单说就是配置独立的网桥,分配给docker IP cd /etc/sysconfig/network-scripts/ vi ifcfg-eth0 DEVICE=eth0 BOOTPROTO=none ONBOOT=yes TYPE=Ethernet BRIDGE="br0" BOOTPROTO=static vi ifcfg-br0 DEVICE="b

Centos7.3 Docker安装部署学习记录1

一.Docker基础环境的安装 1. 环境说明 本机采用操作系统如下: CentOS-7.3-X86-64,内核3.10 x64位,docker 1.12.x版本.   建议采用CentOS7版本或ubuntu版本,本文采用CentOS7即CentOS-7-x86_64-DVD-1611.iso版本最小化安装.    Docker可以在虚拟机环境中运行进行使用测试.本文出自:http://koumm.blog.51cto.com/ 2. 主机网络 1)关闭firewalld防火墙和SELinux

centos7之docker安装

下午四点左右,我准备接触docker这个技术.之所以接触它,原因来自tomcat服务器老是挂,也不能说老是挂,一周一次吧,或者不定时,最初出现的问题,分为这么几类? 一类,java代码的问题,某个类导致线程阻塞导致内存泄露,使tomcat突然宕机和某个类找不到异常导致宕机; 二类,java运行环境内存不足,通过调tomcat内存解决该问题,不过这并不能解决这个问题,当然tomcat初始内存的确小,需求适当的调大,但是前提必须符合服务器的配置和内存; 三类,tomcat连接池和线程池的缘故,需要t

DocKer 创建容器 镜像端口映射失败

问题一: 我想使用同一个镜像创建多个容器,并映射端口出现以下错误,该怎么解决? docker: Error response from daemon: driver failed programming external connectivity on endpoint mysql2 (039404f00f8dc0059a1e2f9e1db0e1b5da82a3ae14f3117fbac8af6a0c6fe119): Error starting userland proxy: mkdir /p

使用iptables为docker容器动态添加端口映射

1.将当前iptables的配置写入保存到/etc/sysconfig/iptables 2.保存 /etc/init.d/iptables sava 3.修改iptables配置(vi /etc/sysconfig/iptables): 在适当位置增加下面红色的三行,然后重启iptables即可.(30612 是容器对外提供服务的端口) -A FORWARD -i docker0 -o docker0 -j ACCEPT -A DOCKER -d 172.17.0.10/32 ! -i doc