Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install python in a docker image?

Tags:

python

docker

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?

like image 759
Alex Avatar asked Nov 10 '17 06:11

Alex


People also ask

Can I install Python in a docker container?

How to Run the Python script file in Docker Container? After installing the python you can create a python script and run it easily. But one thing you should note is that any editor is not available in the docker ubuntu container thus you have to first install it using the apt-get install command.

What docker image does Python use?

If you want the absolute latest bugfix version of Python, or a wide variety of versions, the official Docker Python image is your best bet. If you want the absolute latest system packages, you'll want Ubuntu 22.04.

Can I install PyCharm in docker container?

For PyCharm Community Edition, you need to install the Docker plugin as described inInstall plugins. You can run and debug your Python code in the variously configured environments deployed in Docker containers.


1 Answers

RUN sudo apt-get update -y

RUN sudo apt-get install -y python

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.

like image 187
mikey Avatar answered Sep 18 '22 22:09

mikey