How to train Machine inside the docker container

MD MOQADDAS
5 min readMay 30, 2021

Hello in this article i am going to discuss how to train Machine inside docker container.

So first let’s take a look at headlines.

  • How to install docker
  • How to start and enable the docker
  • How to install python in docker container & trouble shooting an error
  • How to train Machine Inside docker
  • How to copy the file ?
  • How to install libraries like sklearn, pandas
  • How to write ML code and RUN

How to install docker -:)

I am going to download the docker in Red Hat Enterprise Linux 8.

You can use any operating system but for this, you can configure the package installer according to the os and just install it, afterward all the processes will remain the same.

  1. Configure Yum Repo -:
open file as
putting these data inside this repo

Put these data inside “docker.repo”

[docker]

baseurl=https://download.docker.com/linux/centos/7/x86_64/stable/

gpgcheck=no

2. Now install docker -:

Installing docker

How to Start and Enable the docker daemon or service -:

To start the docker service
To enable the docker service permanent
To see the status of the docker container

How to install python in a docker container & trouble shoot an error-:)

Okay, now move forward, so here I am going to install python inside docker before go ahead I want to tell you something about docker,

We know a docker is a container tool that is used to launch an entire OS in just within a second, so to install python we have to first launch the OS or I can say launch the docker container

So let’s run the docker container

We know to start the os we need an image, so in docker world, we also need an image, here I am using CentOS image

Let’s install the CentOS image

“docker pull centos”

Now, launch the docker container

Launching the docker container

Now this OS is totally independent, before install python, i want to show here, there python installed or not

See python not installed

So let’s install python inside a docker container

When we trying to install python then it shows an error,

The reason behind this error only because the firewall

So some command here, just run in your Red hat Linux and then again install.

firewall-cmd --zone=public --add-masquerade --permanentfirewall-cmd --zone=public --add-port=443/tcpfirewall-cmd --reload systemctl restart docker

Now you can able to download the python3

How to train Machine Inside docker -:)

Keep in mind you have dataset, either you can download in docker host or inside docker container, but here i am going to download the data inside docker host,

How to copy the file ?

Here, I am going to copy the dataset from windows to Red Hat Linux and then Red Hat Linux to Docker Container

Note -: At least dataset should be in Windows

Step1: Install the “WinScp” software in windows

use above link to install WinScp

step2 : First see the IP address of Red Hat Linux

Step3: Now open “WinScp”

username@ip_address

step4: Drag and Drop, either we can do from windows to linux , linux to windows

By drag and drop we can
After copying the file you can see here

step 5 : Now we have to copy this file inside the docker container

To copy the data from Docker Host to container
See data come up inside docker container

Let’s train the Machine -:)

step1: First i am going to open a file called “mtrain.py”

step2: Now i am going to write all the code regarding my dataset

This one is simple Linear Regression code

step3: Let’s run the code and see what happend

After running error come, It says “pandas” Module not found it means we have to install because this is diffrent OS altogether.

step4: Installing “pandas”

This command install pandas

step5: Let’s again run the app

Again error come up, it also says that “sklearn” module not found so we have to install this module also

This will install “sklearn”

step6: Let’s again run the app

Now finally machine training completed.

Okay, this is all about the How to train Machine inside docker container

MD MOQADDAS

Keep Learning Keep Sharing

--

--