CentOS7 虚拟机docker安装宝塔及端口映射
启动docker服务
systemctl start docker
列出所有的容器 ID
docker ps -aq
[ ~]# docker pull centos
[ ~]# 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及开启的映射端口,进入容器
[ ~]# 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 [ ~]# docker port ae3bc57f521b 8088/tcp -> 0.0.0.0:8088
[ ~]# docker exec -it ae3bc57f521b /bin/bash [ /]#
执行安装命令:
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可以直接退出容器
[ /]# exit [ ~]#
新启一个容器
[ ~]# docker run -d -it centos da5ccb809d79334bf999486e38c6a775515c8079f6080a7f2b2e389ea02d0c68 [ ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES da5ccb809d79 centos "/bin/bash" 7 seconds ago Up 4 seconds upbeat_payne
启动已有容器
[ ~]# docker start ae3bc57f521b ae3bc57f521b [ ~]# 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
列出所有容器
[ ~]# 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
进入容器
[ ~]# docker exec -it ae3bc57f521b /bin/bash
启动宝塔
[ /]# /etc/init.d/bt restart Stopping Bt-Tasks... done Stopping Bt-Panel... done Starting Bt-Panel....... done Starting Bt-Tasks... done
修改映射ip
[ ~]# 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
也可通过下面方法
[ ~]# 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和容器,查看映射端口,已设置成功
启动宝塔
物理机访问
相关推荐
JustHaveTry 2020-06-21
zwt00 2020-04-29
82143754 2020-04-29
ajuan 2020-04-23
qdqht00 2020-04-20
sxlongwork 2020-03-25
xsg 2020-02-10
linuxisperfect 2020-01-19
杨友山 2020-01-14
tianlong 2020-01-03
yangliuhbhd 2019-12-31
杨友山 2019-12-29
韩学敏 2019-12-15
cuixingwudi 2015-01-26
过儿古墓 2007-07-14
spylyt 2019-11-04
啦啦啦啦啦 2019-10-29