除非我使用-i -t,为什么我的docker容器不运行? [英] Why won't my docker container run unless I use -i -t?

查看:184
本文介绍了除非我使用-i -t,为什么我的docker容器不运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用以下命令运行Dockerfile,则Docker容器开始运行,一切都很好。

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

但是,如果我不带-it运行此命令,则容器似乎未在运行,因为docker ps不返回任何内容:

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.

不确定问题是否

############################################################
# 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]\nlocalhost\n' > /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


推荐答案

运行容器时,在CMD或ENTRYPOINT变为$ 1后执行命令您的容器的过程。如果此过程无法顺利进行,则您的容器将死亡。
因此,使用以下命令检查容器日志:
docker logs<容器ID>

并在<$ c $中重新检查命令c> CMD django-admin startproject $ PROJECTNAME

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

这篇关于除非我使用-i -t,为什么我的docker容器不运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆