How to make changes to httpd.conf of apache running inside DOCKER container and restart apache

No need to attach or exec (which is really a debug feature anyway)

You can use docker cp to copy a local version of your httpd.conf to the container. (That way, you can modify the file from the comfort of your local environment)

docker cp httpd.conf <yourcontainer_name>:/path/to/httpd.conf

Once that is done, you can send an USR1 signal to ask for a graceful restart (see docker kill syntax):

docker kill --signal="USR1" <yourcontainer_name>

Replace <yourcontainer_name> by the container id or name which is running Apache.

That will only work if the main process launched by your container is

CMD ["apachectl", "-DFOREGROUND"]

See more at "Docker: How to restart a service running in Docker Container"


Enter a container by opening a bash shell:

docker exec -it containerName bash

I guess you better just reload apache config and not reboot apache. But I wouldn't go this route and just modify Dockerfile and rebuild and rerun the image.

edit for link: https://docs.docker.com/engine/reference/commandline/exec/


To update Apache configs you need to:

  1. Replace Apache configs.

    • If you have config folder mapped from outside of container you should update configs outside of container.

    • If your apache configs are stored inside of container, you will need to run something like this:

      docker cp httpd.conf YOUR_CONTAINER_NAME:/path/to/httpd.conf
      
  2. Do Graceful Apache restart:

    sudo docker exec -it YOUR_CONTAINER_NAME apachectl graceful