How to configure Docker

Last updated on Sep 16 2022
Neha Warghade

Table of Contents

How to configure Docker

Docker – Configuring

In this blog, we’ll look at the different options to configure Docker.

service docker prevent

This command is employed to prevent the Docker daemon process.

Syntax

service docker prevent

Options

None

Return Value

A message showing that the Docker process has preventped.

Example

sudo service docker prevent

Output

When we run the above command, it will produce the following result −

doc 30

service docker start

This command is employed to start the Docker daemon process.

Syntax

service docker start

Options

None

Return Value

A message showing that the Docker process has started.

Example

sudo service docker start

Output

When we run the above command, it will produce the following result −

doc 31

Docker – Containers and Shells

By default, when you launch a container, you will also use a shell command while launching the container as shown below. This is what we have seen in the earlier chapters when we were working with containers.

doc 32

In the above screenshot, you can observe that we have issued the following command −

sudo docker run –it centos /bin/bash

We employed this command to create a new container and then employed the Ctrl+P+Q command to exit out of the container. It ensures that the container still exists even after we exit from the container.

We can verify that the container still exists with the Docker ps command. If we had to exit out of the container directly, then the container itself would be destroyed.

Now there is an easier way to attach to containers and exit them cleanly without the need of destroying them. One way of achieving this is by using the nsenter command.

doc 33

Before we run the nsenter command, you need to first install the nsenter image. It can be done by using the following command −

docker run –rm -v /usr/local/bin:/target jpetazzo/nsenter

Before we use the nsenter command, we need to get the Process ID of the container, because this is required by the nsenter command. We can get the Process ID via the Docker inspect command and filtering it via the Pid.

doc 34

As seen in the above screenshot, we have first employed the docker ps command to see the running containers. We can see that there is one running container with the ID of ef42a4c5e663.

We then use the Docker inspect command to inspect the configuration of this container and then use the grep command to just filter the Process ID. And from the output, we can see that the Process ID is 2978.

Now that we have the process ID, we can proceed forward and use the nsenter command to attach to the Docker container.

nsenter

This method allows one to attach to a container without exiting the container.

Syntax

nsenter –m –u –n –p –i –t containerID command

Options

  • -u is employed to mention the Uts namespace
  • -m is employed to mention the mount namespace
  • -n is employed to mention the network namespace
  • -p is employed to mention the process namespace
  • -i s to make the container run in interactive mode.
  • -t is employed to connect the I/O streams of the container to the host OS.
  • containerID − This is the ID of the container.
  • Command − This is the command to run within the container.

Return Value

None

Example

sudo nsenter –m –u –n –p –i –t 2978 /bin/bash

Output

doc 35

From the output, we can observe the following points −

  • The prompt changes to the bash shell directly when we issue the nsenter
  • We then issue the exit Now normally if you did not use the nsenter command, the container would be destroyed. But you would notice that when we run the nsenter command, the container is still up and running.

Docker – Container and Hosts

The good thing about the Docker engine is that it is designed to work on various operating systems. We have already seen the installation on Windows and seen all the Docker commands on Linux systems. Now let’s see the various Docker commands on the Windows OS.

Docker Images

Let’s run the Docker images command on the Windows host.

doc 36

From here, we can see that we have two images − ubuntu and hello-world.

Running a Container

Now let’s run a container in the Windows Docker host.

doc 37

We can see that by running the container, we can now run the Ubuntu container on a Windows host.

Listing All Containers

Let’s list all the containers on the Windows host.

doc 38

Preventping a Container

Let’s now prevent a running container on the Windows host.

doc 39

So you can see that the Docker engine is pretty consistent when it comes to different Docker hosts and it works on Windows in the same way it works on Linux.

So, this brings us to the end of blog. This Tecklearn ‘How to Configure Docker’ blog helps you with commonly asked questions if you are looking out for a job in DevOps. If you wish to learn Docker and build a career in DevOps domain, then check out our interactive, Containerization using Docker Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

https://www.tecklearn.com/course/containerization-using-docker/

Containerization using Docker Training

About the Course

Tecklearn has specially designed this Containerization using Docker Training Course to advance your skills for a successful career in this domain. his Docker training online course will help you learn Docker containerization, running Docker containers, Docker image creation, Dockerfile, Docker orchestration, security best practices and more through hands-on projects and case studies. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Docker.

Why Should you take Containerization using Docker Training?

  • Average salary of Docker Expert is $110k – Indeed.com
  • According to Grand View Research, the DevOps market size is estimated to be worth $12.85 billion by 2025. DevOps professionals are highly paid and in-demand throughout industries including retail, eCommerce, finance, and technology.
  • Intuit, PayPal, Splunk, Uber & many other MNC’s worldwide use Docker across industries

What you will Learn in this Course?

Introduction to DevOps

  • What is Software Development
  • Software Development Life Cycle
  • Why DevOps?
  • What is DevOps?
  • DevOps Lifecycle
  • DevOps Tools
  • Benefits of DevOps
  • How DevOps is related to Agile Delivery
  • DevOps Implementation

Containerization using Docker – Part 1

  • Introduction to Docker
  • Understanding Docker Lifecycle
  • Docker Architecture
  • Components of Docker Ecosystem
  • Common Docker Operations
  • Committing changes in a Container
  • Hands On

Containerization using Docker – Part 2

  • Building Custom Docker Images
  • Docker Image
  • Introduction to Docker Swarm
  • Deploying a 2-Node Cluster using Docker Swarm
  • Hands on

 

0 responses on "How to configure Docker"

Leave a Message

Your email address will not be published. Required fields are marked *