Train ML Model inside Docker Container

What is Docker ?

Docker is a software platform for building applications based on containers — small and lightweight execution environments that make shared use of the operating system kernel but otherwise run in isolation from one another. While containers as a concept have been around for some time, Docker, an open source project launched in 2013, helped popularize the technology, and has helped drive the trend towards containerization and microservices in software development that has come to be known as cloud-native development.

What is Machine Learning ?

Machine learning is a method of data analysis that automates analytical model building. It is a branch of artificial intelligence based on the idea that systems can learn from data, identify patterns and make decisions with minimal human intervention.

Task Description 📄

👉 Pull the Docker container image of CentOS image from Docker Hub and create a new container

👉 Install the Python software on the top of docker container

👉 In Container you need to train machine learning model

Step-1: Install the Docker

  1. Configure yum for Docker :
Create a file “/etc/yum.repos.d/docker.repo”[docker]
name=docker repo baseurl=https://download.docker.com/linux/centos/7/x86_64/stable/
gpgcheck=0

Then check with “yum repolist” Some additional software can be seen.

2. Install Docker and start service :

# To Install docker
yum install docker-ce — nobest -y
# To Start Docker service
systemctl start docker
# To Enable Docker service
systemctl enable docker

Step-2 : Pull centos image from docker hub

# pull the cenots image with latest version
docker pull cenots:latest

Step-3 : Launch a container

docker run -it --name <name_of_OS> centos:latest

Step-4 : Install required packages for task

# To install python
yum install python36
# installing required libraries for taskpip3 install pandas
pip3 install scikit-learn

Step-5: Create a Docker image with commit

docker commit <os_name> <image_name>:<version>

Step-6 : Launch a container using that image

docker run -it --name <name> <image_name:version>

To verify use “docker images” command

docker images

Step-7: Copy the dataset which we want to work on

docker cp <location_in_local>  <docker_os_name>:<location_in_docker_container>

To verify is it copied or not check inside the docker container

ls

Step-8: Create Linear Regression Model

Step-9: Let’s test our model

The Output of our Machine Learning Model is

Thanks For Spending Your Time Here,

🔰Keep Learning❗❗ 🔰Keep Sharing ❗❗

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store