Divesh Karkera
4 min readMay 27, 2021

--

How to Load a Machine Learning Model in Docker.

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and deploy it as one package.

Step1: The first step is to Install the Docker.

Step 2: Pull the Centos Image from Dockerhub.

Command: “docker pull centos: latest”

Step 3: Create a container with the help of a centos image.

Command : “docker run -it — name=container_name centos:latest”

You can use the above command to create a Container, As I have already created a container I will just start my Docker and Enter my Container. command: 1) systemctl start docker

command: 2) docker start “Container name

command: 3) docker attach “Container name”

in my case, the Container name is “myos1

Step 4: Install the Python software on the top of the docker container

Command: “yum install python3”
you can use this command if you haven't installed python3. As I have already Installed Python earlier you can see the terminal showing python is already installed.

Step 5: Install the required Python packages on the top of the docker container.

Packages are Important Because You can solve algebraic formulas, perform common statistical operations, and much more. While NumPy is a valuable Python package for a variety of general-purpose programming tasks, it’s particularly important if you want to do machine learning as it provides Various Libraries.

Commands to install Packages are :

“pip3 install NumPy”

“pip3 install pandas”

“pip3 install scikit-learn”

Step 6: Now inside this container we need to copy/create our machine learning model on whichever dataset we want.

Before I show you how to create or run our machine learning model I would like to show you a very important step.

What if your data, which you are going to work with is in another OS? It's actually very easy what we have to do is we have to download Winscp. WinSCP is an open-source free SFTP client, FTP client, WebDAV client, S3 client and SCP client for Windows. Its main function is file transfer between a local and a remote computer. Beyond this, WinSCP offers scripting and basic file manager functionality.

Step6.1: Go to your Linux Terminal and type the command: ifconfig enp0s3.

Step6.2: Now open Winscp and write the inet address in the hostname followed by the system and password.

Step 6.3: As soon as you enter you will find two screens as you can see below the left screen is my windows and my right screen is Linux. you have to just drag the file and drop the file at its location.

You can see I have dragged one image file from left to right.

In the same way, I have saved my Datafile that is Salary. data.csv

Now coming back to the container we need to copy/create our machine learning model on whichever dataset we want.

Step 7: Here We create A predict file.

We access the vi editor and write our code. Here we are writing a code in which the user will enter his year of experience and on the basis of his experience how much will the company pay’s him as a salary

here I have saved the file name as task1.py

Step8: Run the model

Years of experience as you can see I have inserted 2 and we get our answer is the amount that the company offers as salary based on your experience.

Thank you for reading this blog!

--

--