0

I am relatively new to docker and havent used it except for simple cases so please bear with me.

I have a python3 docker image that lacks some of the modules I need like scipy, sklearn etc. I run the image (docker run -i -t python) and then I am able to download and install the necessary packages as below from inside the container:

>>> import pip
>>> pip.main(["install", "sklearn", "scipy"])

However when I quit the container and restart all the installs are gone. How can I make them persistent?

user2399453
  • 2,930
  • 5
  • 33
  • 60
  • You could use `docker commit` to take a snapshot of your container. But a better bet is to create a custom image based off the official Python image, containing steps that install these dependencies. – Oliver Charlesworth Nov 26 '17 at 19:08
  • Where do i run the docker commit from? I am on the python shell when I use the container, if I exit the shell I lose whatever I installed. – user2399453 Nov 26 '17 at 19:10
  • See https://stackoverflow.com/questions/19585028/i-lose-my-data-when-the-container-exits for an example. – Oliver Charlesworth Nov 26 '17 at 19:12

1 Answers1

1

Proper way would be to build your custom image based on source one. For this you need to define what your image should contain. It can be done using Dockerfile. It's a simple text file, in your case it will look like this:

FROM python:3

RUN pip install sklearn scipy

Then just run docker build -t myPythonImage . in folder where you have Dockerfile. when it finishes you will be able to use your new image with docker run myPythonImage. More info on official site: https://docs.docker.com/engine/reference/builder/

odk
  • 2,144
  • 1
  • 16
  • 10