Docker Fundamentals

Docker Fundamentals

DevOps Blog: 4

Before proceeding to the definition and significance of Docker, it is important to understand why should we use docker as a DevOps Engineer. What are the requirements that Docker fulfills?

Let's understand it with an example, let's say the development team created an application 'A' in Python language using Django framework and shared the same with the operations team to deploy it. But the code did not work with the operations team as the software dependencies are not installed on their side. In this case, the conflict will be there. Both teams are doing well on their behalf but the problem was the software dependencies that should be installed in the system to run that application. Now to resolve this conflict, Docker Engine comes into the picture.

Docker

It is a virtual machine that allows the applications to use the Linux kernel of the same machine on which it is installed rather than creating a separate operating system done by most virtual machines. Docker can make the applications ready to ship to other machines running the same Linux OS with somewhat different configurations. The only requirement to run the docker-based application is Docker Engine.

In other words, Docker is a software platform that allows you to build, test, and deploy applications quickly. Docker packages software into standardized units called containers that have everything the software needs to run including libraries, system tools, code, and runtime. Using Docker, you can quickly deploy and scale applications into any environment and know your code will run.

To start with Docker, one should know how to write a Docker file which is used to make images. Once an image is built from a Docker File, it is then run to containerize the application.

It is to be noted that from a single Docker file, only one image can be built whereas from one image multiple containers can be made and run simultaneously. These images can be imported from DockerHub which is just like GitHub, the global platform which has a plethora of images and can be used to generate containers.

The container consists of a bundle of code and dependencies which can be shipped to any platform to run the particular application for which it was made. That is why its symbol is like a ship containing containers.

Aim: To run Jenkins server using Docker

Step-1: Create an ec2 instance on AWS and install docker on it. Check if is there any container running.

docker ps To check the running containers.

If you got the error: "Permission Denied", fix it by adding the current user to assign all the privileges and then reboot the system. Now, again build a new connection using an SSH client as shown below.

Step-2: Pull Jenkins image from Docker Hub

docker pull <image_name>

docker pull jenkins/jenkins

Step-3: Run the image as a container with the arguments as container name, port etc.

docker run -d --name <container-name> -p <port mapping> <image_name:tag>

docker run -d --name jenkins-server-docker -p 8080:8080 jenkins/jenkins:latest

Check the running containers, you will find your container in the list.

One thing to note here is, for successful mapping, the ports should be open to all traffic under the inbound rule of the security group of your ec2 instance. If it is not predefined, you need to add a custom rule as a new inbound rule as shown below.

Now, copy the public id of your ec2 instance and map it to port 8080 in a new tab; you will find Jenkins running on the server.

There are some basic docker commands written below as:

  • Use the docker run command to start a new container and interact with it through the command line.

  • Use the docker inspect command to view detailed information about a container or image.

  • Use the docker port command to list the port mappings for a container.

  • Use the docker stats command to view resource usage statistics for one or more containers.

  • Use the docker top command to view the processes running inside a container.

  • Use the docker save command to save an image to a tar archive.

  • Use the docker load command to load an image from a tar archive.

    Below is an example of using docker inspect command. In the same way, the above-listed commands will be used in coming blogs.

All done for the basic understanding of docker. Thanks for reading the blog. Stay Tuned. Hope you find it interesting and informative. Will upload the next blog on Docker projects.

Happy Learning :)- Neha Bhardwaj