[英]Unable to run docker image with docker run command
I want to create a python Django container.我想创建一个 python Django 容器。 I have a Dockerfile
as shown below -我有一个Dockerfile
,如下所示 -
FROM python:3.7-slim
ENV PYTHONUNBUFFERED 1
RUN apt-get update
RUN apt-get install python3-dev default-libmysqlclient-dev gcc -y
COPY ./requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
RUN mkdir /eitan_app
WORKDIR /eitan_app
COPY . /eitan_app
EXPOSE 8000
RUN python3 manage.py makemigrations
RUN python3 manage.py migrate
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]
I created image with the command mentioned below -我使用下面提到的命令创建了图像 -
docker build -t gcr.io/eitan-269907/eitan-app:v1 .
The above command created image successfully.上面的命令成功创建了图像。 Now I want to create a running container of the image so run command -现在我想创建一个正在运行的图像容器,所以运行命令 -
docker run --rm -p 8000:8000 gcr.io/eitan-269907/eitan-app:v1
The above command exited without any error code.上面的命令退出没有任何错误代码。 So I run command docker ps -a
to check the status of container.所以我运行命令docker ps -a
来检查容器的状态。
The container was not running.容器没有运行。 Hence I tried to check the logs with command docker logs -f <container id>
but command did not return any thing.因此,我尝试使用命令docker logs -f <container id>
检查日志,但命令没有返回任何内容。
I don't understand what is wrong with my configuration.我不明白我的配置有什么问题。 I have been trying to look for the solution and found nothing.我一直在寻找解决方案,但一无所获。
This could be due to some error in running makemigration
or some other script, In such case I try to use Entrypoint as '/dev/null' so that container doesn't exit,这可能是由于运行makemigration
或其他一些脚本时出现错误,在这种情况下,我尝试将 Entrypoint 用作“/dev/null”,以便容器不会退出,
This gives chance to log into container and execute them manually to check what's core issue这提供了登录容器并手动执行它们以检查核心问题的机会
For your case would suggest对于你的情况会建议
FROM python:3.7-slim
ENV PYTHONUNBUFFERED 1
RUN apt-get update
RUN apt-get install python3-dev default-libmysqlclient-dev gcc -y
COPY ./requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
RUN mkdir /eitan_app
WORKDIR /eitan_app
COPY . /eitan_app
ENTRYPOINT ["tail", "-f", "/dev/null"]
Once you build this image and execute same, it will keep container running构建此映像并执行相同的操作后,它将保持容器运行
you can then use docker exec -it <container_name> bash
which will allow you to log into container and execute rest of commands and see if it's giving some error然后您可以使用docker exec -it <container_name> bash
这将允许您登录容器并执行其余命令并查看它是否给出了一些错误
When you run it with the --rm
flag, it removes the container after the command or job it is supposed to do is complete.当您使用--rm
标志运行它时,它会在它应该执行的命令或作业完成后删除容器。 This explains why you are not seeing anything when trying to view the logs or with ps -a
.这解释了为什么您在尝试查看日志或使用ps -a
时没有看到任何内容。 Try to run the container with -d
(detach) instead of --rm
and see if the container stays running after.尝试使用-d
(分离)而不是--rm
运行容器,然后查看容器是否继续运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.