Docker Community Forums

Share and learn in the Docker community.

Docker can't find pip3, even though its installed

Docker can’t find pip3, even though its installed

 % which pip3                   
/usr/local/bin/pip3

% docker build --target test -t todobackend-test .
Sending build context to Docker daemon  372.7kB
...
Step 4/12 : RUN apk add --no-cache gcc python3 python3-dev libffi-dev musl-dev linux-headers mariadb-dev
 ---> Using cache
 ---> 7e64185b97f9
Step 5/12 : RUN pip3 install wheel
 ---> Running in 7aa68a2249b4
/bin/sh: pip3: not found
The command '/bin/sh -c pip3 install wheel' returned a non-zero code: 127

What is the easiest way to solve this?

Uhm, you did use which pip3 on your host, didn’t you? This is completly unrelated to what is in inside the image.

Add py3-pip to your apk add command.

1 Like

That worked, thank you.

I’m following an example from a book, which is obviously outdated.

Don’t worry, It just took me a couple of seconds to google for “apk add pip3” :wink:

You might want to take a llok at the excellent Introduction to Docker and Containers self-paced tutorial.

1 Like

Your problem comes from the fact that Docker is not using the proper DNS server. You can fix it in three different ways :

  1. Adding Google DNS to your local config
    Modifying /etc/resolv.conf and adding the following lines at the end

Google IPv4 nameservers

nameserver 8.8.8.8
nameserver 8.8.4.4

If you want to add other DNS servers, have a look here.

However this change won’t be permanent (see this thread). To make it permanent : $ sudo nano /etc/dhcp/dhclient.conf
Uncomment and edit the line with prepend domain-name-server : prepend domain-name-servers 8.8.8.8, 8.8.4.4;

Restart dhclient : $ sudo dhclient.

  1. Modifying Docker config
    As explained in the docs :

Systems that run Ubuntu or an Ubuntu derivative on the desktop typically use 127.0.0.1 as the default nameserver in /etc/resolv.conf file.

To specify a DNS server for use by Docker :

  1. Log into Ubuntu as a user with sudo privileges.

  2. Open the /etc/default/docker file for editing :

    $ sudo nano /etc/default/docker

  3. Add the following setting for Docker.

    DOCKER_OPTS="–dns 8.8.8.8"

  4. Save and close the file.

  5. Restart the Docker daemon :

    $ sudo systemctl restart docker

  6. Using a parameter when you run Docker
    When you run docker, simply add the following parameter : --dns 8.8.8.8

i realy wish someone would delete this stupid bot user lewish95!