Came out with doccode 0

I am trying to start a container using docker-compose services. But unfortunately the container came out of code 0 . The containers are created using the repository from the .tar.gz archive. This archive is a Centos VM.

I want to create 6 containers from the same archive. Instead of typing docker command 6 times, I would like to create a docker-compose.yml file where I can summarize their command and tag.

I started writing a docker-compose.yml file just to create one container.

Here is my docker-compose.yml:

version: '2'
services:
  dvpt:
   image: compose:test.1
   container_name: cubop1
   command: mkdir /root/essai/
   tty: true

      

Ignore the command as I just have to specify it.

So my question is, why is the container exiting ? Is there another solution to build this container at the same time?

Thank you for your responses.

+11


source to share


3 answers


The answer is actually the first comment. I'll explain a little to Miguel.

First, we need to understand that the Docker container runs one command. The container will run as long as this command is run. Once the process is done and exited, the container will stop.



With this understanding, we can make an assumption about what is happening in your case. When the service starts dvpt

, the command is executed mkdir /root/essai/

. This command creates a folder and then exits. At this point, the Docker container stops because the process has completed (state 0, indicating it mkdir

completed without errors).

+19


source


One solution is to create a process that doesn't end, an endless loop, or something that can run continuously in the background. This will open the container because the process will not end.

This is a very hack. I am still looking for the best solution.

Zend Server image does something like this. In their .sh script, they have a final command:



exec /usr/local/bin/nothing

      

Executes a file that is constantly running in the background. I tried to copy the contents of the file here, but it must be in binary format.

EDIT: You can also terminate your file with /bin/bash

, which starts a new terminal process in the container and prevents it from closing.

+2


source


You can end up with a command like tail -f / dev / null

This often works in my docker-compose.yml with

command: tail -f/dev/null

And it's easy to see how I keep the container running.

docker ps

0


source







All Articles