Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

dockerfile - Why won't my docker container run unless I use -i -t?

If I run my Dockerfile with the following command, the docker container starts running and all is well.

docker run --name test1 -i -t 660c93c32a

However, if I run this command without the -it, the container does not appear to be running as docker ps returns nothing:

docker run -d --name test1 660c93c32a

.

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS 

         PORTS               NAMES

All I'm trying to do is run the container and then be able to attach and/or open a shell in the container later.

Not sure if the issue is in my dockerfile or not, so have pasted the dockerfile below.

############################################################
# Dockerfile to build Ubuntu/Ansible/Django
############################################################

# Set the base image to Ansible
FROM ubuntu:16.10

# File Author / Maintainer
MAINTAINER David


# Install Ansible and Related Deps #
RUN apt-get -y update && 
    apt-get install -y python-yaml python-jinja2 python-httplib2 python-keyczar python-paramiko python-setuptools python-pkg-resources git python-pip
RUN mkdir /etc/ansible/
RUN echo '[local]
localhost
' > /etc/ansible/hosts
RUN mkdir /opt/ansible/
RUN git clone http://github.com/ansible/ansible.git /opt/ansible/ansible
WORKDIR /opt/ansible/ansible
RUN git submodule update --init
ENV PATH /opt/ansible/ansible/bin:/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin
ENV PYTHONPATH /opt/ansible/ansible/lib
ENV ANSIBLE_LIBRARY /opt/ansible/ansible/library

# Update the repository sources list
RUN apt-get update -y
RUN apt-get install python -y
RUN apt-get install python-dev -y
RUN apt-get install python-setuptools -y
RUN apt-get install python-pip

RUN mkdir /ansible/
WORKDIR /ansible
COPY ./ansible ./
WORKDIR /

RUN ansible-playbook -c local ansible/playbooks/installdjango.yml

ENV PROJECTNAME davidswebsite
CMD django-admin startproject $PROJECTNAME
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

When you run your container, command after CMD or ENTRYPOINT becomes $1 process of you container. If this process doesn't run well, your container will die. So, check container logs using:
docker logs <container id>
and recheck your command in CMD django-admin startproject $PROJECTNAME


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...