Tuesday, October 26, 2021

[SOLVED] Install python-pip using apt-get via Ubuntu's apt-get in Dockerfile

Issue

Am walking through the following blog post:

https://codefresh.io/docker-tutorial/hello-whale-getting-started-docker-flask/


Here's the Github repo of this project (courtesy of the author):

https://github.com/ChloeCodesThings/chloe_flask_docker_demo


Dockerfile:

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"]

After cloning this project to my local machine which runs macOS Catalina (10.15.4).

And running the following command (from inside the web folder):

docker build -t flask-hello:latest .

Output in stdout:

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 version:

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

Why can't it find python-pip for Ubuntu using apt-get? Any suggestions are greatly appreciated!


Solution

I'm suspecting the first line in Dockerfile tries to use the latest Ubuntu version 20.04, that doesn't have the package.

Change to version 18.04 and it will work:

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"]


Answered By - Andrej Kesely