I have been following the Quickstart Guide: Compose and WordPress and can’t get it to work.
I think it has something to do with my directory structure. After running all the steps I had a sub-directory called wordpress
but I think all of my code referenced a sub-directory called code
so I decided to rename my wordpress
directory code
. I then re-run docker-compose up
but this also unfortunately didn’t work.
UPDATE: By “can’t get it to work” when I enter load the website the PHP server returns:
Not Found
The requested resource / was not found on this server
Your
Dockerfile
anddocker-compose.yml
should be inside your wordpress directory. (The one you renamed code)Your confusion
For some reason you think there is a code directory involved. There is no directory like that in your wordpress and it’s perfectly normal.
Let’s break down the command that are confusing you :
Dockerfile
:ADD . /code
This line has for effect to copy the directory indicated (here it’s . ) into the container directory indicated (here it’s /code).
It’s equivalent to a
cp
command only that you copy from the host to the container.docker-compose.yml
:volumes:
- .:/code
This command is exposing a directory to a container. Here we expose the host directory . into the container directory /code.
Note : If you understood volume you might realize that the
ADD
instruction in your Dockerfile is unnecessary.Why it’s not working
Your
docker-compose.yml
andDockerfile
are above the intended working directory.So when the docker-compose execute it copy the content of your current directory into the /code directory of the container.
So when php try to execute in /code it doesn’t see the file he expect hence the Not found error.
Fix it
Either copy you
Dockerfile
anddocker-compose.yml
into the code directory (the one you renamed).Or modify the
Dockerfile
anddocker-compose.yml
so that they point to the good directory.By having a closer look to that quick start guide: The
Dockerfile
and the compose file should be inside yourwordpress
project folder that you created in the beginning. And also inside thatwordpress
folder there should be a sub-foldercode
. Rundocker-compose
from within thewordpress
folder that way should work.Unfortunately when you run the
curl https://wordpress.org/latest.tar.gz | tar -xvzf -
command from within yourwordpress
project folder it creates an other folderwordpress
below your project directory. You should rename that one tocode
.