Training Machine Learning model using Python inside a Docker container

Ritesh Choudhary
4 min readJun 4, 2021

#Task1

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.

What is Machine Learning?

Machine Learning refers to the study of algorithms and models for computers to perform tasks without explicit instructions. It is a discipline of Artificial Intelligence (AI) that predicts the system output through its experience of processing the data, without previously having known the system behavior model. The algorithms simulate human learning capabilities that help the system automatically improve through this experience and yield accurate output based on new system input.

What is Docker?

Docker is a containerization platform which packages your application and all its dependencies together in the form of containers so as to ensure that your application works seamlessly in any environment, be it development, test or production. Docker containers, wrap a piece of software in a complete filesystem that contains everything needed to run: code, runtime, system tools, system libraries, etc. It wraps basically anything that can be installed on a server. This guarantees that the software will always run the same, regardless of its environment.

What is a Docker Container?

Docker containers include the application and all of its dependencies. It shares the kernel with other containers, running as isolated processes in user space on the host operating system. Docker containers are not tied to any specific infrastructure: they run on any computer, on any infrastructure, and in any cloud. Docker containers are basically runtime instances of Docker images.

What are Docker Images?

Docker image is the source of Docker container. In other words, Docker images are used to create containers. When a user runs a Docker image, an instance of a container is created. These docker images can be deployed to any Docker environment.

What is Docker Hub?

Docker images create docker containers. There has to be a registry where these docker images live. This registry is Docker Hub. Users can pick up images from Docker Hub and use them to create customized images and containers. Currently, the Docker Hub is the world’s largest public repository of image containers.

Step 1: Check Docker is Installed or not

$ docker info

or

$ docker - -version

Step 2: Install docker

$ yum install docker-ce

Step 3: Check if the docker is running

$ systemctl status docker

Step 4: Pull latest version of centos form dockerhub

$ docker pull centos:latest

Step 5: Create a Container with the Centos image

$ docker run -it --name=<name> centos:latest

Docker container is running now.

Step 6: Install Python and other libraries

$ yum install python3

$ pip3 install numpy

$ pip3 install pandas

$ pip3 install scikit-learn

Step 7: Create a Python file and run it.

$ vi LinearRegression.py
$ python3 LinearRegression.py

Step 8: Create a Model file.

$ vi model.py

Step 9: Run the Model file.

$ python3 model.py

Task Done!

Thanks for reading.

--

--