Sample Header Ad - 728x90

Docker communication between containers

2 votes
1 answer
1239 views
Using CoreOS (docker preinstalled), I am failing to make two containers communicate together. I am trying to setup a MySql container called by a Gogs container (Git server). So here is what I did: The port is set with 127.0.0.1 so it cannot be accessible from the outside. > docker run --name mysql1 -v /volumedata/mysql/mysql1:/var/lib/mysql -e > MYSQL_ROOT_PASSWORD=PWDHERE -p 127.0.0.1:33061:3306 -d > mysql/mysql-server:latest --character-set-server=utf8 > --collation-server=utf8_general_ci And then I have installed > docker run --name=go-git-server1 -p 10022:22 -p 10080:3000 -v > /data/go-git-server1:/data gogs/gogs Both of them are running when I check it with **docker ps -a** and I can access to the install page of "go-git-server1" without any problem, however when I specify the host address: 127.0.0.1:33061 on the setup page of Gogs, after validating I have this error: > Database setting is not correct: dial tcp 127.0.0.1:33061: getsockopt: connection refused I thought that with the IP and Port given by "docker ps -a" (and already set manually with the initial "docker run") it would have been sufficient for "go-git-server1" container to access the MySql database. Am I missing a step? Is there something else that we need to do so the MySql container can be accessible from the other container? Here is what docker inspect mysql1 gives: docker inspect mysql1 [ { "Id": "c811d29d866ef977eb0cb93a9697bc4afd2a51e828b7757a5ea8962d784f0166", "Created": "2016-07-03T21:55:29.693884299Z", "Path": "/entrypoint.sh", "Args": [ "-p", "127.0.0.1:33061:3306" ], "State": { "Status": "exited", "Running": false, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 0, "ExitCode": 1, "Error": "", "StartedAt": "2016-07-26T18:23:36.144915853Z", "FinishedAt": "2016-07-26T18:23:38.281589339Z" }, "Image": "4e66d61404cc06e3c40c46f5e83bda5a14dda2838b84210c7eb5a3d6e1f7752b", "ResolvConfPath": "/var/lib/docker/containers/c811d29d866ef977eb0cb93a9697bc4afd2a51e828b7757a5ea8962d784f0166/resolv.conf", "HostnamePath": "/var/lib/docker/containers/c811d29d866ef977eb0cb93a9697bc4afd2a51e828b7757a5ea8962d784f0166/hostname", "HostsPath": "/var/lib/docker/containers/c811d29d866ef977eb0cb93a9697bc4afd2a51e828b7757a5ea8962d784f0166/hosts", "LogPath": "/var/lib/docker/containers/c811d29d866ef977eb0cb93a9697bc4afd2a51e828b7757a5ea8962d784f0166/c811d29d866ef977eb0cb93a9697bc4afd2a51e828b7757a5ea8962d784f0166-json.log", "Name": "/mysql1", "RestartCount": 0, "Driver": "overlay", "ExecDriver": "native-0.2", "MountLabel": "system_u:object_r:svirt_lxc_file_t:s0:c724,c935", "ProcessLabel": "system_u:system_r:svirt_lxc_net_t:s0:c724,c935", "AppArmorProfile": "", "ExecIDs": null, "HostConfig": { "Binds": [ "/donnees/mysql/mysql1:/var/lib/mysql" ], "ContainerIDFile": "", "LxcConf": [], "Memory": 0, "MemoryReservation": 0, "MemorySwap": 0, "KernelMemory": 0, "CpuShares": 0, "CpuPeriod": 0, "CpusetCpus": "", "CpusetMems": "", "CpuQuota": 0, "BlkioWeight": 0, "OomKillDisable": false, "MemorySwappiness": -1, "Privileged": false, "PortBindings": {}, "Links": null, "PublishAllPorts": false, "Dns": [], "DnsOptions": [], "DnsSearch": [], "ExtraHosts": null, "VolumesFrom": null, "Devices": [], "NetworkMode": "default", "IpcMode": "", "PidMode": "", "UTSMode": "", "CapAdd": null, "CapDrop": null, "GroupAdd": null, "RestartPolicy": { "Name": "no", "MaximumRetryCount": 0 }, "SecurityOpt": null, "ReadonlyRootfs": false, "Ulimits": null, "LogConfig": { "Type": "json-file", "Config": {} }, "CgroupParent": "", "ConsoleSize": [ 0, 0 ], "VolumeDriver": "" }, "GraphDriver": { "Name": "overlay", "Data": { "LowerDir": "/var/lib/docker/overlay/4e66d61404cc06e3c40c46f5e83bda5a14dda2838b84210c7eb5a3d6e1f7752b/root", "MergedDir": "/var/lib/docker/overlay/c811d29d866ef977eb0cb93a9697bc4afd2a51e828b7757a5ea8962d784f0166/merged", "UpperDir": "/var/lib/docker/overlay/c811d29d866ef977eb0cb93a9697bc4afd2a51e828b7757a5ea8962d784f0166/upper", "WorkDir": "/var/lib/docker/overlay/c811d29d866ef977eb0cb93a9697bc4afd2a51e828b7757a5ea8962d784f0166/work" } }, "Mounts": [ { "Source": "/donnees/mysql/mysql1", "Destination": "/var/lib/mysql", "Mode": "", "RW": true } ], "Config": { "Hostname": "c811d29d866e", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": false, "AttachStderr": false, "ExposedPorts": { "3306/tcp": {}, "33060/tcp": {} }, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "MYSQL_ROOT_PASSWORD=mypwd", "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", "PACKAGE_URL=https://repo.mysql.com/yum/mysql-5.7-community/docker/x86_64/mysql-community-server-minimal-5.7.13-1.el7.x86_64.rpm " ], "Cmd": [ "-p", "127.0.0.1:33061:3306" ], "Image": "mysql/mysql-server:latest", "Volumes": { "/var/lib/mysql": {} }, "WorkingDir": "", "Entrypoint": [ "/entrypoint.sh" ], "OnBuild": null, "Labels": {}, "StopSignal": "SIGTERM" }, "NetworkSettings": { "Bridge": "", "SandboxID": "", "HairpinMode": false, "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "Ports": null, "SandboxKey": "", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null, "EndpointID": "", "Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "IPAddress": "", "IPPrefixLen": 0, "IPv6Gateway": "", "MacAddress": "", "Networks": { "bridge": { "EndpointID": "", "Gateway": "", "IPAddress": "", "IPPrefixLen": 0, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "" } } } } ] I have tried the ip given by ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+' ...instead the 127.0.0.1 that failed, but no, it doesn't work. It seems I am kind of stuck at the first step of docker container communication.
Asked by Micaël Félix (121 rep)
Jul 26, 2016, 10:07 PM
Last activity: Nov 15, 2020, 08:04 PM