Reading Time: 4 minutes

What is Docker ?

Docker is an open source technology that helps simplify the process of developing, deploying, and running applications. It allows you to separate your applications from your infrastructure and you can deploy your software quickly.

Docker Components:

Docker engine:-

It is the core part of the whole docker system, follows client-server architecture and runs on the host machine.

Docker engine has three main components:

  1. Server: A server which is a type of long-running program called a daemon process. t can create and manage images, Containers, networks, etc.
  2. Client: Command Line Interface (CLI) is a client which is used to interact with dockerd.

Docker daemon:

The Docker daemon runs on the host operating system.It along with Containerd and runc is responsible for running and managing the containers. It can communicates with other daemons and provide various objects for eg. images, containers, networks and storage.

Docker Client:

Docker users can interact with Docker through a client. When any docker commands runs, the client sends them to dockerd daemon, which carries them out. Docker API is used by Docker commands. It is possible for Docker client to communicate with more than one daemon.

Connecting to a remote docker engine:

Most of the time we connect to Docker running on our local machine, but you can also connect to Docker on a different machine too.

There are two ways to deploy it on the remote host:

1. Using the DOCKER_HOST environment variable to set up the target engine.

DOCKER_HOST environmental variable is used to set the url to a docker engine which can be local or remote.

How to connect to remote docker engine using DOCKER_HOST environment variable

Let’s see what happens when we list containers locally and on a remote host.

  1. Show all the local containers using this command:

docker container ls

2. The DOCKER_HOST variable has different syntax, including tcp: // to connect to an export port and unix: /// to connect to a local socket. The easiest method to configure securely is to use ssh as we did below.

Docker_HOST=”ssh://ubuntu@ip” docker run -dP nginx

3. Showing all the running containers on the instance.

docker ps

2. Using docker context.

Docker context:

A single CLI can have multiple contexts. Each context contains all of the endpoint and security information needed to manage a different cluster or node. This command makes it easy to configure these contexts and switch between them.

  1. This command is used for adding the key temporarily to the ssh agent:

ssh-add <path_to_the_.pem_file>

2. The simple way to see what a context looks like is to view the default context:

docker context ls

This shows a single context called “default”. It’s configured to talk to a Swarm cluster through the local /var/run/docker.sock Unix socket.

3. This command used for create the docker context:

docker context create docker-machine –docker “host=ssh://ubuntu@ip

4. And again list our context to see that is used this command:

docker context ls

5. Note that if we list the containers, we see only the container running on the local docker engine as we haven’t switched our context:

docker container ls

6. we can change our context with the use command:

docker context use docker-machine

7. verify if the context has been switched using:

docker context ls

Now open the new terminal and login into remote server using this commands.

Using this command you can pull any images from Docker Hub and you can run this images on your instance.

docker pull nginx

This last step verify that my connection is established on local.

Written by 

I am an enthusiastic , hard-working and determine girl with strong attention to detail and eager to learn about new technologies.