skip to Main Content

I have built a project with a webhost (httpd:2.4)

(Dockerfile Content:
FROM httpd:2.4
COPY . /usr/local/apache2/htdocs )

It’s hosting a static website… and I’d like to be able to change that / publish future changes but that doesn’t work in the way I was expecting it to…

I’m using

git clone [repository]
cd [repository]
docker-compose -f docker-compose/docker-compose.yml up -d

to run the project, which works perfectly fine

The problem is that I should be able to make changes to the website.
I supposed it would just work like that:

docker-compose -f docker-compose/docker-compose.yml down
changing the index.html (save)
docker-compose -f docker-compose/docker-compose.yml up -d

But even though (for the test) I deleted every single character in my index.html, it still shows up exactly the same as before

What am I missing? What commands would I have to run for the changes to get applied?

2

Answers


  1. If you have a dockerfile, the file containing the below,

    FROM httpd:2.4
    COPY . /usr/local/apache2/htdocs
    

    It means you are building a custom docker image for your need. And you are also using the COPY command to copy the project to your docker image which is done when building the custom docker image. This is a good solution to copy the code in the docker image for distribution purposes however might not be the best for development purposes.

    If changes are made to the project, this is not reflected in the custom docker image until that docker image is rebuilt. After rebuilding the image, the current files of the project are copied to the docker image. Then after restarting the docker compose and by also using the latest image built, the changes will be visible.

    If you do not want to build a docker image each time a change is made, it might be best to create a docker-compose file which will map your project directly to /usr/local/apache2/htdocs. This way when the changes made to the project will be reflected instantly without any build process.

    Sample docker compose file with the project mapping to /usr/local/apache2/htdocs, this docker compose file needs to be located in the directory where the index.html lives.

    version: '3.9'
    
    services:
      apache:
        image: httpd:latest
        container_name: webserver
        ports:
          - '8080:80'
        volumes:
          # mapping your root project's directory to htdocs
          - ${PWD}:/usr/local/apache2/htdocs
    
    Login or Signup to reply.
  2. This problem may arise if you have referenced a docker image inside your docker-compose.yml file instead of building the image there. When you reference an image, docker-compose up will create the corresponding containers with the exact same image.

    You need to:

    • Build the image again AFTER you have made changes to your html file and BEFORE running docker-compose.

    OR

    • Build the image inside docker-compose.yml like this
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search