Docker Compose WordPress example

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.

Read More

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

Related posts

2 comments

  1. Your Dockerfile and docker-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 :

    • In the 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.

    • In the 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 and Dockerfile 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 and docker-compose.yml into the code directory (the one you renamed).

    Or modify the Dockerfile and docker-compose.yml so that they point to the good directory.

  2. By having a closer look to that quick start guide: The Dockerfile and the compose file should be inside your wordpress project folder that you created in the beginning. And also inside that wordpress folder there should be a sub-folder code. Run docker-compose from within the wordpress folder that way should work.

    Unfortunately when you run the curl https://wordpress.org/latest.tar.gz | tar -xvzf - command from within your wordpress project folder it creates an other folder wordpress below your project directory. You should rename that one to code.

Comments are closed.