What is going on when the docker container exits as soon as it runs?

  docker, question

My Dockerfile:

FROM continuumio/miniconda:latest
 MAINTAINER Kamil Kwiek <kamil.kwiek@continuum.io>
 ADD  backend.tar.gz /usr/src/
 # app directory
 WORKDIR /usr/src/backend
 # install miniconda, configure conda environment
 RUN apt-get install -y gcc g++
 COPY backend_uwsgi.ini /usr/src/backend/
 COPY environment.txt /usr/src/backend/environment.txt
 RUN conda env create -f /usr/src/backend/environment.txt

Content of start.sh:

#!  /bin/bash
 docker exec -d mysql mysql -uroot -p123456 -e "create database blog;"
 docker build -t feiyu/django-app .
 docker run --name django \
 -v /usr/src/backend \
 -v /usr/src/backend/static \
 --link mysql:mysql \
 -p 12000:8000 \
 -d feiyu/django-app uwsgi --ini /usr/src/backend/backend_uwsgi.ini /bin/bash
 sleep 15
 #-d feiyu/django-app /usr/local/bin/gunicorn backend.wsgi:application -w 1 -b :8000

Enter sudokker ps-a to view, the results are

51e87164a739        feiyu/django-app           "/usr/bin/tini -- ..."   5 minutes ago       Exited (127) 8 seconds ago                            django

As soon as it runs, it exit. What’s going on? What should I do?

You need to let the Docker container run in the background as a daemon, which can be achieved by adding the -d parameter.

$ sudo docker run -d ubuntu:14.04 /bin/sh -c "while true;   do echo hello world;   sleep 1;  done"

Pay attention here/bin/sh -c "while true; do echo hello world; sleep 1; done"