简体   繁体   English

在 Ubuntu 上运行一个简单的 Python 容器

[英]Running a simple Python Container on Ubuntu

So I have a directory that just includes a Dockerfile .所以我有一个只包含Dockerfile的目录。 I want to experiment with the poetry package in python.我想在 python 中试验诗歌 package。 So I do not want any python files to be inside it initially because I want to create a poetry project from scratch inside the directory.所以我最初不希望任何 python 文件在其中,因为我想在目录中从头开始创建一个诗歌项目。 So ı went ahead and built the image called local:python3.10ubuntu for it.所以我继续为它构建了名为local:python3.10ubuntu的图像。 When I ran the container for it with the command docker run --name py3.10ubuntu local:python3.10ubuntu I can see that the docker container was not running why is that and how would I be able to run it.当我使用命令docker run --name py3.10ubuntu local:python3.10ubuntu为它运行容器时,我可以看到 docker 容器没有运行,为什么会这样以及我如何能够运行它。 when I try to see the docker logs for the container it wouldnt show anything as well.当我尝试查看容器的 docker 日志时,它也不会显示任何内容。 Besides starting the container how would I be able to run the command shell within the container and run python files?除了启动容器之外,我如何能够在容器内运行命令 shell 并运行 python 文件?

Directory Structure:目录结构:

.
└── Dockerfile

Dockerfile contents Dockerfile 内容

FROM python:3.10-slim
RUN pip install --no-cache-dir poetry

ughhhh?啊?

docker run -ti <your_image>

or if you want see more than python itself:或者,如果您想查看的不仅仅是 python 本身:

docker run -ti --entrypoint /bin/bash <your_image>

Your dockerfile is not configured properly try to refer below website on how to create a docker file for poetry.您的 dockerfile 配置不正确,请尝试参考以下网站,了解如何为诗歌创建 docker 文件。

Dockerfile for poetry Dockerfile 为诗歌

Also to run a shell script in dockerfile it could be done if your code has a.sh file.如果您的代码有一个 .sh 文件,也可以在 dockerfile 中运行 shell 脚本。 You could either use RUN, ENTRYPOINT, CMD or combination of these to run the shell script in your docker file.Refer the below answer您可以使用 RUN、ENTRYPOINT、CMD 或这些组合在 docker 文件中运行 shell 脚本。请参阅以下答案

Using ENTRYPOINT to run shell script in dockerfile 使用 ENTRYPOINT 在 dockerfile 中运行 shell 脚本

To run a docker container you can use要运行 docker 容器,您可以使用

docker run -it <docker-image>

Try exec command to run something inside the container尝试 exec 命令在容器内运行某些东西

docker exec -it <container-name-or-id> bash

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM