Docker and Kubernetes Made Relatable - II
Sampriti Mitra
Posted on October 29, 2021
Welcome back to the second part of this series.
Last time we discussed about Containers and Images and how they can be related with a workspace kit and a blueprint, respectively. In this post, we will see Docker images in action!
Now that we're here, let's get on with it!
Getting Started With Docker Images and Containers
Docker is a well-known runtime environment for creating and building applications within containers. It deploys containerized applications or software in different environments, from development to testing and production, using Docker images.
Creating a sample Go application
Let’s create a basic Go application that we will use to deploy on our minikube cluster.
Create a directory my-app which contains the below main.go file. From the command line, run the following:
go mod init
go mod tidy
Creating a Dockerfile for the Go application
To create the dockerfile for our application, we will refer to this:
Building the docker image and running the container
For building the docker image, run the following command in the terminal:
docker build --tag myapp .
docker images
You should be able to see the newly created myapp image in the list.
Now let us try running the image as a container. Since containers run in isolation, we need to expose the port inside our container to our host port.
To publish a port for our container, we’ll use the --publish flag (-p for short) on the docker run command. The format of the --publish command is [host_port]:[container_port]. So if we wanted to expose port 8080 inside the container to port 3000 outside the container, we would pass 3000:8080 to the --publish flag.
docker run -d -p 8080:10000 myapp
Open localhost:8080
in the terminal; it should say
Welcome to myapp!
Now that we have an idea about docker containers and the templates from which they are generated, i.e., images. Let’s have a look at container schedulers, which is what K8s is.
Why Do We Require Container Schedulers? Why K8s Over Containers/Docker?
We saw how useful containers can be for running applications in an isolated way, on any environment. However, in production, hundreds to thousands of different containers may be required.
Container runtime systems like Docker benefit from the usage of additional technologies to orchestrate or manage all of the containers in use.
This orchestration is handled by Kubernetes.
In the next part, we will explore what Kubernetes is and how it works.
Thanks for reading!
Posted on October 29, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.