我运行一个docker镜像busybox和docker-compose是dnmp,dnmp可以在github上找到。
#显示我当前运行容器,dnmp开头的容器是可以互相访问的,可以通过ip或者名字。
liusuwanqing@ken:~$ sudo docker container ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7214f7c8f6a2 busybox "/bin/sh" About a minute ago Up About a minute cranky_chebyshev
4a02568f420e mysql:8.0 "docker-entrypoint.s…" 43 minutes ago Up 20 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp dnmp_mysql_1_f57b6a1eb2d0
91ab9566f2d8 redis:alpine "docker-entrypoint.s…" 2 hours ago Up 20 minutes 0.0.0.0:6379->6379/tcp dnmp_redis_1_83817e8d6d2b
e248531ec66f nginx:alpine "nginx -g 'daemon of…" 2 hours ago Up 20 minutes 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp dnmp_nginx_1_9fc11fa7effa
c74f15f3f4a3 dnmp_php72 "docker-php-entrypoi…" 2 hours ago Up 20 minutes 9000/tcp dnmp_php72_1_e4b3f6db9460
47e767870da3 dnmp_php56 "docker-php-entrypoi…" 2 hours ago Up 20 minutes 9000/tcp dnmp_php56_1_18d27b9a2cc5
21f3e74270f5 erikdubbelboer/phpredisadmin:latest "php -S 0.0.0.0:80" 2 hours ago Up 20 minutes 0.0.0.0:8081->80/tcp dnmp_phpredisadmin_1_5e3bb136dc5b
10eb0fb59dc6 dnmp_php54 "php-fpm" 2 hours ago Up 20 minutes 9000/tcp dnmp_php54_1_cbdddc1f3208
7552d764b3de phpmyadmin/phpmyadmin:latest "/run.sh supervisord…" 2 hours ago Up 20 minutes 9000/tcp, 0.0.0.0:8080->80/tcp dnmp_phpmyadmin_1_fd161800d20f
分别查看busybox和mysql容器有什么区别,使用容器id进行查看。留意他们的Networks,busybox的network是bridge,而mysql容器的network是dnmp_default。他们是两个不通网络空间!!!docker中两个不同网络默认是不允许通讯的,如果要通讯需要特殊的处理!!这样可以做到容器的互相隔离!!!他们网段也是不一样的,busybox和mysql分别是17网段和18网段。
liusuwanqing@ken:~$ sudo docker inspect 7214f7c8f6a2
"Id": "7214f7c8f6a2facfdcf53ab69814ccd9270171f1480be47d64ec9921898d3a60",
"Created": "2018-11-21T08:42:16.140468492Z",
"Path": "/bin/sh",
"Args": [],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 124859,
"ExitCode": 0,
"Error": "",
"StartedAt": "2018-11-21T08:42:18.371304141Z",
"FinishedAt": "0001-01-01T00:00:00Z"
"Image": "sha256:59788edf1f3e78cd0ebe6ce1446e9d10788225db3dedcfd1a59f764bad2b2690",
"ResolvConfPath": "/var/lib/docker/containers/7214f7c8f6a2facfdcf53ab69814ccd9270171f1480be47d64ec9921898d3a60/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/7214f7c8f6a2facfdcf53ab69814ccd9270171f1480be47d64ec9921898d3a60/hostname",
"HostsPath": "/var/lib/docker/containers/7214f7c8f6a2facfdcf53ab69814ccd9270171f1480be47d64ec9921898d3a60/hosts",
"LogPath": "/var/lib/docker/containers/7214f7c8f6a2facfdcf53ab69814ccd9270171f1480be47d64ec9921898d3a60/7214f7c8f6a2facfdcf53ab69814ccd9270171f1480be47d64ec9921898d3a60-json.log",
"Name": "/cranky_chebyshev",
"RestartCount": 0,
"Driver": "aufs",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "docker-default",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
"NetworkMode": "default",
"PortBindings": {},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "shareable",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
"ReadonlyPaths": [
"/proc/asound",
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
"GraphDriver": {
"Data": null,
"Name": "aufs"
"Mounts": [],
"Config": {
"Hostname": "7214f7c8f6a2",
"Domainname": "",
"User": "",
"AttachStdin": true,
"AttachStdout": true,
"AttachStderr": true,
"Tty": true,
"OpenStdin": true,
"StdinOnce": true,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
"Cmd": [
"/bin/sh"
"Image": "busybox",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {}
"NetworkSettings": {
"Bridge": "",
"SandboxID": "efd3e86227038ae1c82c8662c091bf6d754726d83a654c429918313177b766db",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/efd3e8622703",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "4d8f6671e34f5a46120862eb76edb6186ca22ba994a1eec4ef50b755b38f82a6",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "146bacc8c450741db44a70a0a6482e4a7eb4622615c5c51b4c1cda02478ca1fe",
"EndpointID": "4d8f6671e34f5a46120862eb76edb6186ca22ba994a1eec4ef50b755b38f82a6",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
liusuwanqing@ken:~$ sudo docker inspect 4a02568f420e
"Id": "4a02568f420e1fcc56147cd5b45440f8ef4699e689e6890ec517a576da01cae3",
"Created": "2018-11-21T08:00:26.724258311Z",
"Path": "docker-entrypoint.sh",
"Args": [
"mysqld"
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 122997,
"ExitCode": 0,
"Error": "",
"StartedAt": "2018-11-21T08:23:42.882186953Z",
"FinishedAt": "2018-11-21T08:23:01.261052399Z"
"Image": "sha256:f991c20cb5087fdd01fa7a2181f0a123a54d697681cf3723370bf50566d2e7cf",
"ResolvConfPath": "/var/lib/docker/containers/4a02568f420e1fcc56147cd5b45440f8ef4699e689e6890ec517a576da01cae3/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/4a02568f420e1fcc56147cd5b45440f8ef4699e689e6890ec517a576da01cae3/hostname",
"HostsPath": "/var/lib/docker/containers/4a02568f420e1fcc56147cd5b45440f8ef4699e689e6890ec517a576da01cae3/hosts",
"LogPath": "/var/lib/docker/containers/4a02568f420e1fcc56147cd5b45440f8ef4699e689e6890ec517a576da01cae3/4a02568f420e1fcc56147cd5b45440f8ef4699e689e6890ec517a576da01cae3-json.log",
"Name": "/dnmp_mysql_1_f57b6a1eb2d0",
"RestartCount": 0,
"Driver": "aufs",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "docker-default",
"ExecIDs": null,
"HostConfig": {
"Binds": [
"/home/liusuwanqing/dnmp/mysql:/var/lib/mysql:rw"
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
"NetworkMode": "dnmp_default",
"PortBindings": {
"3306/tcp": [
"HostIp": "",
"HostPort": "3306"
"RestartPolicy": {
"Name": "always",
"MaximumRetryCount": 0
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": [],
"CapAdd": null,
"CapDrop": null,
"Dns": null,
"DnsOptions": null,
"DnsSearch": null,
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "shareable",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
"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,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": null,
"DeviceCgroupRules": null,
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
"ReadonlyPaths": [
"/proc/asound",
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
"GraphDriver": {
"Data": null,
"Name": "aufs"
"Mounts": [
"Type": "bind",
"Source": "/home/liusuwanqing/dnmp/mysql",
"Destination": "/var/lib/mysql",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
"Config": {
"Hostname": "4a02568f420e",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"3306/tcp": {},
"33060/tcp": {}
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"MYSQL_ROOT_PASSWORD=123456",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"GOSU_VERSION=1.7",
"MYSQL_MAJOR=8.0",
"MYSQL_VERSION=8.0.13-1debian9"
"Cmd": [
"mysqld"
"ArgsEscaped": true,
"Image": "mysql:8.0",
"Volumes": {
"/var/lib/mysql": {}
"WorkingDir": "",
"Entrypoint": [
"docker-entrypoint.sh"
"OnBuild": null,
"Labels": {
"com.docker.compose.config-hash": "027056cf672015aaee8e57268caf830ab86ca53b7f77703e816f6d136bcb2231",
"com.docker.compose.container-number": "1",
"com.docker.compose.oneoff": "False",
"com.docker.compose.project": "dnmp",
"com.docker.compose.service": "mysql",
"com.docker.compose.slug": "f57b6a1eb2d07eac7bae3b25a7285d68cf21326b5df6032d99fd3a26642b240",
"com.docker.compose.version": "1.23.1"
"NetworkSettings": {
"Bridge": "",
"SandboxID": "3affc5b2aafc2b065d3bfb1af105a33b92243d0e598402572f032d41d1fca0a0",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"3306/tcp": [
"HostIp": "0.0.0.0",
"HostPort": "3306"
"33060/tcp": null
"SandboxKey": "/var/run/docker/netns/3affc5b2aafc",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"dnmp_default": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"4a02568f420e",
"mysql"
"NetworkID": "d81d6a629af7e1a948edc4372b64c98abf62b13326e43e1b759ff15b22d3a24b",
"EndpointID": "7f4a0f468ab632042f54e9718d320ba7b009d92879e7f79940460084278651c3",
"Gateway": "172.18.0.1",
"IPAddress": "172.18.0.7",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:12:00:07",
"DriverOpts": null
再查看是否存在这个两个网络空间,的确是存在的,docker的网络是重点,这篇主要自己对比一下,做做笔记。
liusuwanqing@ken:~$ sudo docker network ls
[sudo] password for liusuwanqing:
NETWORK ID NAME DRIVER SCOPE
146bacc8c450 bridge bridge local
d81d6a629af7 dnmp_default bridge local
aed22d019943 host host local
d59dc471b94b none null local
我运行一个docker镜像busybox和docker-compose是dnmp,dnmp可以在github上找到。#显示我当前运行容器,dnmp开头的容器是可以互相访问的,可以通过ip或者名字。liusuwanqing@ken:~$ sudo docker container psCONTAINER ID IMAGE ...
2、link容器别名访问(ps: 官方文档中已经不推荐使用)
3、同一自定义网络下可通过容器名访问
4.docker compose部署可通过service服务名访问(单机)
5.docker swarm 可通过service服务名访问(多主机集群 跨主机通讯)
去翻了下docker-entrypoint发现是ping db命令ping不通。
docker有着内部的dns,db这个域名会被解析成如172.18.0.4这样的内部地址,ping db不通那显然是ip不通的原因。
可问题是,我ctfd的ip是172.18.0.4/24,显然和db的ip在同一网段,但却不通,这是什么原因呢?
看了下这篇文章:
https://maximorlov.com/4-reasons-w
Docker version 1.13.1, build 7d71120/1.13.1
容器间通讯
由于是分布式环境,各个服务之间是需要进行通讯的,所以这里需要配置docker的网络,保证各个容器之间网络互通,确保服务正常地调用。
Dokcer在安装的时候,会默认创建一个内部的桥接网络d
一、docker中运行的不同容器之间是允许网络互通的,可以通过–icc=false 来关闭容器之间的通信
打开启动服务文件:vim /usr/lib/systemd/system/docker.service
在ExecStart中添加–icc=false
重启服务:systemctl restart docker
运行两个容器:
docker run -d -h web1 nginx_php:...
文章目录MySQL的安装与配置
Docker 安装 MySQL快速启动一个 MySQL 服务实例使用
docker-compose 部署MySQL
MySQL的安装与配置
Docker 安装 MySQL
通过
Docker 搭建 MySQL 数据库环境,同时能同时启动多个 MySQL 版本。在安装前,最好上
docker 官网上看一下 MySQL 的版本,更具具体需求版本安装 MySQL,假设你已经搭建好
Docker 环境下面介绍如何创建一个 MySQL
服务器实例。
快速启动一个 MySQL 服务实例
Docker网络&容器通信参考之前的rhel7-up和busybox的例子
为什么资源的隔离和限制在云时代更加重要?在默认情况下,一个操作系统里所有运行的进程共享CPU和内存资源,
如果程序设计不当,最极端的情况,某进程出现死循环可能会耗尽CPU资源,或者由于内存泄漏消耗掉大部分系统资源,
这在企业级产品场景下是不可接受的,所以进程的资源隔离技术是非常必要的
Linux操作系统本身从操作系统层面就支持虚拟化技术,叫做Linux container,也就是大家到处能看到的LXC的全称
LXC的三大特色
解决方案:
netstat -nap 查找3306端口 查看程序运行的pid,发现确实被占用了,记住PID
直接找到这个端口是否被占用,命令:netstat -nap | grep 3306
kill PID 杀死该进程 ,这里是kill 1107
2.数据库的配置问题
在window11系统上,使用VMware Workstation软件,配置的虚拟机
虚拟机系统为centos7,配置有
docker容器。并在
docker容器
中配置的mysql数据库
(base) [root@192 ~]#
docker ps
CONTAINER ID IMAGE