Running an Machine Learning Model on Docker

Shashwat Misra
2 min readJul 16, 2021

Docker is an open source software platform to create, deploy and manage virtualized application containers on a common operating system (OS), with an ecosystem of allied tools.

First step is to Install the docker to your system. Next, you start your docker in your computer using “systemctl start docker”. After this you need to create a container for your docker using the command “docker run -it — name <image name>:version”, by this a container will start in background. To run a existing container you need to “attach” it by command “docker attach <dockername>”.

To run a Machine learning Model you need to have a dataset available. To transfer the dataset from your computer to you VM there are many ways, for example- WinScp for windows and FileZilla for MacOS.

Using these software transfer the dataset to your VM. Next to transfer the dataset to your docker you have to use a command “docker cp <source path> name of docker: <destination path>”. This will copy the selected file to your docker.

Now as we know each container is like a fresh intalled pc. Hence, we need to install required software to run a Machine Learning program. We need to install Python3 by using “dnf install pyhton3” or “pip3 install python3". After this we need to install libraries like sklearn, Numpy, etc necessary for the program.

After all the installation we can now create and open a python file using “vim filename.py” as docker does not support gedit command. After this you can code your ML program

Now you can execute the program just by typing “python3 filename.py” and the docker will execute your file and showcase the output.

--

--