Connection problem between two containers

I’m trying to run wordpress using two containers.
There are many tutorials out there. I’ve used this one: https://www.hostinger.com/tutorials/run-docker-wordpress

For some reason WordPress container can’t communicate with the mysql container.
going to localhost:8000 I get this message:

Error establishing a database connection

I thought that’s why we have docker0 (for communication between containers) but a new bridge network is always being created (should it be created?) when running docker-compose…

I’ll appreciate any assistance.

Some additional info:

docker container ls

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2bb0b6311f4e wordpress:latest “docker-entrypoint.s…” About an hour ago Up About an hour 0.0.0.0:8000->80/tcp wordpress3_wordpress_1
6b3b81afd103 mysql:5.7 “docker-entrypoint.s…” About an hour ago Up About an hour 3306/tcp, 33060/tcp wordpress3_db_1

docker inspect -f ‘{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}’ 2bb0b6311f4e
172.18.0.3

docker inspect -f ‘{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}’ 6b3b81afd103
172.18.0.2

**SQL is accessible from host **

telnet 172.18.0.2 3306
Trying 172.18.0.2…
Connected to 172.18.0.2.
Escape character is ‘^]’.

WordPress is accessible from host
telnet 172.18.0.3 80
Trying 172.18.0.3…
Connected to 172.18.0.3.
Escape character is ‘^]’.

ifconfig
br-b9e08cdbb0cb: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.18.0.1 netmask 255.255.0.0 broadcast 172.18.255.255
inet6 fe80::42:8fff:fe15:91a prefixlen 64 scopeid 0x20
ether 02:42:8f:15:09:1a txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
inet6 fe80::42:7ff:feab:7267 prefixlen 64 scopeid 0x20
ether 02:42:07:ab:72:67 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 9 bytes 612 (612.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

enp7s0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether f8:75:a4:31:51:b1 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1000 (Local Loopback)
RX packets 23 bytes 10606 (10.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 23 bytes 10606 (10.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

veth1dfb2aa: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::4463:2ff:fe62:a0b4 prefixlen 64 scopeid 0x20
ether 46:63:02:62:a0:b4 txqueuelen 0 (Ethernet)
RX packets 42 bytes 8728 (8.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 272 bytes 47062 (45.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

vethbc11a6b: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::fc02:61ff:feb7:c59e prefixlen 64 scopeid 0x20
ether fe:02:61:b7:c5:9e txqueuelen 0 (Ethernet)
RX packets 13 bytes 909 (909.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 248 bytes 42148 (41.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

wlp0s20f3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.20.133 netmask 255.255.255.0 broadcast 192.168.20.255
inet6 fe80::87c9:de80:d5c4:e35b prefixlen 64 scopeid 0x20
ether 4c:1d:96:05:98:1c txqueuelen 1000 (Ethernet)
RX packets 486776 bytes 494587671 (471.6 MiB)
RX errors 0 dropped 216 overruns 0 frame 0
TX packets 187466 bytes 32715850 (31.2 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.20.254 0.0.0.0 UG 0 0 0 wlp0s20f3
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
172.18.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-b9e08cdbb0cb
192.168.20.0 0.0.0.0 255.255.255.0 U 0 0 0 wlp0s20f3

docker network ls
NETWORK ID NAME DRIVER SCOPE
82b5f6ce9037 bridge bridge local
b13c58426fa4 host host local
141d06d6193a none null local
b9e08cdbb0cb wordpress3_default bridge local

This is not a network problem, if you use the compose file from this tutorial the two containers are attached to the same network and are accessible with their names (db and wordpress). Go to the db container and try if you can access MySQL from there, then go to the wordpress container and try to access the db again (at host db). Use the mysql command line tool to really access the database and not telnet.
There was a similar question not so long ago and my guess what that it could be a timing problem at startup, but I never received any feedback. Maybe the best is to delete the volume db_data and start again.
And then please don’t add any restart parameters to a compose file as long as the system isn’t working. I know you see this in 90 % of the tutorials…

I’m not convinced the article is correct for all OSes. I suggest adding the containers to the same Docker network to ensure the names resolve correctly. But you’d then struggle to do any real work in WordPress - restarting the containers would reinstall WP again.

This is not necessary if the containers are started with the same compose file. Then they automatically share the same network.

In my opinion the starting point for a wordpress setup should be the the docs of the official image on dockerhub. There we see that for wordpress it is necessary to create 2 volumes for persistent data, one for /var/www/html in the wp container and one for /var/lib/mysql in the db. The first one is missing in the tutorial linked in the first post.

Thanks tekki.

Following your suggestion, I managed to run mysql on the db container.
But I don’t know how to access it from the wordpress container - there’s no ping, telnet, mysql or any other command I found on that container that I can use. Is there another command I can use?

db container
$ docker exec -it 6b3b81afd103 /bin/bash
root@6b3b81afd103:/# mysql -u wordpress -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.30 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> show databases;
±-------------------+
| Database |
±-------------------+
| information_schema |
| wordpress |
±-------------------+
2 rows in set (0.00 sec)

mysql>

wordpress container
$ docker exec -it 2bb0b6311f4e /bin/bash
root@2bb0b6311f4e:/var/www/html# ping db
bash: ping: command not found
root@2bb0b6311f4e:/var/www/html# telnet
bash: telnet: command not found
root@2bb0b6311f4e:/var/www/html# traceroute
bash: traceroute: command not found
root@2bb0b6311f4e:/var/www/html# route
bash: route: command not found
root@2bb0b6311f4e:/var/www/html# arp
bash: arp: command not found
root@2bb0b6311f4e:/var/www/html# netstat
bash: netstat: command not found
root@2bb0b6311f4e:/var/www/html#

I think that network wise (at least docker’s network) the connectivity exist - see details below.
One more piece of information that is pointing to the network environment on the host:
I have added a VM (Ububtu) on the host and on that VM I ran the same docker file. everything works there.
hence, on a clean new network (the VM’s network) everything runs smoothly.

[liran@localhost ~]$ docker network ls
NETWORK ID NAME DRIVER SCOPE
7935fbb86a03 bridge bridge local
b13c58426fa4 host host local
141d06d6193a none null local
b9e08cdbb0cb wordpress3_default bridge local
[liran@localhost ~]$ docker network inspect b9e08cdbb0cb
[
{
“Name”: “wordpress3_default”,
“Id”: “b9e08cdbb0cb1ceada3ae49f364c3f70ee8308b3b4a1d679654bd2a98f94f8ff”,
“Created”: “2020-07-07T12:00:53.946493527+03:00”,
“Scope”: “local”,
“Driver”: “bridge”,
“EnableIPv6”: false,
“IPAM”: {
“Driver”: “default”,
“Options”: null,
“Config”: [
{
“Subnet”: “172.18.0.0/16”,
“Gateway”: “172.18.0.1”
}
]
},
“Internal”: false,
“Attachable”: true,
“Ingress”: false,
“ConfigFrom”: {
“Network”: “”
},
“ConfigOnly”: false,
“Containers”: {
“2bb0b6311f4efa5788e94456e4d5973f49cf8bda91b32a2f5986fff3c3f42b24”: {
“Name”: “wordpress3_wordpress_1”,
“EndpointID”: “e8c60264a2afadd102013dcc5e7a3acdb5b1aefb690bb9c0835a65f65ae3be33”,
“MacAddress”: “02:42:ac:12:00:02”,
“IPv4Address”: “172.18.0.2/16”,
“IPv6Address”: “”
},
“6b3b81afd1033f6bfa5f29c0eefdddffb3ec2e45927002273c1b69f25b2a8bba”: {
“Name”: “wordpress3_db_1”,
“EndpointID”: “f22c7c982c8b50459d43ec07c5745f5c1d2a34dd2cd5cc3fb31aaa5fda2f3391”,
“MacAddress”: “02:42:ac:12:00:03”,
“IPv4Address”: “172.18.0.3/16”,
“IPv6Address”: “”
}
},
“Options”: {},
“Labels”: {
“com.docker.compose.network”: “default”,
“com.docker.compose.project”: “wordpress3”,
“com.docker.compose.version”: “1.25.0”
}
}
]

Did you see my last post? You definitely have to use the compose file from Dockerhub and not from the turorial (and comment out or delete the restart parameters, of course).
I recommend that you delete your existing volumes and start from scratch. Some days ago I was able to reproduce the ‘access denied’ error, but today everything worked. Typed

$ docker-compose up

and waited until the output got silent. To be correct during the process there were some

wordpress_1  | MySQL Connection Error: (2002) Connection refused 

errors, but when the initialization of the database had finished I was able to open Wordpress in the browser.

Edit:
Make sure you have the most recent Wordpress image:

$ docker image pull wordpress

Both options did not work.

Option 1: removing “restart” from tutorial docker file & removing/cleaning existing docker storage
Option 2: using official community WordPress from docker-hub

Since both docker-files (from tutorial and official) works on a clean VM, there is something else we are missing.
it could be fw (although I’ve added docker0 to trusted zone) - maybe I should add the new generated network to trusted zone or there is some routing misconfiguration in the host level or the docker level.
this is a riddle… :thinking:

Both result the same error -

Error establishing a database connection

Option1 - tutorial dockerfile
$ docker volume ls
DRIVER VOLUME NAME
local 295527222ca382a6f31c571a85d492f7d68042eea51aadb222b65aa122ab4f38
local wordpress3_db_data
[liran@localhost wordpress3]$ docker volume rm wordpress3_db_data
wordpress3_db_data

docker-compose up
Creating volume “wordpress3_db_data” with default driver
Creating wordpress3_db_1 … done
Creating wordpress3_wordpress_1 … done
Attaching to wordpress3_db_1, wordpress3_wordpress_1
db_1 | 2020-07-11 10:02:41+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.30-1debian10 started.
db_1 | 2020-07-11 10:02:41+00:00 [Note] [Entrypoint]: Switching to dedicated user ‘mysql’
db_1 | 2020-07-11 10:02:41+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.30-1debian10 started.
wordpress_1 | WordPress not found in /var/www/html - copying now…
db_1 | 2020-07-11 10:02:41+00:00 [Note] [Entrypoint]: Initializing database files
removing some lines - response length limitation
db_1 | 2020-07-11T10:02:49.028525Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1 | 2020-07-11T10:02:49.029561Z 0 [Note] mysqld (mysqld 5.7.30) starting as process 1 …
db_1 | 2020-07-11T10:02:49.031938Z 0 [Note] InnoDB: PUNCH HOLE support available
db_1 | 2020-07-11T10:02:49.031947Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1 | 2020-07-11T10:02:49.031949Z 0 [Note] InnoDB: Uses event mutexes
db_1 | 2020-07-11T10:02:49.031951Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
db_1 | 2020-07-11T10:02:49.031953Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
db_1 | 2020-07-11T10:02:49.031955Z 0 [Note] InnoDB: Using Linux native AIO
db_1 | 2020-07-11T10:02:49.032226Z 0 [Note] InnoDB: Number of pools: 1
db_1 | 2020-07-11T10:02:49.032312Z 0 [Note] InnoDB: Using CPU crc32 instructions
db_1 | 2020-07-11T10:02:49.033658Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
db_1 | 2020-07-11T10:02:49.041011Z 0 [Note] InnoDB: Completed initialization of buffer pool
db_1 | 2020-07-11T10:02:49.042869Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
db_1 | 2020-07-11T10:02:49.054577Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
db_1 | 2020-07-11T10:02:49.060319Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db_1 | 2020-07-11T10:02:49.060474Z 0 [Note] InnoDB: Setting file ‘./ibtmp1’ size to 12 MB. Physically writing the file full; Please wait …
db_1 | 2020-07-11T10:02:49.071407Z 0 [Note] InnoDB: File ‘./ibtmp1’ size is now 12 MB.
db_1 | 2020-07-11T10:02:49.071984Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
db_1 | 2020-07-11T10:02:49.071990Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
db_1 | 2020-07-11T10:02:49.072502Z 0 [Note] InnoDB: Waiting for purge to start
db_1 | 2020-07-11T10:02:49.123292Z 0 [Note] InnoDB: 5.7.30 started; log sequence number 12488234
db_1 | 2020-07-11T10:02:49.123497Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db_1 | 2020-07-11T10:02:49.123636Z 0 [Note] Plugin ‘FEDERATED’ is disabled.
db_1 | 2020-07-11T10:02:49.125104Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200711 10:02:49
db_1 | 2020-07-11T10:02:49.127045Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
db_1 | 2020-07-11T10:02:49.127052Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
db_1 | 2020-07-11T10:02:49.127597Z 0 [Warning] CA certificate ca.pem is self signed.
db_1 | 2020-07-11T10:02:49.127617Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
db_1 | 2020-07-11T10:02:49.127986Z 0 [Note] Server hostname (bind-address): ‘*’; port: 3306
db_1 | 2020-07-11T10:02:49.128012Z 0 [Note] IPv6 is available.
db_1 | 2020-07-11T10:02:49.128019Z 0 [Note] - ‘::’ resolves to ‘::’;
db_1 | 2020-07-11T10:02:49.128031Z 0 [Note] Server socket created on IP: ‘::’.
db_1 | 2020-07-11T10:02:49.129590Z 0 [Warning] Insecure configuration for --pid-file: Location ‘/var/run/mysqld’ in the path is accessible to all OS users. Consider choosing a different directory.
db_1 | 2020-07-11T10:02:49.134989Z 0 [Note] Event Scheduler: Loaded 0 events
db_1 | 2020-07-11T10:02:49.135215Z 0 [Note] mysqld: ready for connections.
db_1 | Version: ‘5.7.30’ socket: ‘/var/run/mysqld/mysqld.sock’ port: 3306 MySQL Community Server (GPL)
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) No route to host
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) No route to host
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) No route to host
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) No route to host
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) No route to host
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) No route to host
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) No route to host
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) No route to host
wordpress_1 |
wordpress_1 | WARNING: unable to establish a database connection to ‘db:3306’
wordpress_1 | continuing anyways (which might have unexpected results)
wordpress_1 |
wordpress_1 | AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 172.18.0.3. Set the ‘ServerName’ directive globally to suppress this message
wordpress_1 | AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 172.18.0.3. Set the ‘ServerName’ directive globally to suppress this message
wordpress_1 | [Sat Jul 11 10:03:20.262378 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.4.7 configured – resuming normal operations
wordpress_1 | [Sat Jul 11 10:03:20.262454 2020] [core:notice] [pid 1] AH00094: Command line: ‘apache2 -D FOREGROUND’

option2 - official
$docker volume ls
DRIVER VOLUME NAME
[liran@localhost wordpress4]$ docker-compose up
Creating network “wordpress4_default” with the default driver
Creating volume “wordpress4_wordpress” with default driver
Creating volume “wordpress4_db” with default driver
Creating wordpress4_db_1 … done
Creating wordpress4_wordpress_1 … done
Attaching to wordpress4_db_1, wordpress4_wordpress_1
db_1 | 2020-07-11 10:26:15+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.30-1debian10 started.
db_1 | 2020-07-11 10:26:15+00:00 [Note] [Entrypoint]: Switching to dedicated user ‘mysql’
db_1 | 2020-07-11 10:26:15+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.30-1debian10 started.
wordpress_1 | WordPress not found in /var/www/html - copying now…
db_1 | 2020-07-11 10:26:15+00:00 [Note] [Entrypoint]: Initializing database files
db_1 | 2020-07-11T10:26:15.456734Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
wordpress_1 | Complete! WordPress has been successfully copied to /var/www/html
db_1 | 2020-07-11T10:26:15.584226Z 0 [Warning] InnoDB: New log files created, LSN=45790
db_1 | 2020-07-11T10:26:15.607410Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
db_1 | 2020-07-11T10:26:15.662589Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: f36ed7ab-c360-11ea-8eb1-0242ac140002.
db_1 | 2020-07-11T10:26:15.663761Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
db_1 | 2020-07-11T10:26:16.027076Z 0 [Warning] CA certificate ca.pem is self signed.
db_1 | 2020-07-11T10:26:16.106619Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
wordpress_1 | [11-Jul-2020 10:26:16 UTC] PHP Warning: mysqli::__construct(): (HY000/2002): No route to host in Standard input code on line 22
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) No route to host
db_1 | 2020-07-11 10:26:18+00:00 [Note] [Entrypoint]: Database files initialized
db_1 | 2020-07-11 10:26:18+00:00 [Note] [Entrypoint]: Starting temporary server
db_1 | 2020-07-11 10:26:18+00:00 [Note] [Entrypoint]: Waiting for server startup
db_1 | 2020-07-11T10:26:18.688780Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1 | 2020-07-11T10:26:18.689865Z 0 [Note] mysqld (mysqld 5.7.30) starting as process 79 …
db_1 | 2020-07-11T10:26:18.692094Z 0 [Note] InnoDB: PUNCH HOLE support available
db_1 | 2020-07-11T10:26:18.692104Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1 | 2020-07-11T10:26:18.692107Z 0 [Note] InnoDB: Uses event mutexes
db_1 | 2020-07-11T10:26:18.692109Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
db_1 | 2020-07-11T10:26:18.692111Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
db_1 | 2020-07-11T10:26:18.692113Z 0 [Note] InnoDB: Using Linux native AIO
db_1 | 2020-07-11T10:26:18.692377Z 0 [Note] InnoDB: Number of pools: 1
db_1 | 2020-07-11T10:26:18.692498Z 0 [Note] InnoDB: Using CPU crc32 instructions
db_1 | 2020-07-11T10:26:18.693850Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
db_1 | 2020-07-11T10:26:18.701161Z 0 [Note] InnoDB: Completed initialization of buffer pool
db_1 | 2020-07-11T10:26:18.702765Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
db_1 | 2020-07-11T10:26:18.714203Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
db_1 | 2020-07-11T10:26:18.720131Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db_1 | 2020-07-11T10:26:18.720235Z 0 [Note] InnoDB: Setting file ‘./ibtmp1’ size to 12 MB. Physically writing the file full; Please wait …
db_1 | 2020-07-11T10:26:18.731470Z 0 [Note] InnoDB: File ‘./ibtmp1’ size is now 12 MB.
db_1 | 2020-07-11T10:26:18.732077Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
db_1 | 2020-07-11T10:26:18.732083Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
db_1 | 2020-07-11T10:26:18.732559Z 0 [Note] InnoDB: Waiting for purge to start
db_1 | 2020-07-11T10:26:18.782648Z 0 [Note] InnoDB: 5.7.30 started; log sequence number 2629907
db_1 | 2020-07-11T10:26:18.782818Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db_1 | 2020-07-11T10:26:18.783015Z 0 [Note] Plugin ‘FEDERATED’ is disabled.
db_1 | 2020-07-11T10:26:18.783785Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200711 10:26:18
db_1 | 2020-07-11T10:26:18.786322Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
db_1 | 2020-07-11T10:26:18.786334Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
db_1 | 2020-07-11T10:26:18.786970Z 0 [Warning] CA certificate ca.pem is self signed.
db_1 | 2020-07-11T10:26:18.786988Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
db_1 | 2020-07-11T10:26:18.788439Z 0 [Warning] Insecure configuration for --pid-file: Location ‘/var/run/mysqld’ in the path is accessible to all OS users. Consider choosing a different directory.
db_1 | 2020-07-11T10:26:18.793382Z 0 [Note] Event Scheduler: Loaded 0 events
db_1 | 2020-07-11T10:26:18.793537Z 0 [Note] mysqld: ready for connections.
db_1 | Version: ‘5.7.30’ socket: ‘/var/run/mysqld/mysqld.sock’ port: 0 MySQL Community Server (GPL)
db_1 | 2020-07-11 10:26:19+00:00 [Note] [Entrypoint]: Temporary server started.
db_1 | Warning: Unable to load ‘/usr/share/zoneinfo/iso3166.tab’ as time zone. Skipping it.
db_1 | Warning: Unable to load ‘/usr/share/zoneinfo/leap-seconds.list’ as time zone. Skipping it.
db_1 | Warning: Unable to load ‘/usr/share/zoneinfo/zone.tab’ as time zone. Skipping it.
db_1 | Warning: Unable to load ‘/usr/share/zoneinfo/zone1970.tab’ as time zone. Skipping it.
db_1 | 2020-07-11 10:26:20+00:00 [Note] [Entrypoint]: GENERATED ROOT PASSWORD: riRooXeeWooch3shah1oopi6quooreim
db_1 | 2020-07-11 10:26:20+00:00 [Note] [Entrypoint]: Creating database exampledb
db_1 | 2020-07-11 10:26:20+00:00 [Note] [Entrypoint]: Creating user exampleuser
db_1 | 2020-07-11 10:26:20+00:00 [Note] [Entrypoint]: Giving user exampleuser access to schema exampledb
db_1 |
db_1 | 2020-07-11 10:26:20+00:00 [Note] [Entrypoint]: Stopping temporary server
db_1 | 2020-07-11T10:26:20.575427Z 0 [Note] Giving 0 client threads a chance to die gracefully
db_1 | 2020-07-11T10:26:20.575440Z 0 [Note] Shutting down slave threads
db_1 | 2020-07-11T10:26:20.575443Z 0 [Note] Forcefully disconnecting 0 remaining clients
db_1 | 2020-07-11T10:26:20.575446Z 0 [Note] Event Scheduler: Purging the queue. 0 events
db_1 | 2020-07-11T10:26:20.575513Z 0 [Note] Binlog end
db_1 | 2020-07-11T10:26:20.575933Z 0 [Note] Shutting down plugin ‘ngram’
db_1 | 2020-07-11T10:26:20.575941Z 0 [Note] Shutting down plugin ‘partition’
db_1 | 2020-07-11T10:26:20.575944Z 0 [Note] Shutting down plugin ‘BLACKHOLE’
db_1 | 2020-07-11T10:26:20.575947Z 0 [Note] Shutting down plugin ‘ARCHIVE’
db_1 | 2020-07-11T10:26:20.575949Z 0 [Note] Shutting down plugin ‘PERFORMANCE_SCHEMA’
db_1 | 2020-07-11T10:26:20.575970Z 0 [Note] Shutting down plugin ‘MRG_MYISAM’
db_1 | 2020-07-11T10:26:20.575973Z 0 [Note] Shutting down plugin ‘MyISAM’
db_1 | 2020-07-11T10:26:20.575977Z 0 [Note] Shutting down plugin ‘INNODB_SYS_VIRTUAL’
db_1 | 2020-07-11T10:26:20.575979Z 0 [Note] Shutting down plugin ‘INNODB_SYS_DATAFILES’
db_1 | 2020-07-11T10:26:20.575980Z 0 [Note] Shutting down plugin ‘INNODB_SYS_TABLESPACES’
db_1 | 2020-07-11T10:26:20.576005Z 0 [Note] Shutting down plugin ‘INNODB_SYS_FOREIGN_COLS’
db_1 | 2020-07-11T10:26:20.576006Z 0 [Note] Shutting down plugin ‘INNODB_SYS_FOREIGN’
db_1 | 2020-07-11T10:26:20.576008Z 0 [Note] Shutting down plugin ‘INNODB_SYS_FIELDS’
db_1 | 2020-07-11T10:26:20.576009Z 0 [Note] Shutting down plugin ‘INNODB_SYS_COLUMNS’
db_1 | 2020-07-11T10:26:20.576011Z 0 [Note] Shutting down plugin ‘INNODB_SYS_INDEXES’
db_1 | 2020-07-11T10:26:20.576012Z 0 [Note] Shutting down plugin ‘INNODB_SYS_TABLESTATS’
db_1 | 2020-07-11T10:26:20.576034Z 0 [Note] Shutting down plugin ‘INNODB_SYS_TABLES’
db_1 | 2020-07-11T10:26:20.576036Z 0 [Note] Shutting down plugin ‘INNODB_FT_INDEX_TABLE’
db_1 | 2020-07-11T10:26:20.576037Z 0 [Note] Shutting down plugin ‘INNODB_FT_INDEX_CACHE’
db_1 | 2020-07-11T10:26:20.576039Z 0 [Note] Shutting down plugin ‘INNODB_FT_CONFIG’
db_1 | 2020-07-11T10:26:20.576040Z 0 [Note] Shutting down plugin ‘INNODB_FT_BEING_DELETED’
db_1 | 2020-07-11T10:26:20.576042Z 0 [Note] Shutting down plugin ‘INNODB_FT_DELETED’
db_1 | 2020-07-11T10:26:20.576044Z 0 [Note] Shutting down plugin ‘INNODB_FT_DEFAULT_STOPWORD’
db_1 | 2020-07-11T10:26:20.576045Z 0 [Note] Shutting down plugin ‘INNODB_METRICS’
db_1 | 2020-07-11T10:26:20.576047Z 0 [Note] Shutting down plugin ‘INNODB_TEMP_TABLE_INFO’
db_1 | 2020-07-11T10:26:20.576048Z 0 [Note] Shutting down plugin ‘INNODB_BUFFER_POOL_STATS’
db_1 | 2020-07-11T10:26:20.576050Z 0 [Note] Shutting down plugin ‘INNODB_BUFFER_PAGE_LRU’
db_1 | 2020-07-11T10:26:20.576052Z 0 [Note] Shutting down plugin ‘INNODB_BUFFER_PAGE’
db_1 | 2020-07-11T10:26:20.576053Z 0 [Note] Shutting down plugin ‘INNODB_CMP_PER_INDEX_RESET’
db_1 | 2020-07-11T10:26:20.576055Z 0 [Note] Shutting down plugin ‘INNODB_CMP_PER_INDEX’
db_1 | 2020-07-11T10:26:20.576072Z 0 [Note] Shutting down plugin ‘INNODB_CMPMEM_RESET’
db_1 | 2020-07-11T10:26:20.576073Z 0 [Note] Shutting down plugin ‘INNODB_CMPMEM’
db_1 | 2020-07-11T10:26:20.576075Z 0 [Note] Shutting down plugin ‘INNODB_CMP_RESET’
db_1 | 2020-07-11T10:26:20.576076Z 0 [Note] Shutting down plugin ‘INNODB_CMP’
db_1 | 2020-07-11T10:26:20.576078Z 0 [Note] Shutting down plugin ‘INNODB_LOCK_WAITS’
db_1 | 2020-07-11T10:26:20.576079Z 0 [Note] Shutting down plugin ‘INNODB_LOCKS’
db_1 | 2020-07-11T10:26:20.576080Z 0 [Note] Shutting down plugin ‘INNODB_TRX’
db_1 | 2020-07-11T10:26:20.576082Z 0 [Note] Shutting down plugin ‘InnoDB’
db_1 | 2020-07-11T10:26:20.576124Z 0 [Note] InnoDB: FTS optimize thread exiting.
db_1 | 2020-07-11T10:26:20.576172Z 0 [Note] InnoDB: Starting shutdown…
db_1 | 2020-07-11T10:26:20.676604Z 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
db_1 | 2020-07-11T10:26:20.676877Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 200711 10:26:20
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) No route to host
db_1 | 2020-07-11T10:26:21.690204Z 0 [Note] InnoDB: Shutdown completed; log sequence number 12488234
db_1 | 2020-07-11T10:26:21.691021Z 0 [Note] InnoDB: Removed temporary tablespace data file: “ibtmp1”
db_1 | 2020-07-11T10:26:21.691032Z 0 [Note] Shutting down plugin ‘MEMORY’
db_1 | 2020-07-11T10:26:21.691035Z 0 [Note] Shutting down plugin ‘CSV’
db_1 | 2020-07-11T10:26:21.691038Z 0 [Note] Shutting down plugin ‘sha256_password’
db_1 | 2020-07-11T10:26:21.691039Z 0 [Note] Shutting down plugin ‘mysql_native_password’
db_1 | 2020-07-11T10:26:21.691145Z 0 [Note] Shutting down plugin ‘binlog’
db_1 | 2020-07-11T10:26:21.691612Z 0 [Note] mysqld: Shutdown complete
db_1 |
db_1 | 2020-07-11 10:26:22+00:00 [Note] [Entrypoint]: Temporary server stopped
db_1 |
db_1 | 2020-07-11 10:26:22+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
db_1 |
db_1 | 2020-07-11T10:26:22.729641Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1 | 2020-07-11T10:26:22.730205Z 0 [Note] mysqld (mysqld 5.7.30) starting as process 1 …
db_1 | 2020-07-11T10:26:22.732667Z 0 [Note] InnoDB: PUNCH HOLE support available
db_1 | 2020-07-11T10:26:22.732677Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1 | 2020-07-11T10:26:22.732680Z 0 [Note] InnoDB: Uses event mutexes
db_1 | 2020-07-11T10:26:22.732682Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
db_1 | 2020-07-11T10:26:22.732684Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
db_1 | 2020-07-11T10:26:22.732686Z 0 [Note] InnoDB: Using Linux native AIO
db_1 | 2020-07-11T10:26:22.732930Z 0 [Note] InnoDB: Number of pools: 1
db_1 | 2020-07-11T10:26:22.733121Z 0 [Note] InnoDB: Using CPU crc32 instructions
db_1 | 2020-07-11T10:26:22.734304Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
db_1 | 2020-07-11T10:26:22.741796Z 0 [Note] InnoDB: Completed initialization of buffer pool
db_1 | 2020-07-11T10:26:22.743270Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
db_1 | 2020-07-11T10:26:22.754540Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
db_1 | 2020-07-11T10:26:22.760477Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db_1 | 2020-07-11T10:26:22.760543Z 0 [Note] InnoDB: Setting file ‘./ibtmp1’ size to 12 MB. Physically writing the file full; Please wait …
db_1 | 2020-07-11T10:26:22.771503Z 0 [Note] InnoDB: File ‘./ibtmp1’ size is now 12 MB.
db_1 | 2020-07-11T10:26:22.772042Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
db_1 | 2020-07-11T10:26:22.772049Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
db_1 | 2020-07-11T10:26:22.772458Z 0 [Note] InnoDB: Waiting for purge to start
db_1 | 2020-07-11T10:26:22.822734Z 0 [Note] InnoDB: 5.7.30 started; log sequence number 12488234
db_1 | 2020-07-11T10:26:22.822957Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db_1 | 2020-07-11T10:26:22.823182Z 0 [Note] Plugin ‘FEDERATED’ is disabled.
db_1 | 2020-07-11T10:26:22.825121Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200711 10:26:22
db_1 | 2020-07-11T10:26:22.826432Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
db_1 | 2020-07-11T10:26:22.826439Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
db_1 | 2020-07-11T10:26:22.826876Z 0 [Warning] CA certificate ca.pem is self signed.
db_1 | 2020-07-11T10:26:22.826894Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
db_1 | 2020-07-11T10:26:22.827203Z 0 [Note] Server hostname (bind-address): ‘*’; port: 3306
db_1 | 2020-07-11T10:26:22.827243Z 0 [Note] IPv6 is available.
db_1 | 2020-07-11T10:26:22.827251Z 0 [Note] - ‘::’ resolves to ‘::’;
db_1 | 2020-07-11T10:26:22.827263Z 0 [Note] Server socket created on IP: ‘::’.
db_1 | 2020-07-11T10:26:22.828539Z 0 [Warning] Insecure configuration for --pid-file: Location ‘/var/run/mysqld’ in the path is accessible to all OS users. Consider choosing a different directory.
db_1 | 2020-07-11T10:26:22.833667Z 0 [Note] Event Scheduler: Loaded 0 events
db_1 | 2020-07-11T10:26:22.833832Z 0 [Note] mysqld: ready for connections.
db_1 | Version: ‘5.7.30’ socket: ‘/var/run/mysqld/mysqld.sock’ port: 3306 MySQL Community Server (GPL)
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) No route to host
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) No route to host
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) No route to host
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) No route to host
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) No route to host
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) No route to host
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) No route to host
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) No route to host
wordpress_1 |
wordpress_1 | WARNING: unable to establish a database connection to ‘db’
wordpress_1 | continuing anyways (which might have unexpected results)
wordpress_1 |
wordpress_1 | AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 172.20.0.3. Set the ‘ServerName’ directive globally to suppress this message
wordpress_1 | AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 172.20.0.3. Set the ‘ServerName’ directive globally to suppress this message
wordpress_1 | [Sat Jul 11 10:26:53.254275 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.4.8 configured – resuming normal operations
wordpress_1 | [Sat Jul 11 10:26:53.254307 2020] [core:notice] [pid 1] AH00094: Command line: ‘apache2 -D FOREGROUND’

I’m tended to say that these things should just work. If you are in your company and running an endpoint protection solution, then you should ask your system administrator for help.
One thing is a bit strange, you get a ‘no route to host’ error. Did you really use the compose file from Dockerhub, just delete the restart parameters and then not change a single character? Notice that I got a ‘connection refused’ error instead during startup.
To check the network itself, you could run a simple compose file like

---

version: '3'

services:
  one:
    image: debian
    command: ping -c 5 two
  two:
    image: debian
    command: ping -c 5 one

This just creates two containers that ping each other. If this doesn’t work, then there is really a problem with your network traffic.

All the above is on my personal laptop for learning purpose…

your compose file works (ping between two containers), so why wordpress can’t connect to sql server docker?
they should have their own network… are there some log file that could assist?

$ docker-compose up
Creating network “test_default” with the default driver
Pulling one (debian:)…
latest: Pulling from library/debian
e9afc4f90ab0: Pull complete
Digest: sha256:46d659005ca1151087efa997f1039ae45a7bf7a2cbbe2d17d3dcbda632a3ee9a
Status: Downloaded newer image for debian:latest
Creating test_one_1 … done
Creating test_two_1 … done
Attaching to test_one_1, test_two_1
one_1 | PING two (172.21.0.3) 56(84) bytes of data.
one_1 | 64 bytes from test_two_1.test_default (172.21.0.3): icmp_seq=1 ttl=64 time=0.075 ms
two_1 | PING one (172.21.0.2) 56(84) bytes of data.
two_1 | 64 bytes from test_one_1.test_default (172.21.0.2): icmp_seq=1 ttl=64 time=0.061 ms
one_1 | 64 bytes from test_two_1.test_default (172.21.0.3): icmp_seq=2 ttl=64 time=0.057 ms
two_1 | 64 bytes from test_one_1.test_default (172.21.0.2): icmp_seq=2 ttl=64 time=0.042 ms
one_1 | 64 bytes from test_two_1.test_default (172.21.0.3): icmp_seq=3 ttl=64 time=0.039 ms
two_1 | 64 bytes from test_one_1.test_default (172.21.0.2): icmp_seq=3 ttl=64 time=0.051 ms
one_1 | 64 bytes from test_two_1.test_default (172.21.0.3): icmp_seq=4 ttl=64 time=0.068 ms
two_1 | 64 bytes from test_one_1.test_default (172.21.0.2): icmp_seq=4 ttl=64 time=0.041 ms
one_1 | 64 bytes from test_two_1.test_default (172.21.0.3): icmp_seq=5 ttl=64 time=0.052 ms
one_1 |
one_1 | — two ping statistics —
one_1 | 5 packets transmitted, 5 received, 0% packet loss, time 77ms
one_1 | rtt min/avg/max/mdev = 0.039/0.058/0.075/0.013 ms
two_1 | 64 bytes from test_one_1.test_default (172.21.0.2): icmp_seq=5 ttl=64 time=0.041 ms
two_1 |
two_1 | — one ping statistics —
two_1 | 5 packets transmitted, 5 received, 0% packet loss, time 135ms
two_1 | rtt min/avg/max/mdev = 0.041/0.047/0.061/0.009 ms
test_one_1 exited with code 0
test_two_1 exited with code 0

and thanks for all your efforts so far. much appreciated :slightly_smiling_face:

1 Like

This means you have no network problems.

Because of ‘something else’.
Maybe you should look more closely at your compose file:

  • MySQL should be 5.7. In higher versions a new authentication (caching_sha2_password) was introduced that is probably not supported by Wordpress.
  • WORDPRESS_DB_HOST must be identical to the name of the MySQL service (db in the example on Dockerhub).
  • WORDPRESS_DB_USER and MYSQL_USER have to be identical.
  • WORDPRESS_DB_PASSWORD and MYSQL_PASSWORD have to be identical.
  • WORDPRESS_DB_NAME and MYSQL_DATABASE have to be identical.
  • The names of the volumes in the services and those under volumes have to be identical.

Then remember that the database, user and password combination are created when the database is initialized on an empty volumes. Later changes are not updated in MySQL.

The example docker-compose file at https://hub.docker.com/_/wordpress/
comply with all the matching pairs you’ve depicted.
again, everything works when deployed in fresh VM with the same docker-compose file.
The big question is what’s the communication problem between the two containers on the host.

if only I could trace the outbound traffic from the wordpress container and see in some log what’s the error.