45

I want to create a docker image with selenium and chrome correctly installed, so I choose a base image with these properties. Therefore, the first line of the Dockerfile is as follows:

FROM selenium/node-chrome:3.7.1-argon

Then the next command is

RUN apt-get update

which created the following error while creating the docker image:

Step 4/19 : RUN apt-get update
 ---> Running in af08ae07cbf3
Reading package lists...
E: List directory /var/lib/apt/lists/partial is missing. - Acquire (13: Permission denied)
The command '/bin/sh -c apt-get update' returned a non-zero code: 100

How to be able to install python in this docker image?

Alex
  • 41,580
  • 88
  • 260
  • 469

3 Answers3

54

RUN apt-get update

RUN apt-get install -y python3

As hinted by:

Acquire (13: Permission denied)

I believe this is due to your base image:

https://github.com/SeleniumHQ/docker-selenium/blob/master/NodeChrome/Dockerfile

As you can see it swaps from the default user context of 'root' to 'seluser'.

You can either:

  1. wear this as a consequence of the base image (i.e. use sudo)
  2. swap back: USER root
  3. or consider creating your own docker image to avoid swapping in the first place

Using sudo is best avoided in Dockerfiles where possible, so it would be preferable to go with option #2 or #3, rather than #1.

Hope that helps mate.

Nam G VU
  • 33,193
  • 69
  • 233
  • 372
mikey
  • 1,068
  • 10
  • 13
  • 1
    Yes. Strange. I created a docker image before and never required 'root'... – Alex Nov 10 '17 at 06:31
  • Well the only reason it would make sense is if you used the 'USER' directive, otherwise I would assume the container should be of user root and thus not need sudo. – mikey Nov 10 '17 at 06:32
  • Updated my answer to clarify, there is in the base image you are inheriting from. – mikey Nov 10 '17 at 06:36
  • 1
    One thing to notice this installs python 2. As I can see you're doing stuff with `selenium` and `chrome`, you may want to install python 3 to make it work. – Aniruddha Pandey Sep 01 '20 at 15:06
  • In the event that you need a particular version of python, for example python 2.7, you can type `RUN sudo apt-get install python2.7`. – amc Dec 16 '20 at 01:34
13

Note: Below commands may require root/administrative previleges.

  1. Download docker image docker pull ubuntu
  2. Start interactive container docker run -it ubuntu /bin/bash

Note: By default you will be logged in inside container as root user if not then either elevate your privileges to root or use sudo before below listed commands

  1. Update container instance apt-get update
  2. For python 2.7 apt-get install python2
  3. For Python 3.x apt-get install python3
Chandan
  • 11,465
  • 1
  • 6
  • 25
Sagar
  • 171
  • 1
  • 6
  • 2
    when you do `apt-get install python` which one do you install? – KansaiRobot Oct 11 '21 at 05:04
  • @KansaiRobot it appears that `apt-get install python` used to install Python 2 but has since been removed to force the user to be more explicit: `Package python is not available, but is referred to by another package. [...] However the following packages replace it: [...] python2 [...] E: Package 'python' has no installation candidate`. Where `[...]` is me removing unnecessary text. – Matt Popovich Nov 21 '22 at 00:05
1

First, you would like to log in as root:

sudo docker exec -u root -it 88d53df8fd19 /bin/bash

Once you are there, you will be root and will be able to run commands as such without problems.

Run below command inside container to install python

apt update
apt-get install python3.6
Hafiz Muhammad Shafiq
  • 8,168
  • 12
  • 63
  • 121
  • The question was about how to create a Docker image. Your command can be used to log into a running container and modify the container, not the image. – Sky Mar 15 '23 at 17:11