docker wordpress container can't connect to database container
<p>I've been using docker to build wordpress apps for some days. I got some working but now I don't know why I can get to connect the database container and the wordpress container.</p>

<p>I've reduced the failing condiguration to the simplest possible.</p>

<p>Right now I have the following docker-compose.yml file:</p>

<pre><code>wordpress:
  image: wordpress
  links:
    - db:mysql
  ports:
    - 8080:80

db:
  image: mariadb
  environment:
    MYSQL_ROOT_PASSWORD: example
</code></pre>

<p>which is an exact copy of this official example:</p>

<p><a href="https://hub.docker.com/_/wordpress/" rel="nofollow">https://hub.docker.com/_/wordpress/</a></p>

<p>(scroll down to "... via docker-compose").</p>

<p>If I do composer up with this file I got the following relevant log entries:</p>

<pre><code>Creating miqueladell_db_1
Creating miqueladell_wordpress_1
Attaching to miqueladell_db_1, miqueladell_wordpress_1
db_1        | Initializing database
</code></pre>

<p>…lots of initialization…</p>

<pre><code>wordpress_1 | Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 10
</code></pre>

<p>…this goes on for a while, db_1 says it's initializing and wordpress_1 says it can connect
and then…</p>

<pre><code>db_1        | MySQL init process done. Ready for start up.
</code></pre>

<p>…some more database messages…</p>

<pre><code>db_1        | 2016-01-12 14:34:46 139698309449664 [Note] mysqld: ready for connections.
wordpress_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.5. 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.17.0.5. Set the 'ServerName' directive globally to suppress this message
wordpress_1 | [Tue Jan 12 14:34:47.180996 2016] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.10 (Debian) PHP/5.6.17 configured -- resuming normal operations
wordpress_1 | [Tue Jan 12 14:34:47.181253 2016] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
</code></pre>

<p>…at that momment if I browse to the wordpress endpoint I got…</p>

<pre><code>wordpress_1 | 192.168.99.1 - - [12/Jan/2016:14:34:47 +0000] "GET / HTTP/1.1" 500 586 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
</code></pre>

<p>And an <strong>Error establishing a database connection</strong> on the front end.</p>

<p>I've pasted the full log here in case someone want's to take a look: <a href="http://pastebin.com/Z9U2iMsH" rel="nofollow">http://pastebin.com/Z9U2iMsH</a></p>

<p>I've got my environment running before and I am sure that if not this particular example I have been able to run the containers and connect to the database with some of the examples I tried (without luck) today so I guess there is something wrong with my environment but I don't know how to debug it.</p>

<p>I've removed all containers, all images, re-donwloaded the images and rebuilt de containers. Even tested everyithing on a enpty folder with a newly created docker-compose.yml file.</p>

<p>In fact as reading the logs it seemed that maybe the wordpress process was exhausting its tries I have even restarted the wordpress container <em>while</em> the database container was already up and the result is the same.</p>

<p>Just in case it's relevant I'm running all of this locally on a mac using the docker quickstart terminal as descrived here: </p>

<p><a href="https://docs.docker.com/mac/step_one/" rel="nofollow">https://docs.docker.com/mac/step_one/</a></p>

<p>and <strong>docker -v</strong> says:</p>

<pre><code>Docker version 1.9.1, build a34a1d5
</code></pre>

<p><strong>EDIT:</strong> Just tried using:</p>

<pre><code>image: wordpress:4.4
</code></pre>

<p>instead of "no tag" which downloads latest (4.4.1 at the time of writing) and it works. So it seems that is a bug introduced on 4.4.1</p>

<p>I've oppened one here</p>

<p><a href="https://github.com/docker-library/wordpress/issues/120" rel="nofollow">https://github.com/docker-library/wordpress/issues/120</a></p>

<p>I'll keep the question open just in case but it seems quite  clear that is a bug</p>