在 Dockerfile 中通过 Ubuntu 的 apt-get 使用 apt-get 安装 python-pip
Install python-pip using apt-get via Ubuntu's apt-get in Dockerfile
正在浏览以下博客 post:
https://codefresh.io/docker-tutorial/hello-whale-getting-started-docker-flask/
这是该项目的 Github 存储库(由作者提供):
https://github.com/ChloeCodesThings/chloe_flask_docker_demo
Docker文件:
FROM ubuntu:latest
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
ENTRYPOINT ["python"]
CMD ["app.py"]
将此项目克隆到我运行 macOS Catalina (10.15.4) 的本地计算机后。
和运行以下命令(来自网络文件夹内):
docker build -t flask-hello:latest .
标准输出中的输出:
Sending build context to Docker daemon 36.86kB
Step 1/8 : FROM ubuntu:latest
latest: Pulling from library/ubuntu
d51af753c3d3: Pull complete
fc878cd0a91c: Pull complete
6154df8ff988: Pull complete
fee5db0ff82f: Pull complete
Digest: sha256:747d2dbbaaee995098c9792d99bd333c6783ce56150d1b11e333bbceed5c54d7
Status: Downloaded newer image for ubuntu:latest
---> 1d622ef86b13
Step 2/8 : RUN apt-get update -y
---> Running in b85d892341c1
Get:1 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]
Get:2 http://security.ubuntu.com/ubuntu focal-security InRelease [107 kB]
Get:3 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [3717 B]
Get:4 http://archive.ubuntu.com/ubuntu focal-updates InRelease [106 kB]
Get:5 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [35.3 kB]
Get:6 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [3190 B]
Get:7 http://archive.ubuntu.com/ubuntu focal-backports InRelease [89.2 kB]
Get:8 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages [11.3 MB]
Get:9 http://archive.ubuntu.com/ubuntu focal/restricted amd64 Packages [33.4 kB]
Get:10 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages [1275 kB]
Get:11 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [177 kB]
Get:12 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [14.1 kB]
Get:13 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [3190 B]
Get:14 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [42.7 kB]
Fetched 13.5 MB in 4s (3264 kB/s)
Reading package lists...
Removing intermediate container b85d892341c1
---> 3b5aa4c86a97
Step 3/8 : RUN apt-get install -y python-pip python-dev build-essential
---> Running in a9f9fdde1725
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package python-pip
The command '/bin/sh -c apt-get install -y python-pip python-dev build-essential' returned a non-zero code: 100
Docker版本:
Client: Docker Engine - Community
Version: 19.03.8
API version: 1.40
Go version: go1.12.17
Git commit: afacb8b
Built: Wed Mar 11 01:21:11 2020
OS/Arch: darwin/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.8
API version: 1.40 (minimum version 1.12)
Go version: go1.12.17
Git commit: afacb8b
Built: Wed Mar 11 01:29:16 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
为什么使用 apt-get
找不到 Ubuntu 的 python-pip
?非常感谢任何建议!
我怀疑 Dockerfile
中的第一行试图使用最新的 Ubuntu 版本 20.04
,但没有软件包。
更改为版本 18.04
即可运行:
FROM ubuntu:18.04
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
ENTRYPOINT ["python"]
CMD ["app.py"]
检查这个
FROM python:3.8-slim-buster
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ADD requirements.txt .
RUN python -m pip install -r requirements.txt
WORKDIR /app
ADD . /app
RUN useradd appuser && chown -R appuser /app
USER appuser
CMD ["python", "-m", "app.py"]
正在浏览以下博客 post:
https://codefresh.io/docker-tutorial/hello-whale-getting-started-docker-flask/
这是该项目的 Github 存储库(由作者提供):
https://github.com/ChloeCodesThings/chloe_flask_docker_demo
Docker文件:
FROM ubuntu:latest
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
ENTRYPOINT ["python"]
CMD ["app.py"]
将此项目克隆到我运行 macOS Catalina (10.15.4) 的本地计算机后。
和运行以下命令(来自网络文件夹内):
docker build -t flask-hello:latest .
标准输出中的输出:
Sending build context to Docker daemon 36.86kB
Step 1/8 : FROM ubuntu:latest
latest: Pulling from library/ubuntu
d51af753c3d3: Pull complete
fc878cd0a91c: Pull complete
6154df8ff988: Pull complete
fee5db0ff82f: Pull complete
Digest: sha256:747d2dbbaaee995098c9792d99bd333c6783ce56150d1b11e333bbceed5c54d7
Status: Downloaded newer image for ubuntu:latest
---> 1d622ef86b13
Step 2/8 : RUN apt-get update -y
---> Running in b85d892341c1
Get:1 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]
Get:2 http://security.ubuntu.com/ubuntu focal-security InRelease [107 kB]
Get:3 http://security.ubuntu.com/ubuntu focal-security/universe amd64 Packages [3717 B]
Get:4 http://archive.ubuntu.com/ubuntu focal-updates InRelease [106 kB]
Get:5 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [35.3 kB]
Get:6 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [3190 B]
Get:7 http://archive.ubuntu.com/ubuntu focal-backports InRelease [89.2 kB]
Get:8 http://archive.ubuntu.com/ubuntu focal/universe amd64 Packages [11.3 MB]
Get:9 http://archive.ubuntu.com/ubuntu focal/restricted amd64 Packages [33.4 kB]
Get:10 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages [1275 kB]
Get:11 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [177 kB]
Get:12 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 Packages [14.1 kB]
Get:13 http://archive.ubuntu.com/ubuntu focal-updates/restricted amd64 Packages [3190 B]
Get:14 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages [42.7 kB]
Fetched 13.5 MB in 4s (3264 kB/s)
Reading package lists...
Removing intermediate container b85d892341c1
---> 3b5aa4c86a97
Step 3/8 : RUN apt-get install -y python-pip python-dev build-essential
---> Running in a9f9fdde1725
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package python-pip
The command '/bin/sh -c apt-get install -y python-pip python-dev build-essential' returned a non-zero code: 100
Docker版本:
Client: Docker Engine - Community
Version: 19.03.8
API version: 1.40
Go version: go1.12.17
Git commit: afacb8b
Built: Wed Mar 11 01:21:11 2020
OS/Arch: darwin/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 19.03.8
API version: 1.40 (minimum version 1.12)
Go version: go1.12.17
Git commit: afacb8b
Built: Wed Mar 11 01:29:16 2020
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: v1.2.13
GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429
runc:
Version: 1.0.0-rc10
GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd
docker-init:
Version: 0.18.0
GitCommit: fec3683
为什么使用 apt-get
找不到 Ubuntu 的 python-pip
?非常感谢任何建议!
我怀疑 Dockerfile
中的第一行试图使用最新的 Ubuntu 版本 20.04
,但没有软件包。
更改为版本 18.04
即可运行:
FROM ubuntu:18.04
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
ENTRYPOINT ["python"]
CMD ["app.py"]
检查这个
FROM python:3.8-slim-buster
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ADD requirements.txt .
RUN python -m pip install -r requirements.txt
WORKDIR /app
ADD . /app
RUN useradd appuser && chown -R appuser /app
USER appuser
CMD ["python", "-m", "app.py"]