Docker 构建挂起

Docker build hangs

我正在尝试为 python 程序构建一个 Docker Img(这是来自 FreeCodeCamp 的电报机器人), 现在代码运行完美,但是当我尝试构建这个 Dockerfile

FROM python:3.6
COPY . /app

WORKDIR /app

RUN pip install -r requirement.txt

ENV PORT 8080

ENV HOST 0.0.0.0

RUN ["python","bot.py"]

系统挂起。

dishant_sonawane17@cloudshell:~/project (voice-261819)$ docker build -t python-docker-dev .
Sending build context to Docker daemon  4.608kB
Step 1/7 : FROM python:3.6
 ---> e0373ff33a19
Step 2/7 : COPY . /app
 ---> Using cache
 ---> 6f9396ff2a64
Step 3/7 : WORKDIR /app
 ---> Using cache
 ---> 1c216f1a529c
Step 4/7 : RUN pip install -r requirement.txt
 ---> Using cache
 ---> 531e40ac101d
Step 5/7 : ENV PORT 8080
 ---> Using cache
 ---> 385b36f30518
Step 6/7 : ENV HOST 0.0.0.0
 ---> Using cache
 ---> b1ba2f0bf26e
Step 7/7 : RUN ["python","bot.py"]
 ---> Running in 5ceec7069ee9

不确定您的 bot.py 会做什么,但它会 运行 并等待完成... 看起来您希望 bot.py 成为容器启动后启动的应用程序。

为此你应该使用 ENTRYPOINT or CMD

简而言之:

  • RUN executes command(s) in a new layer and creates a new image. E.g., it is often used for installing software packages.
  • CMD sets default command and/or parameters, which can be overwritten from command line when docker container runs.
  • ENTRYPOINT configures a container that will run as an executable.

更详细explanation/source:https://goinbigdata.com/docker-run-vs-cmd-vs-entrypoint/.