Can't reach localhost on simple wordpress setup

I am trying to set up wordpress in Docker. Or rather to re-set it up as it worked on an older machine. I have the following

version: "3"
services:
  db:
    image: mariadb
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: my_root_pword
      MYSQL_DATABASE: my_db
      MYSQL_USER: my_user
      MYSQL_PASSWORD: my_pword
    ports:
      - 3306:3306

  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - 8000:80
    restart: always
    working_dir: /var/www/html
    volumes:
      - ../wordpress:/var/www/html

  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    ports:
      - 61112:80
    depends_on:
      - db
    environment:
      MYSQL_USERNAME: root
      MYSQL_ROOT_PASSWORD: my_root_pword
    restart: always

volumes:
  db_data:

But I get an error AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.4. Set the 'ServerName' directive globally to suppress this message and - perhaps for the same reason - wordpress will not connect to mariadb when I load http://172.18.0.4

This script is the first and only one Iā€™ve ever written and Iā€™m devastated that it has stopped working because Docker is hard. Any clues on how to solve this.

Hi

Can you open the page and the db connection fail, or cant you open the wordpress at all?

The first thing that comes to mind, is that you have set wordpress to be available on port 8000, but you didnā€™t define a port in your request, it would be: http://172.18.0.4:8000

Also, you could try and just open: http://localhost:8000

IF some of this works, when you then need to connect to the db, ā€œdbā€ would be the hostname of your database.

1 Like

This is not an error, just a warning that doesnā€™t cause any problems. You can ignore it.

Thanks so much for helping, and I hope the following helps you to help more.

I decided to reboot and then - before doing anything more - discovered

~ sudo ps -aux | grep docker
root      1195  0.8  1.0 1971856 86992 ?       Ssl  07:57   0:00 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
root      1600  0.0  0.0 548872  3796 ?        Sl   07:57   0:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 3306 -container-ip 172.19.0.2 -container-port 3306
root      1614  0.0  0.0 475140  3900 ?        Sl   07:57   0:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 61112 -container-ip 172.19.0.3 -container-port 80
root      1627  0.0  0.0 475140  3972 ?        Sl   07:57   0:00 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8000 -container-ip 172.20.0.4 -container-port 80
root      1636  0.0  0.0 107344  4896 ?        Sl   07:57   0:00 containerd-shim -namespace moby -workdir /var/lib/containerd/io.containerd.runtime.v1.linux/moby/dc558be308814fff8ea8358b3c8dc73cb2eb4ae7848240ce59c64737688267ba -address /run/containerd/containerd.sock -containerd-binary /usr/bin/containerd -runtime-root /var/run/docker/runtime-runc
root      1641  0.0  0.0 107344  4876 ?        Sl   07:57   0:00 containerd-shim -namespace moby -workdir /var/lib/containerd/io.containerd.runtime.v1.linux/moby/f367db0ff5751fb96e0e458e430a27bb4ba94ce5361835646f4d1139b722f108 -address /run/containerd/containerd.sock -containerd-binary /usr/bin/containerd -runtime-root /var/run/docker/runtime-runc
root      1663  0.0  0.0 108752  5864 ?        Sl   07:57   0:00 containerd-shim -namespace moby -workdir /var/lib/containerd/io.containerd.runtime.v1.linux/moby/2db63efc1158cfe96b2002d5076f2e6a3de2af5c83c6f2577dd661825a51207c -address /run/containerd/containerd.sock -containerd-binary /usr/bin/containerd -runtime-root /var/run/docker/runtime-runc
root      1680  0.0  0.0 107344  5488 ?        Sl   07:57   0:00 containerd-shim -namespace moby -workdir /var/lib/containerd/io.containerd.runtime.v1.linux/moby/c68c5bcb32e61fdd116cbeed43667f45730b1fa317cec398ddaa1bf01fa2a945 -address /run/containerd/containerd.sock -containerd-binary /usr/bin/containerd -runtime-root /var/run/docker/runtime-runc
root      1701  0.0  0.0 107344  5428 ?        Sl   07:57   0:00 containerd-shim -namespace moby -workdir /var/lib/containerd/io.containerd.runtime.v1.linux/moby/1517c5336e04a4c84b3e561cf15011402ac48e35da9725d45721bb6dbad25909 -address /run/containerd/containerd.sock -containerd-binary /usr/bin/containerd -runtime-root /var/run/docker/runtime-runc
simon     3179  0.0  0.0  17616   912 pts/0    S+   07:58   0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn docker

I use Docker so that I donā€™t have the whole LAMP stack running on my machine all the time (I normally just write javascript with webpack building). So the next thing I need to do is to prevent docker loading at boot time. Iā€™m also wondering how the bootup scripts know where to find my docker script on the disk?

Then, these are the results of various urls

localhost:61112/ loads phpmyadmin
localhost:8000/ is automatically redirected to localhost which fails with localhost refused to connect.
172.20.0.4/ loads my wordpress site
172.19.0.3/ loads phpmyadmin

But these 172.*.*.* addresses are different every time I boot so I canā€™t work with them as, for example, the url gets hard coded into the wordpress database.

āœ— sudo docker version
Client: Docker Engine - Community
 Version:           19.03.1
 API version:       1.40
 Go version:        go1.12.5
 Git commit:        74b1e89
 Built:             Thu Jul 25 21:21:22 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.1
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.5
  Git commit:       74b1e89
  Built:            Thu Jul 25 21:19:53 2019
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.6
  GitCommit:        894b81a4b802e4eb2a91d1ce216b8817763c29fb
 runc:
  Version:          1.0.0-rc8
  GitCommit:        425e105d5a03fabd737a126ad93d62a9eeede87f
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

Iā€™m not sure I can because this is what is leading apache to give itself a randomly chosen private IP address each time I start my computer

Your expectation, that containers should not be restarted after a system restart, contradicts with the ā€œrestart: alwaysā€ policies in your docker-compose.yml

In the container world, accessing a container by its ip is in 99,99% of the cases wrong, as a container ip is not static and will eventualy change. For container to container communication the servicename (or an network alias or the containers hostname) needs to be used. If you want to access the service inside the container, you will need to publish a port and use it to access your containerized service.

There is no other direction than terpz and tekki already guided you to :slight_smile:

Now the remaining question is: why is accessing wp using the url http://localhost:8000 not working. What sort of forward does the container do? You might want to share the snippet of the configuration that does the forwarding.

1 Like

Thanks @meyay.

I will remove the restart line - Iā€™m a complete amateur, but I know I donā€™t want docker running all the time because I use only very infrequently for one client.

I do not want to use IP addresses either, so the heart of my question is how to get localhost to be recognised as Docker starts.

I realise now that although I can get to the login screen of phpmyadmin, I cannot login at I get an error that mysql has gone away, presumably because of the weirdness in the IP address.

As regards 8000, I do not know of any other redirecting but that might - perhaps - be due to wordpress as it stores the siteā€™s url in its DB. That would right itself if I could get a stable name for what docker is running.

I think that Apache is struggling to get its ServerName correctly, but I do not know how to tell Apache inside a container what this value should be. I tried some suggestions by logging into the container when it was running and changing apache.conf, but the changes did not survive a restart

I am not sure what the default behavior is. I would advise to set an explicit behavior:

restart: "no"
restart: always 
restart: on-failure
restart: unless-stopped

Pick one that suits your requirement.

Not sure what this is supposed to say - there is plenty of room for guessing in this sentence :slight_smile:

How and where is the db configuration done in phpmyadmin? There is no environment varible present in your docker-compose.yml that would configure itā€¦

Yep, the last one seems like a winner! If the port is part of the stored configuration, the hostname is NOT your problem. The problem is that the wp config expects itself under a given port, which is unknown in your hosts world.

Also i did find that people mention hard coded settings in the wp-config.php file.
You could try to set the ā€œexternalā€ access url from the hosts perspective:
define(ā€˜WP_SITEURLā€™, ā€˜http://localhost:8080/ā€™);
define(ā€˜WP_HOMEā€™, ā€˜https://localhost:8080/ā€™);

If this doesnā€™t work - you could try to publish the container port to the same port on your host (this way http:/localhost:80 is valid on the host and in the container). Make sure the settings in wp-config.php do use port 80 as well.

If this is still insufficient, you could add a reverse proxy configuration in your wp container or put a reverse proxy in front that does url rewrite for you.

I uninstalled everything and ran rm -rf /var/lib/docker, then followed the instructions to use docker-compose without sudo.

As a result after running docker-compose up

  • http://localhost:61112 is now serving phpmyadmin :slight_smile:

  • curl http://172.18.0.3 returns the initial page of a wordpress setup, but

  • curl http://localhost:8000 first got reset by host and then a while later a wordpress error page where the key line is php_network_getaddresses: getaddrinfo failed: Name or service not known. I get the same error with curl http://172.18.0.4

  • and in the logs as its starts up I still get

wordpress_1   | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.4. Set the 'ServerName' directive globally to suppress this message

I canā€™t help thinking that if I could fix this so that the reliable fqn was localhost I may be in a much better situation?

Sure, lets ignore everything established so far and start from the beginning!

My sincere apologies - you can be absolutely certain that my intention was not to piss anyone off. I am at a complete loss for ideas why a brand new ubuntu 19.04 with a brand new docker and a script more or less cut and paste from the internet gets such intractable errors, but I know for certain that I wonā€™t be able to resolve them alone

it was intended to be sarcastic: think about your establish a chain of thoughts, and tell someone about doā€™s and donā€™tsā€¦ and the next thing you see is that everything estables before is completly ignored. I am neither mad, nor pissed of - why should I? It is just a sign for me that I am not able to help you with your situation.

Good luck in finding a solution!

No worries then. Just found https://github.com/nezhar/wordpress-docker-compose/issues/19 and I have the same issue with this very popular script. That makes me think the issue is more to do with the interaction between docker and the network settings of my own box. On the latter, I did recently get a major update from my cable provider (new router etc)

And now tried this repo on a Mac on the same network and it worked fine, but with the apache2: Could not reliably determine the server's fully qualified domain name, using 172.19.0.3. Set the 'ServerName' directive globally to suppress this message messages, so I realiae that those were indeed the source of the problem

It seems its an issue with Ubuntu 19.04

ā€¦ and it seems it was a permissions issue that I introduced as I tried to get things working.