Dokcer & ML

Launch a container to run or build a ML model

Mukul Jeveriya
4 min readMay 30, 2021

--

Hello gyus :-)

In this Blog I am going to show you How to run or can say build a ML model inside a Docker Container. Full task description listed below step by step wise, what I am gonna to do.

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 copy/create machine learning model

👉 Build the ML model

Let’s Start

I am running Docker Container on the top of Redhat8. So my base system is rhel8 and on the top of my Container running

On the base system I created a directory You can see on the image in this I put my ML data and ML code (this is simple linear regression ml code here the purpose is not to show my ML skills purpose is show to integration of two useful technologies)

Code for training ML model

Code for predicting values via trained ML model

Dataset for training ML model

Now let pull the Docker image

In my case I already have centos but for pulling image form docker repo we have command.

docker pull image_name:version_name

Right now I don’t have any running or terminated docker container. For seeing this we have command

docker ps -a

This show all the running and terminated docker container until we remove all the container.

Let start a docker container

docker run -it --name any_name image_name:version_name

Now in next image you can see a docker container is running with the name mlcontainer.

Now copy all the code file from base system to docker container

We have to copy all the file in container for this we have a docker command

docker cp /source_path container_ID/name:/destination_pathdocker cp /root/summer_2021/task1 mlcontainer:/task1

Install Python and libraries to Run ML code

For installing python we have command

yum install python36

Installing pandas and sklearn libraries

pip3 install pandas 
pip3 install sklearn

Now all set just time to Run our ML code

Now let’s run the prediction code

Look model trained successfully and saved as salary.pk1 and also give prediction value.

All done we Integrate to big Technologies.

Thanks for reading , I hope you like the Blog!!!

--

--

No responses yet