Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exited with code 0 docker

I'm trying to launch container using docker-compose services.But unfortunetly, container exited whith code 0. Containers is build thanks to a repository which is from a .tar.gz archive. This archive is a Centos VM.

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

I have started to write docker-compose.yml file just for 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 

Do not pay attention to the command as I have just to specify one.

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

Thanks for your responses.

like image 596
Sylvain M.J. Avatar asked Jul 03 '17 11:07

Sylvain M.J.


People also ask

What is the cause of exit code 0 for a container?

Exit code 0 indicates that the specific container does not have a foreground process attached. This exit code is the exception to all the other exit codes to follow.

What does exited mean in docker?

When the process running inside your container ends, the container will exit. Here are a couple of examples: You run a container, which runs a shell script to perform some tasks. When the shell script completes, the container will exit, because there's nothing left for the container to run.

How do I stop docker containers from exiting?

Method 1: You can use the -t (pseudo-tty) docker parameter to keep the container running. Method 2: You can run the container directly passing the tail command via arguments as shown below. Method 3: Another method is to execute a sleep command to infinity.


1 Answers

The answer is actually the first comment. I'll explain Miguel's comment a bit.

First, we need to understand that a Docker container runs a single command. The container will be running as long as that process the command started is running. Once the process is completed and exits then the container will stop.

With that understanding, we can make an assumption of what is happening in your case. When you start your dvpt service it runs the command mkdir /root/essai/. That command creates the folder and then exits. At this point, the Docker container is stopped because the process exited (with status 0, indicating that mkdir completed with no error).

like image 72
Andy Shinn Avatar answered Sep 30 '22 12:09

Andy Shinn