我有一個名為 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.
uj5u.com熱心網友回復:
只是大量的無效語法錯誤。代替
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" ]
利用
ADD main.py /main.py
RUN pip install requests pygame
CMD [ "python3", "/main.py" ]
uj5u.com熱心網友回復:
您在 ADD 中缺少第二個引數,即目標目錄。嘗試以下操作,例如./將 main.py 復制到當前目錄。
ADD main.py ./
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/421338.html
標籤:
上一篇:Docker不創建資料庫
