Pulling docker container image of CentOS and installing python on top of docker container

RajSaundatikar
3 min readMay 29, 2021

Task Description πŸ“„

πŸ‘‰ Pull the Docker container image of CentOS image from DockerHub and create a new container

πŸ‘‰ Install the Python software on the top of docker container

πŸ‘‰ In Container you need to copy/create machine learning model which you have created in jupyter notebook

First, we will check whether docker is installed. We can check docker version using command

--docker version

Pulling CentOS image

Use below command to pull centos image

docker pull centos

Creating a container

We use following command to run docker container

docker run -it --name myos centos

-it = stands for interactive terminal, it means that as soon as the container launches it shows the terminal of the container

-name = it is used for naming the container

Installing pip

For installing pip we use following command

yum install python3-pip -y

Installing scikit-learn library

Next, we need to install scikit-learn library, we install it using following command

pip3 install scikit-learn pandas

Copying code and dataset

Open new terminal and write the following commands

docker cp /root/Documents/ml.py myos:/
docker cp /root/Documents/SalaryData.csv myos:/

The docker cp command is used to copy data from base os to container.

Running code and saving model

Go to previous terminal and to run the code use the following command

python3 ml.py

Saving container as the new image

Now use exit command to come out the container

Use following command to create new image from the container

docker commit myos mlimage

Next, run docker images command to confirm whether image is created

In the above picture we can see the image created

--

--