Back to Top

Docker container stop automatically after running

Updated 4 February 2017

What is Docker ?

Docker is an Application Container Engine. Using it we can pack any Linux software into a self-contained, isolated container image that can be easily distributed, and run on any Host Machine. Once we have the image built or downloaded, we can use it to start containers as many as we want & run the software(s) on them.

Yesterday, while working on Docker image to start some process I was stuck in some problem which I`ll explain in this blog along with the solution I used to fix it. I hope it will help someone.

PROBLEM : According to the Docker tutorial I read so far, using “docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG…]” will start a container from image, and the container will run. But in my situation it`s not.

  • If I ran “docker ps“, nothing was returned.
  • I tried “docker ps -a“, I can see container already exited:
    mohit.chandra@mohit106:/home/mohit/docker# docker ps -a
    CONTAINER_ID    IMAGE            COMMAND                 CREATED        STATUS         NAMES
    a581778502e9    webkul/odoo:v10  "/docker-entrypoint.s"  2 minutes ago  Exited(126)    dare_dev

Here is the content of Dockerfile:

Searching for an experienced
Odoo Company ?
Find out More
FROM webkul/odoo
MAINTAINER Mohit Chandra <[email protected]>

# Expose Odoo/Postgresql services
EXPOSE 8069 5432

# Copy Entrypoint script in the container
COPY ./ /


and here is the content of script file( :

set -e
echo "Starting PostgreSQL..."
service postgresql start
echo "Starting ODOO..."
service odoo-server start

I tried many things, Google it, but nothing works. Thanks to Stackoverflow, I found the reason behind this,

REASON: Docker requires command(s) to keep running in the foreground. Otherwise, it thinks that application is stopped and it shutdown the container. As my script( contained only background processes, and no other foreground process triggered later, that`s why container exits when script ends.

SOLUTION: In order to fix this issue, we need to either leave something running in the foreground or use a process manager such as runit or supervisord to run the processes.

This behavior confused me a long time and finally by Hit-n-Try method, I got the better trick which fix this issue, and here it is :

Add extra command at the end of the script, as:

set -e
echo "Starting PostgreSQL..."
service postgresql start
echo "Starting ODOO..."
service odoo-server start
#Extra line added in the script to run all command line arguments
exec "$@";

and supply some [COMMAND] while running docker image, as:

#To open container with a shell prompt
docker run -it webkul/odoo:v10 /bin/bash


#To start a container in detached mode
docker run -dit webkul/odoo:v10 /bin/bash

That`s it !!! I hope it will help someone in the future. And by someone I most likely mean by me !

Your opinions, comments and suggestions are important to keep the page updated and interesting !!!

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


  • Website directory
    • Vipin Kumar (Moderator)
  • Jan Smeds
    • Anisha Bahukhandi (Moderator)
  • Valter
    • Anisha Bahukhandi (Moderator)
  • bonitobonita24
  • David
  • Avi Dror
  • Sonu Puthukudi
    • Mohit Chandra (Moderator)
  • Bentzy Sagiv
    • Mohit Chandra (Moderator)
  • septentrion
    • Mohit Chandra (Moderator)
  • siva kumar
    • Mohit Chandra
  • Rahul Goyal
    • Suraj Kumar
  • Vi Hùng
    • Suraj Kumar
  • Ale DC
    • Mohit Chandra
  • asfour mohamed
    • Mohit Chandra
      • ankit
        • Mohit Chandra (Moderator)
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home