Docker Community Forums

Share and learn in the Docker community.

Help creating a WordPress dev environment


(Lmartins) #1

Hi everyone,

Im pretty new to Docker and Kitematic. I was hoping some of you could help me out finish setting up my WordPress dev environment using Kitematic. I’ve installed the official MySQL and WordPress containers.

I have both container running but when launching the WordPress container the log shows:

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

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

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

It repeats this a few times and finally the container halts. My current config for the WordPress container looks like this:
WordPress Container config

I must likely failing at some crucial step, but can’t figure out which one.

Could you please help?


(Aurel) #2

Hi,

The error show that mysqli cannot connect to the host you gave him.

What is your mysqli connection details ?
I think you have to indicate wordpressdb as the hostname to make it work.

Edit
I miss your mysql env variables.
Check if your wp-config.php use WORDPRESS_DB_HOST as mysql host.


(Lmartins) #3

Thank you @lighta971

Looking at wp-config.php it does seem right:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'root');

/** MySQL database password */
define('DB_PASSWORD', 'password');

/** MySQL hostname */
define('DB_HOST', 'wordpressdb');

Shouldn’t I have to run a PHP server also, or is that part of the main VM Kinematic launches?


(Aurel) #4

The mysql container need to be linked to the wordpress container.
So open wordpress container terminal and type cat /etc/hosts and you should see something like x.x.x.x wordpressdb if they linked.


(Lmartins) #5

Ok, ill have to dig a bit deeper as I not sure how to ssh into the container neither I have the docker command available in regular shell.


(Lmartins) #6

Seems like they are not linked:

# cat /etc/hosts
172.17.0.4	10736ea05570
127.0.0.1	localhost
::1	localhost ip6-localhost ip6-loopback
fe00::0	ip6-localnet
ff00::0	ip6-mcastprefix
ff02::1	ip6-allnodes
ff02::2	ip6-allrouters

(Josh Fialkoff) #7

I’m having the same problem.
Can you please post the exact syntax I need to enter in Terminal to link MySQL and WordPress?
By the way, why isn’t this done by default?
Thanks!


(Lmartins) #8

For me the simplest solution was to use docker-compose to spin up my containers, something like:

containername:
  image: gravityrail/wordpress
  volumes:
    - src:/var/www/html
  links:
    - db:mysql
  ports:
    - 80:80

db:
  image: mariadb
  environment:
    MYSQL_ROOT_PASSWORD: password