I am trying to create a Wordpress site inside a Docker stack composed of the following services:
-
wordpress
- the Wordpress site itself -
db
- the MySQL container
I have the following stack.yml
file:
version: '3.1'
networks:
abtehnic:
services:
db:
image: mysql:latest
restart: always
networks:
- abtehnic
environment:
MYSQL_ROOT_PASSWORD: XXXXX
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: barbu123
wordpress:
image: abtehnic-wordpress
depends_on:
- db
restart: always
ports:
- 80
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_PASSWORD: barbu123
networks:
- abtehnic
volumes:
- ./source:/var/www/html
I deploy the stack with the following command:
$ docker stack deploy -c stack.yml abtehnic
The docker ps
command outputs the following:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
256e65fe2c4c mysql:latest "docker-entrypoint..." About a minute ago Up About a minute 3306/tcp abtehnic_db.1.mo0xp17adt2jocu9yivkzg19g
26481d8bab95 wordpress:4.8 "docker-entrypoint..." About a minute ago Up About a minute 80/tcp abtehnic_wordpress.1.tiikrjwm1kcmxjg7v74vrcquw
I am trying to find out the mapped port via:
$ docker port <container_id for wordpress>
and its output is empty. Also when I am running docker logs <container_id_for_wordpress>
I get the following:
Warning: mysqli::mysqli(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
Warning: mysqli::mysqli(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22
MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 22
MySQL Connection Error: (2002) Connection refused
Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 22
MySQL Connection Error: (2002) Connection refused
MySQL Connection Error: (2002) Connection refused
Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 22
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.0.1.3. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.0.1.3. Set the 'ServerName' directive globally to suppress this message
[Sat Oct 28 16:05:32.189285 2017] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/5.6.31 configured -- resuming normal operations
[Sat Oct 28 16:05:32.189321 2017] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
Here are my questions:
- Why can't the
wordpress
container access thedb
container? - Why isn't there any port that I can use to access the Wordpress site from my host?