Docker Tutorial for Windows: A Must to Know For Data Scientist

Docker tutorial for windows featured image

You must have face deployment or code running issues in your daily coding life. Right! It also happens to me. You also have seen the code you run on your computer doesn’t run on another personal computer. And it’s very frustrating to install all the dependencies and libraries required to run the code. To solve this issues, Docker came to an existence. It removes the problem faced by coders like you. Docker Tutorial for Windows is a step by step guide on how to install Docker and to make its container in windows.

Basic Definition of Docker and Container

Docker( Ship)  is an image file that has many containers. You can say it is as a template that set rules for image creation. A container is an instance of the Docker image. Suppose you have an application that requires libraries and dependencies. If you pass this application to another environment then there you have to also install these libraries and dependencies. If you will build a Container, then all packages and libraries will act as one package. Now you can ship the container to another environment easily for running the applications. Overall you can say Docker allows you to create, deploy and run the application using containers.

How to Install Docker on Window?

Docker requires Linux environment for installing. Therefore you can easily install it through the command on Linux. But on Windows, it requires Virtual Linux OS to run. Therefore Docker setup files with automatically Install VirtualBox with it.

Step 1: Download the Docker Setup File from its official URL. Install Docker For Windows. You will be directed to download the Community Edition of+ Docker. Create a community account if you don’t have otherwise log in to download the setup file. At the time of writing this post, The current version of Docker requires 64 bit Windows 10 Professional or Enterprise Edition. Click on Get Docker File to Download the file.

Download Docker File for Windows

Step 2: After the complete installation when you start docker you will get the error “hyper-v and containers features are not enabled, docker “. You should enable it to work in it. Run the command prompt as an administrator and type the following command.

containers feature not enabled docker

Type the command to enable it

dism.exe /Online /Enable-Feature:Microsoft-Hyper-V /All
bcdedit /set hypervisorlaunchtype auto

Type the Command to disable it

dism.exe /Online /Disable-Feature:Microsoft-Hyper-V
bcdedit /set hypervisorlaunchtype off

To more about it in details you can refer to StackOverflow question.

After typing the command, all things will be done automatically and windows may restart after this process. Hurray, Docker has successfully installed.

How to Create and run a Docker File?

In the above steps of docker tutorial for windows, you learned how to install Docker. In this section, you will know how to create a Docket File. I am here using the simple Python file to run it. Python File is a web app in Flask with the file name index.py.  The Following is the Flask Code.

from flask import Flask
app = Flask(__name__)
@app.route("/")
def index():
return "Welcome to the Data Science Learner!"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=int("5000"), debug=True)

Now the above code is using Flask as a requirement. Therefore I created a requiements.txt file with the following text.

Flask

Now the next step is to create a Docker File and add the following code to the File. Please make sure to save this File in the root directory. It means where the File index.py and requiements.txt has saved.

FROM python:alpine3.7
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
EXPOSE 5000
CMD python ./index.py

The complete code tells the Docker to select alpine as Unix and Python version 3.7. Therefore it will choose. It will use the Images from the Docker Base Hub. The above Python 3.7 is installed on the Alpine Linux.

The statement RUN pip install -r requirements.txt will tell the Docker to install all the dependencies required to run the Python File. The CMD directive will tell the Docker to run the index.py File.

Now the task is to build and run the Docker File. To do this, open the command prompt in the root directory and type the following command.

docker build --tag my-python-app

The tag will create a name for the Image here it is my-python-app.

Type the following command to run the Python Application in the Docker.

docker run --name python-app -p 5000:5000 my-python-app

The -name par tell the Docker to name the image as python-app and -p maps the Docker port 5000 to the host 5000 port. After running the Docker Image you can see the following output in the URL http://127.0.0.1:5000

Welcome to the Data Science Learner!

The above is the basic tutorial on how to run the Docker File. Hope this article “docker tutorial for windows ” has solved queries on Docker Installation. If you want to improve this article, Please contact us.

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

Meet Sukesh ( Chief Editor ), a passionate and skilled Python programmer with a deep fascination for data science, NumPy, and Pandas. His journey in the world of coding began as a curious explorer and has evolved into a seasoned data enthusiast.
 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner