1
votes

This is my docker-compose.yml

version: '2'

services:

 wordpress:
    image: wordpress:4.6.1-php5.6-apache
    container_name: wordpress
    volumes:
         - ./projects/:/home/docker/
    working_dir: /home/docker/
    ports:
         - "8000:80"
    environment:
        WORDPRESS_DB_PASSWORD: secret
    links:
        - database-mysql

 database-mysql:
   image: mysql:5.7
   container_name: mysqldb
   ports:
     - "3306:3306"
   volumes:
     - ./backups/mysqldb/:/var/lib/mysql/
   environment:
     MYSQL_ROOT_PASSWORD: secret
     MYSQL_DATABASE: wordpress

 phpmyadmin:
   image: phpmyadmin/phpmyadmin:latest
   container_name: phpmyadmin
   ports:
     - "8080:80"
   environment:
     PMA_USER: root
     PMA_PASSWORD: secret
     PMA_HOST: database-mysql
   links:
     - database-mysql

When I run: docker-compose up, the log error shows:

MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not know

Warning: mysqli::mysqli(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 19

Warning: mysqli::mysqli(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 19

2016-11-11 04:14:33,648 INFO success: php-fpm entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

2016-11-11 04:14:33,648 INFO success: nginx entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

What am I doing wrong?

2
How do they know how to communicate with each other? So, for the first error, what name or service is it trying to hit?johnharris85

2 Answers

1
votes

is's too long to comment, therefore i create another answer
try this and wait for 2 minutes, after that access localhost:8000

version: '2'

services:
   db:
     image: mysql:5.7
     volumes:
       - "./.data/db:/var/lib/mysql"
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: wordpress
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     links:
       - db
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_PASSWORD: wordpress

   phpmyadmin:
     image: phpmyadmin/phpmyadmin:latest
     container_name: phpmyadmin
     ports:
       - "8080:80"
     environment:
       PMA_USER: root
       PMA_PASSWORD: secret
       PMA_HOST: database-mysql
     links:
       - db
1
votes

On Windows 10 Home edition (so using docker-toolbox) I also ran into this problem. It seems that the wordpress image now required the environment setting:

  • WORDPRESS_DB_HOST: db:3306.

After adding this, the wordpress container can connect to the database. Also with Windows 10 Home edition I can't get the port mapping to work for localhost. I need to lookup the ip-adress via docker-machine ip and connect to the port there.

On Linux Mint (based on Ubuntu) this does not seem required. So I expect this to be an installation problem with docker-toolbox or Windows 10 Home Edition.