How to restart apache2 without terminating docker container?

后端 未结 5 995
甜味超标
甜味超标 2021-02-02 10:29

I am using as a base the php docker container with the tag:

php:5.6-apache

When I try to restart the apache2 inside the container, the containe

相关标签:
5条回答
  • 2021-02-02 11:06

    I want to customize the container, I need to install some extension and for them to work I need to restart apache for the changes to take effect.

    This is against the Docker's immutable infrastructure principle. IMHO, you are using the docker container similar to a full blown VM. Instead, I would suggest you to treat the docker image as the final artifact and version it. Note: This is just my humble opinion, you may have a valid usecase which I am not aware of, which I am curious to find out.

    0 讨论(0)
  • 2021-02-02 11:09

    My solution to this was to exit my bash shell into the container, and just restart the container outside of Docker. Because Apache is set as the primary service, this also restarts Apache, and doesn't crash the container.

    docker restart <container>
    
    0 讨论(0)
  • 2021-02-02 11:10

    But before going, does your apache fails while doing the restart? Thats how it exits? In that case, please do make it run by setting right configurations and having a look at those logs.

    One method you can try is login to the container (to bash) and you could always have a docker commit at a point where it works. You can then change your base container image to that.

    I had workarounds for similar situations by building new images from these committed ones using different ENTRYPOINT's in my Dockefile.

    0 讨论(0)
  • 2021-02-02 11:16

    If you use apache as the primary service to keep your running container, you can NOT reboot it. Simply because you built the image and sets the CMD with it.

    The main purpose of a CMD is to provide defaults for an executing container. These defaults can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction as well.

    Try to reload without restart a service:

    /etc/init.d/apache2 reload
    
    0 讨论(0)
  • 2021-02-02 11:27

    sudo docker kill --signal="USR1" your_appache_container

    Other signals that you can use to achieve the following :

    Stop Now Signal: TERM

    Graceful Restart Signal: USR1

    Restart Now Signal: HUP

    Graceful Stop Signal: WINCH

    From: this website

    0 讨论(0)
提交回复
热议问题