I am trying to run a python container to be used as a virtual development environment. I am building my own docker image with a custom written Dockerfile. The image builds are always successful, but when I run the container off the image, it exits immediately upon starting. I can't seem to figure out why this is happening.

My Dockerfile:

# Creates Python2.7.10 image for a python  dev environemnt on CentOs 7.x

FROM centos:latest


# Installs dependencies
RUN yum update -y && \
yum groupinstall development -y && \
yum install -y \
openssl \
openssl-devel \
bzip2-devel \
gcc \
tar \
wget \
zlib-dev \
git \
sudo \

# Downloads and installs Python
RUN mkdir /tmp_python && \
cd /tmp_python && \
wget --no-check-certificate https://www.python.org/ftp/python/2.7.10/Python-
2.7.10.tgz && \
tar -zxvf Python-2.7.10.tgz && \
cd /tmp_python/Python-2.7.10 && \
./configure --prefix=/usr/local && \
make && \
make altinstall && \
export PATH="/usr/local/bin:$PATH"

# Installs pip
RUN cd /tmp_python && \
wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py && \
python get-pip.py

# Installs virtualenv
RUN pip install virtualenv

# Creates working directory
ADD . /code

# Default command
CMD ["python"]

When I do docker ps -a, this is what I see:

[root@centos python]# docker run -d --name python-dev a9f468205931
[root@centos python]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             
STATUS                         PORTS               NAMES
c47908801503        a9f468205931        "python"                 34 minutes 
ago      **Exited (0)** 34 minutes ago                          python-dev
                     PORTS               NAMES

As you can see, the container already exited.

1 Answer 1


You need:

docker run -dit --name python-dev a9f468205931

-d, --detach Run container in background and print container ID

-i, --interactive Keep STDIN open even if not attached

-t, --tty Allocate a pseudo-TTY

  • This worked. Container is now steadily running.
    – AndG
    Aug 23, 2017 at 14:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .