运维篇-虚拟机docker宝塔安装及端口映射

Posted Web安全进阶之路

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了运维篇-虚拟机docker宝塔安装及端口映射相关的知识,希望对你有一定的参考价值。

宝塔简介:宝塔面板是一款服务器管理软件,支持windows和linux系统,可以通过Web端轻松管理服务器,提升运维效率。例如:创建管理网站、FTP、数据库,拥有可视化文件管理器,可视化软件管理器,可视化CPU、内存、流量监控图表,计划任务等功能。

启动docker服务

systemctl start docker
列出所有的容器 ID
docker ps -aq
[root@localhost ~]# docker pull centos
[root@localhost ~]# 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

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

运维篇-虚拟机docker宝塔安装及端口映射

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

运维篇-虚拟机docker宝塔安装及端口映射

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

[root@localhost ~]# 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
[root@localhost ~]# docker port ae3bc57f521b
8088/tcp -> 0.0.0.0:8088
[root@localhost ~]# docker exec -it ae3bc57f521b /bin/bash
[root@ae3bc57f521b /]#

执行安装命令:

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

运维篇-虚拟机docker宝塔安装及端口映射

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

运维篇-虚拟机docker宝塔安装及端口映射 运维篇-虚拟机docker宝塔安装及端口映射

ctrl+d可以直接退出容器

[root@3a4b31e8f1d8 /]# exit
[root@localhost ~]#
 

修改映射ip

[root@localhost ~]# 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宝塔安装及端口映射

也可通过下面方法

[root@localhost ~]# docker inspect ae3bc57f521b

运维篇-虚拟机docker宝塔安装及端口映射

 运维篇-虚拟机docker宝塔安装及端口映射

 运维篇-虚拟机docker宝塔安装及端口映射

{"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文件里边

config.v2.json

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

运维篇-虚拟机docker宝塔安装及端口映射

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

运维篇-虚拟机docker宝塔安装及端口映射

{"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和容器,查看映射端口,已设置成功

运维篇-虚拟机docker宝塔安装及端口映射

 启动宝塔

运维篇-虚拟机docker宝塔安装及端口映射

 物理机访问

运维篇-虚拟机docker宝塔安装及端口映射

 

 

 

 


以上是关于运维篇-虚拟机docker宝塔安装及端口映射的主要内容,如果未能解决你的问题,请参考以下文章

Docker 核心概念安装端口映射及常用操作命令,详细到令人发指。

运维篇Docker知识点万字吐血大总结,学完阿里叫我明天去入职

Mac在Docker里的CentOS安装宝塔面板

架构运维篇:MySQL 8.0启用BinLog 支持

高效运维篇本地工具访问:安全高效合规的IT资源远程访问

Docker端口映射与进入容器内部