【发布时间】:2022-01-24 12:56:46
【问题描述】:
我有一个名为 docker 的目录,其中包含以下两个文件:
docker:
|_Dockerfile
|_main.py
Dockerfile 如下所示:
#Specifying the base image
FROM python:3.10
#here the dockerfile is pulling the python 3.10 from docker hub which already has python installed so we have all the things we need to have python in our container.
ADD main.py.
#Here we added the python file that we want to run in docker and define its location.
RUN pip install requests pygame
#Here we installed the dependencies, we are using the pygame library in our main.py file so we have to use the pip command for installing the library
CMD [ "python3" "./main.py" ]
#lastly we specified the entry command this line is simply running python ./main.py in our container terminal
main.py 文件如下所示:
# Simple pygame program
# Import and initialize the pygame library
import pygame
pygame.init()
# Set up the drawing window
screen = pygame.display.set_mode([500, 500])
# Running the game until the user asks to quit
running = True
while running:
# creating an if statement for the close button
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# Filling the background color with a gray
screen.fill((55, 55, 55))
# Drawing a solid purple circle in the center
pygame.draw.circle(screen, (0, 0, 251), (251, 251), 74)
# Flip the display
pygame.display.flip()
# Done! Time to quit.
pygame.quit()
我打开了我的 cmd(我在 Windows 10 上)并导航到 docker 目录并执行了以下命令:
docker image build -t python-game .
这是我收到的输出
[+] Building 0.1s (2/2) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 683B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
failed to solve with frontend dockerfile.v0: failed to create LLB definition: dockerfile parse error line 5: ADD requires at least two arguments, but only one was provided. Destination could not be determined.
【问题讨论】:
-
使用复制而不是添加
-
game.py 行中缺少空格。更改为 game.py 。
-
@SimonHawe 将 ADD 更改为 COPY:
failed to solve with frontend dockerfile.v0: failed to create LLB definition: dockerfile parse error line 5: COPY requires at least two arguments, but only one was provided. Destination could not be determined. -
@Tomᚊturm 谢谢,就是这样!
标签: python docker dockerfile