DevOps Certification Training Course
- 139k Enrolled Learners
- Weekend/Weekday
- Live Class
If you’re looking for simple and painless software deployment, Docker is the right tool for you. It is the best containerization platform and in this blog on Docker for Windows we’ll specifically focus on how Docker works on Windows.
To get in-depth knowledge on Docker, you can enroll for live DevOps Certification Training by Edureka with 24/7 support and lifetime access.
I’ll be covering the following topics in this blog:
Why use Docker for Windows – Docker for Windows
You can get a better understanding with this Online Docker Course.
Docker for Windows – Prerequisites
The following requirements need to be met before installing Docker on windows:
Components installed with Docker – Docker for Windows
If you want to learn more about Docker for Windows, check out this video by our DevOps experts.
Docker is a containerization platform that runs applications within containers called Docker containers. Docker containers are light weighted when compared to virtual machines. When you install a Virtual machine on your system, it uses the guest operating system on top of your host operating system. This obviously takes up a lot of resources like disk space, RAM, etc. On the other hand, Docker containers make use of the host operating system itself.
What is Docker – Docker for Windows
In the above image, you can see that, there’s a host operating system on top of which the Docker engine is mounted. The Docker engine runs container #1 and container #2. Both of these containers have different applications and each application has its own libraries and packages installed within the container.
I hope you have a good idea about what Docker is if you still have doubts check out this blog to learn more!
Let’s discuss some Docker terminologies now:
Docker images are read-only templates to build Docker images. Docker images are created from a file called Dockerfile. Within the Dockerfile, you define all the dependencies and packages that are needed by your application.
Every time you run a Docker image, it runs as a Docker container. Therefore, a Docker container is the run time instance of a Docker image.
Docker’s registry, known as DockerHub is used to store Docker images. These images can be pulled from the remote server and can be run locally. DockerHub allows you to have Public/Private repositories.
Docker swarm is a technique to create and maintain a cluster of Docker engines. A cluster of Docker engines comprises of multiple Docker engines connected to each other, forming a network. This network of Docker engines is called a Docker swarm. A Docker manager initiates the whole swarm and the other Docker nodes have services running on them. The main goal of the Docker manager is to make sure that the applications or services are running effectively on these Docker nodes.
Docker compose is used to run multiple containers at once. Let’s say that you have 3 applications in 3 different containers and you want to execute them at once. This is where Docker compose comes in, you can run multiple applications in different containers at once, with a single command, which is docker-compose up.
We’ll begin our demo by installing Docker for windows. But before we do that, check if you’ve met the prerequisites.
One more thing to note is since Docker for Windows requires Microsoft’s Hyper-V and once it’s enabled, VirtualBox will no longer be able to run virtual machines. So you can’t run Docker for Windows and a VirtualBox on the same system, side by side.
Installation – Docker for Windows
Enough of theory, let’s get our hands dirty and create a simple Python web application by using Docker Compose. This application uses the Flask framework and maintains a hit counter on Redis.
Flask is a web development framework, written in Python and Redis is an in-memory storage component, used as a database. You don’t have to install Python or Redis, we’re simply going to use Docker images for Python and Redis.
In this demo we’re going to use Docker compose to run two services, namely:
What does the application do? It maintains a hit counter every time you access a web page. So each time you access the website the hit counter gets incremented. It’s simple logic, just increment the value of the hit counter when the web page is accessed.
For this demo, you’ll need to create four files:
Below is the Python file (webapp.py) that creates an application by using the Flask framework and it maintains a hit counter on Redis.
import time import redis from flask import Flask app = Flask(__name__) cache = redis.Redis(host='redis', port=6379) def get_hit_count(): retries = 5 while True: try: return cache.incr('hits') except redis.exceptions.ConnectionError as exc: if retries == 0: raise exc retries -= 1 time.sleep(0.5) @app.route('/') def hello(): count = get_hit_count() return 'Hello World! I have been seen {} times. '.format(count) if __name__ == "__main__": app.run(host="0.0.0.0", debug=True)
The requirements.txt file has the name of the two dependencies, i.e. Flask and Redis that we’ll be installing in the Dockerfile.
flask redis
The Dockerfile is used to create Docker images. Here, I’m installing python and the requirements mentioned in the requirements.txt file.
FROM python:3.4-alpine ADD . /code WORKDIR /code RUN pip install -r requirements.txt CMD ["python", "webapp.py"]
The Docker compose file or the YAML file contains two services:
version: '3' services: web: build: . ports: - "5000:5000" redis: image: "redis:alpine"
You can now run these two services or containers by using the following command:
docker-compose up
To view the output you can use Kitematic. To open Kitematic, right click on the whale icon on the status bar.
Kitematic – Docker for Windows
On the top left-hand corner, you can see the two services running.
Kitematic – Docker for Windows
This is what the output looks like. When you refresh the page, the hit count gets incremented.
Output – Docker for Windows
With this, we come to the end of this blog. I hope you have a better understanding of how Docker works on Windows. Stay tuned for more blogs on the most trending technologies.
If you found this Docker for Windows blog relevant, check out the DevOps training by Edureka, a trusted online learning company with a network of more than 450,000 satisfied learners spread across the globe. The Edureka DevOps Certification Training course helps learners gain expertise in various DevOps processes and tools such as Puppet, Jenkins, Docker, Nagios, Ansible, and GIT for automating multiple steps in SDLC.
Course Name | Date | |
---|---|---|
DevOps Certification Training Course | Class Starts on 21st January,2023 21st January SAT&SUN (Weekend Batch) | View Details |
DevOps Certification Training Course | Class Starts on 30th January,2023 30th January MON-FRI (Weekday Batch) | View Details |
DevOps Certification Training Course | Class Starts on 20th February,2023 20th February MON-FRI (Weekday Batch) | View Details |
edureka.co