There is a script that should be run after creating the container.

Dockerfile

FROM someimage MAINTAINER Meiram RUN /somedir/somescript.sh start 

As a result, after the build of the image I create a container

 $ docker run -td newsomeimage 

As a result, the process is not running, but it should always be running.


This script is launched with the start parameter, it listens to the port it needs. It should always be running. It is necessary after restarting the container or reboot of the host not to interfere with the operation of the container.

At the moment, after each start of the container, I manually enter the container with the help of the docker exec directive, and manually launch the script, but this is not exactly what I would like. Are there any other ways to run the script all the time after starting the container?

  • duplicate.stackoverflow.com/q/519676/16095 - etki

2 answers 2

fixed :

The run directive in dockerfile specifies the command (s) that are executed during the image creation stage.

To specify the command that will be executed when the container is started, the cmd directive should be used. eg:

 cmd /somedir/somescript.sh start 
  • Thank you, Alexander! This script is run with the start parameter that listens to the port it needs. It should always be running. It is necessary after restarting the container or reboot of the host not to interfere with the operation of the container. At the moment, after each start of the container, I manually go to the container with the help of the docker exec directive and manually start the script, but this is not exactly what I would like. Are there any other ways to run the script all the time after starting the container? - Meiram Chuzhenbayev
  • @MeiramChuzhenbayev, I corrected the answer. The previous version was incorrect, I apologize. - aleksandr barakin
  • Alexander, unfortunately your option does not work. Added CMD with parameters. As a result, at the start of the container, the creak starts but with the status exited. - Meiram Chuzhenbayev
  • @MeiramChuzhenbayev, I think you better ask a new question in which to bring the full contents of your dockerfile and the script that you mention. and output docker inspect for the image you created. - aleksandr barakin

Made through supervisord

through the documentation https://docs.docker.com/engine/admin/using_supervisord/

The fact is that the process I crashed if not connected to another service.