Docker容器无法运行Pygame

发布于 2025-02-02 03:44:05 字数 822 浏览 1 评论 0 原文

因此,实际上,我想使用Docker容器运行Pygame应用程序。但是,当我运行Docker并单击终端上的链接时,它将打开一个选项卡,并说:“网页at http://0.0.0.0:8000/ 可能暂时下降,或者它可能已永久移动到新的网址。”

这是aliens.py github链接:

在aliens.py文件中,我在其中添加了一些代码:

from fastapi import FastAPI

import uvicorn

app = FastAPI()

if __name__ == '__main__': uvicorn.run(app, port=8000, host="0.0.0.0")

创建的Dockerfile文件的代码

Python FROM:3.10

WORKDIR /fastapi-app

COPY requirements.txt .

RUN pip install -r requirements.txt

COPY ./app ./app

CMD["python", "./app/aliens.py"]

以及 主机的IP地址?

so actually, i want to run a pygame application using docker container. however, when i run the docker and click the link at the terminal, it opens a tab and it says : "The webpage at http://0.0.0.0:8000/ might be temporarily down or it may have moved permanently to a new web address."

here's the aliens.py github link: https://github.com/xamox/pygame/blob/master/examples/aliens.py

in the aliens.py file, I added some code into it:

from fastapi import FastAPI

import uvicorn

app = FastAPI()

and

if __name__ == '__main__': uvicorn.run(app, port=8000, host="0.0.0.0")

and for the code of the Dockerfile file that I have created:

Python FROM:3.10

WORKDIR /fastapi-app

COPY requirements.txt .

RUN pip install -r requirements.txt

COPY ./app ./app

CMD["python", "./app/aliens.py"]

Is the problem is in the IP address of the host?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

離人涙 2025-02-09 03:44:05

dockerfile

# python FROM:3.10    <----
FROM python:3.10 

WORKDIR /fastapi-app

COPY requirements.txt .

RUN pip install -r requirements.txt

COPY ./app ./app

#CMD["python", "./app/aliens.py"]
#   ^ whitespace missing
CMD ["python", "./app/aliens.py"]

aliens.py

from fastapi import FastAPI
import uvicorn
app = FastAPI()


if __name__ == '__main__': 
    uvicorn.run(app, port=8000, host="0.0.0.0")

没有Aliens-Code的

# build
$ docker build -t my-app .
# run
$ docker run -d -rm --name mayapp -p 80:8000 my-app
# 80 host-port
# 8000 container-port
$ docker ps -a 
CONTAINER ID   IMAGE     COMMAND                  CREATED         
STATUS        PORTS                  NAMES
5ba7b461e92e   my-app    "python ./app/aliens…"   3 seconds ago   Up 1 second   0.0.0.0:80->8000/tcp   mayapp   

测试http:// localhost/docs

Dockerfile

# python FROM:3.10    <----
FROM python:3.10 

WORKDIR /fastapi-app

COPY requirements.txt .

RUN pip install -r requirements.txt

COPY ./app ./app

#CMD["python", "./app/aliens.py"]
#   ^ whitespace missing
CMD ["python", "./app/aliens.py"]

aliens.py

from fastapi import FastAPI
import uvicorn
app = FastAPI()


if __name__ == '__main__': 
    uvicorn.run(app, port=8000, host="0.0.0.0")

Testing without aliens-code

# build
$ docker build -t my-app .
# run
$ docker run -d -rm --name mayapp -p 80:8000 my-app
# 80 host-port
# 8000 container-port
$ docker ps -a 
CONTAINER ID   IMAGE     COMMAND                  CREATED         
STATUS        PORTS                  NAMES
5ba7b461e92e   my-app    "python ./app/aliens…"   3 seconds ago   Up 1 second   0.0.0.0:80->8000/tcp   mayapp   

http://localhost/docs
enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文