Getting started with Dockers
This post will cover the steps required to get Docker installed on Linux host (RHEL Red Hat Enterprise Linux). In essence when we say, installing Docker, it means installing a Docker engine.
A docker container is a process which runs on a host. Docker or rather the Docker engine enables these processes to run in isolated containers. In other words, Docker makes possible or enables to create, run and manage containers on a single operating system. A Docker container contains all the application and its dependencies, thereby one can safely deploy containers without having to worry for dependencies, like OS version, and other software library dependencies. Isolated means that when the container process runs, it is isolated, i.e. it has its own file system, its own networking and its own isolated process tree separate from the host, although they are using the same kernel of the Operating system- hence containers are not totally isolated from other containers, however one can safely say there is a great degree of isolation. A containerized application is provided with an illusion so that each sees its own instance of the Operating system. Hence, one could run several containerized versions of the very same application on a host Operating System. It would not be possible to run, say several versions of one application on a host Operating system, but Docker makes this possible. When we say run a container, it means to run containerized applications. Additionally, the containerized software can be easily stopped, started as compared to virtual machines.
Why would one want to install a Docker engine? It is for making containers exist on an Operating system.
After Docker (engine) is installed on the Operating System, then you can run applications in the docker container. One installs a Docker engine on the Operating System. Next, you create a Docker image. The Docker engine will allow to run individual containers from the Docker image. Put simply a container is a runtime instance of the Docker image.
A docker container is a process which runs on a host. Docker or rather the Docker engine enables these processes to run in isolated containers. In other words, Docker makes possible or enables to create, run and manage containers on a single operating system. A Docker container contains all the application and its dependencies, thereby one can safely deploy containers without having to worry for dependencies, like OS version, and other software library dependencies. Isolated means that when the container process runs, it is isolated, i.e. it has its own file system, its own networking and its own isolated process tree separate from the host, although they are using the same kernel of the Operating system- hence containers are not totally isolated from other containers, however one can safely say there is a great degree of isolation. A containerized application is provided with an illusion so that each sees its own instance of the Operating system. Hence, one could run several containerized versions of the very same application on a host Operating System. It would not be possible to run, say several versions of one application on a host Operating system, but Docker makes this possible. When we say run a container, it means to run containerized applications. Additionally, the containerized software can be easily stopped, started as compared to virtual machines.
Example: You could run an application as a Docker container from a Docker image.
Below are steps provided to install Docker on a Linux host. Once you have Docker you can go ahead and start deploying containers, or containerized applications.
Following are the 5 steps to get Docker on Linux host
OS: RHEL 7.1
Step 1: Install docker
$sudo yum install docker
Gave error saying No package docker available. Error: Nothing to do
On RHEL instance (This was run on an aws instance of RHEL) "sudo yum install docker", command did not run (as shown above it gave error). Had to (1) first install "yum-utils" which is the utils package, and (2) enable rhui REGION command before getting the install docker to work as below commands were run in the given order
(1) $sudo yum install yum-utils
(2) $sudo yum-config-manager --enable rhui-REGION-rhel-server-extras
After above two packages were installed, now you can run the Step 1
$sudo yum install docker (Now this command worked fine, in Step 1 earlier it gave error)
For ubuntu host, the command to install docker is "sudo snap install docker"
Step 2: Check docker is correctly installed
$sudo yum info docker
This will provide you with Name, version, release, Size, etc info about docker
Commands to check status, start and stop docker service
sudo systemctl enable docker.service
sudo systemctl start docker.service
sudo systemctl stop docker.service
sudo systemctl status docker.service
Step 3: Enable docker.service
Enable docker.service and check status of the docker.service
sudo docker info (and "docker ps" commands etc) - gave the following error message
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
Only the sudo docker --version works, other docker commands are failing, as shown below in screenshot - "cannot connect to the Docker daemon. Is the docker daemon running on this host?". Because the docker.service has not been started (This is Step 4)
See below, attempt to run hello-world also fails since docker service has not been started yet. ( sudo docker run hello-world )
Step 4: Start the docker service
sudo systemctl start docker.service
After docker service has been started, docker commands, such as "docker ps", "docker info" are working fine
docker commands are running fine now. For example, "docker info" on left side and "docker ps" command above are working fine as shown in screenshots.
Step 5: Test docker by pulling an image from docker repository
(This is the final step where we will run the docker run command that will go and start the container with the provided image (or by specifying Name and Tag)
$sudo docker run hello-world
(This command as below, will actually go and download the hello-world image from docker hub, if it is not available locally. In the below screenshot it shows "Unable to find image 'hello-world:latest' locally". And then it automatically goes to the registry online to retrieve the hello-world image)
The above screenshot shows the output of the docker run command run successfully. With this docker container for hello-world ran successfully.
Here is the text output of the docker run command.
sudo docker run hello-world (the output of this command is given below)
Unable to find image 'hello-world:latest' locally
Trying to pull repository registry.access.redhat.com/hello-word ...
Trying to pull repository docker.io/library/hello-world ...
latest: Pulling from docker.io/library/hello-world
This ends the 5 steps to run a docker container. In this example we have chosen to run a simple hello-world container.
Note: You can check if the docker image "hello-world" is now available, run the command sudo docker-images (this command will give list of all docker images available locally on your host computer)
Above were the 5 steps for getting docker up and running on a Linux host. Note: sudo command was required in order to run the docker commands as root, read here.
---------------------------------------------------------------------------
References
https://hub.docker.com/_/hello-world/
https://docs.docker.com/get-started/
https://www.infoworld.com/article/3237645/what-you-need-to-know-now-about-container-standards.html
https://www.upguard.com/articles/docker-vs-coreos
https://containerjournal.com/2019/01/14/kubernetes-vs-docker-a-primer/
Dockers and Containers
--------------------------------------------------------------------------------------------------
Other miscellaneous commands and notes for reference
Docker commands
sudo docker images (listing from my linux host, below 2 apps were installed on my docker)
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/ubuntu latest 0458a4468cbc 3 weeks ago 111.7 MB
docker.io/hello-world latest f2a91732366c 12 weeks ago 1.848 kB
---------------------------------------------------------------------------
Output of docker version (from command docker --version)
Client:
Version: 1.12.6
API version: 1.24
Package version: docker-1.12.6-71.git3e8e77d.el7.x86_64
Go version: go1.8.3
Git commit: 3e8e77d/1.12.6
Built: Wed Dec 13 12:18:58 2017
OS/Arch: linux/amd64
Server:
Version: 1.12.6
API version: 1.24
Package version: docker-1.12.6-71.git3e8e77d.el7.x86_64
Go version: go1.8.3
Git commit: 3e8e77d/1.12.6
Built: Wed Dec 13 12:18:58 2017
OS/Arch: linux/amd64
sudo docker commit 359147593a16 abcd (create image from a container)
sha256:e43dc88e978e03559d86b813682ee7d83974927f3e73cc66396121390560c6e9
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
abcd latest e43dc88e978e 20 seconds ago 111.7 MB
docker.io/ubuntu latest 0458a4468cbc 3 weeks ago 111.7 MB
docker.io/hello-world latest f2a91732366c 12 weeks ago 1.848 kB
[ec2-user@ip-172-11-1-01 ~]$ sudo docker run -i -t abcd:latest
root@15e3bed30d9:/#
The new container was successfully created, and you are in the bash terminal above.
On the host server ps -a listing will show the process as docker-current. If you exit out of bash terminal (#), you exit the container, stop the process and can be verified from the ps -a from the host machine. The process, i.e. the container runs in its own file system.
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
359147593a16 0458a4468cbc "/bin/bash" 16 minutes ago Exited (0) 14 minutes ago peaceful_pike
6ee0ff632350 hello-world "/hello" 32 minutes ago Exited (0) 32 minutes ago fervent_yalow
b97bc0f39158 hello-world "/hello" 45 minutes ago Exited (0) 45 minutes ago loving_shockley
2c0c087e6daa ubuntu "bash" 14 hours ago Exited (0) 14 hours ago myLinuxContainer
3b85875ba70a hello-world "/hello" 15 hours ago Exited (0) 15 hours ago drunk_carson
c69a73ebbe91 hello-world "/hello" 15 hours ago Exited (0) 15 hours ago adoring_archimedes
98524ced1d73 hello-world "/hello" 15 hours ago Exited (0) 15 hours ago amazing_roentgen
-------------------------------------------------------------------------------------
Output of command docker ps -a will give listing of the container as below
sudo docker run --name myHello1 hello-world (This time a new container will be named as myHello1, and you can run the app with this name)
--------------------------------------------------------------------
Following are the 5 steps to get Docker on Linux host
OS: RHEL 7.1
- Step 1 Install docker (rather docker engine)
- Step 2 Check docker installed correctly
- Step 3 Enable docker service
- Step 4 Start docker service
- Step 5 Pull an image from docker repository to your local machine
Step 1: Install docker
$sudo yum install docker
Gave error saying No package docker available. Error: Nothing to do
On RHEL instance (This was run on an aws instance of RHEL) "sudo yum install docker", command did not run (as shown above it gave error). Had to (1) first install "yum-utils" which is the utils package, and (2) enable rhui REGION command before getting the install docker to work as below commands were run in the given order
(1) $sudo yum install yum-utils
(2) $sudo yum-config-manager --enable rhui-REGION-rhel-server-extras
After above two packages were installed, now you can run the Step 1
$sudo yum install docker (Now this command worked fine, in Step 1 earlier it gave error)
For ubuntu host, the command to install docker is "sudo snap install docker"
Step 2: Check docker is correctly installed
$sudo yum info docker
This will provide you with Name, version, release, Size, etc info about docker
Commands to check status, start and stop docker service
sudo systemctl enable docker.service
sudo systemctl start docker.service
sudo systemctl stop docker.service
sudo systemctl status docker.service
Step 3: Enable docker.service
Enable docker.service and check status of the docker.service
sudo docker info (and "docker ps" commands etc) - gave the following error message
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
Only the sudo docker --version works, other docker commands are failing, as shown below in screenshot - "cannot connect to the Docker daemon. Is the docker daemon running on this host?". Because the docker.service has not been started (This is Step 4)
See below, attempt to run hello-world also fails since docker service has not been started yet. ( sudo docker run hello-world )
Step 4: Start the docker service
sudo systemctl start docker.service
After docker service has been started, docker commands, such as "docker ps", "docker info" are working fine
docker commands are running fine now. For example, "docker info" on left side and "docker ps" command above are working fine as shown in screenshots.
Step 5: Test docker by pulling an image from docker repository
(This is the final step where we will run the docker run command that will go and start the container with the provided image (or by specifying Name and Tag)
$sudo docker run hello-world
(This command as below, will actually go and download the hello-world image from docker hub, if it is not available locally. In the below screenshot it shows "Unable to find image 'hello-world:latest' locally". And then it automatically goes to the registry online to retrieve the hello-world image)
The above screenshot shows the output of the docker run command run successfully. With this docker container for hello-world ran successfully.
Here is the text output of the docker run command.
sudo docker run hello-world (the output of this command is given below)
Unable to find image 'hello-world:latest' locally
Trying to pull repository registry.access.redhat.com/hello-word ...
Trying to pull repository docker.io/library/hello-world ...
latest: Pulling from docker.io/library/hello-world
This ends the 5 steps to run a docker container. In this example we have chosen to run a simple hello-world container.
Note: You can check if the docker image "hello-world" is now available, run the command sudo docker-images (this command will give list of all docker images available locally on your host computer)
---------------------------------------------------------------------------
References
https://hub.docker.com/_/hello-world/
https://docs.docker.com/get-started/
https://www.infoworld.com/article/3237645/what-you-need-to-know-now-about-container-standards.html
https://www.upguard.com/articles/docker-vs-coreos
https://containerjournal.com/2019/01/14/kubernetes-vs-docker-a-primer/
Dockers and Containers
--------------------------------------------------------------------------------------------------
Other miscellaneous commands and notes for reference
Docker commands
- sudo docker ps -a
- sudo docker run --name myHello1 hello-world
- sudo docker images
- sudo docker run -it --name myLinuxContainer ubuntu bash (by entering bash, you will directly enter into the bash interface of the ubuntu instance)
sudo docker images (listing from my linux host, below 2 apps were installed on my docker)
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/ubuntu latest 0458a4468cbc 3 weeks ago 111.7 MB
docker.io/hello-world latest f2a91732366c 12 weeks ago 1.848 kB
---------------------------------------------------------------------------
Output of docker version (from command docker --version)
Client:
Version: 1.12.6
API version: 1.24
Package version: docker-1.12.6-71.git3e8e77d.el7.x86_64
Go version: go1.8.3
Git commit: 3e8e77d/1.12.6
Built: Wed Dec 13 12:18:58 2017
OS/Arch: linux/amd64
Server:
Version: 1.12.6
API version: 1.24
Package version: docker-1.12.6-71.git3e8e77d.el7.x86_64
Go version: go1.8.3
Git commit: 3e8e77d/1.12.6
Built: Wed Dec 13 12:18:58 2017
OS/Arch: linux/amd64
----------------------------------------------------------------------------------------------------------------
What does the command docker run hello-world do?
Following is the output of the docker run hello-world.
As we can see below, the docker client contacted Docker daemon can pulled the image called as hello-world and created a new container from this image and ran the executable to produced the below output. Below is actual output by running the command sudo docker run hello-world
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
--------------------------------------------------------------------------------------------------------
sudo docker run -i -t 0458a4468cbc (image name)
Docker runs processes in isolated containers. A container is a process which runs on a host. The host may be local or remote. When an operator executes
The docker run command will go and start the container with the provided image. Other ways of starting are by Name and Tag
-----------------------------------------------------------------------------------------------------------------------
Create image from a containersudo docker run -i -t 0458a4468cbc (image name)
Docker runs processes in isolated containers. A container is a process which runs on a host. The host may be local or remote. When an operator executes
docker run
, the container process that runs is isolated in that it has its own file system, its own networking, and its own isolated process tree separate from the host.The docker run command will go and start the container with the provided image. Other ways of starting are by Name and Tag
-----------------------------------------------------------------------------------------------------------------------
sudo docker commit 359147593a16 abcd (create image from a container)
sha256:e43dc88e978e03559d86b813682ee7d83974927f3e73cc66396121390560c6e9
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
abcd latest e43dc88e978e 20 seconds ago 111.7 MB
docker.io/ubuntu latest 0458a4468cbc 3 weeks ago 111.7 MB
docker.io/hello-world latest f2a91732366c 12 weeks ago 1.848 kB
[ec2-user@ip-172-11-1-01 ~]$ sudo docker run -i -t abcd:latest
root@15e3bed30d9:/#
The new container was successfully created, and you are in the bash terminal above.
On the host server ps -a listing will show the process as docker-current. If you exit out of bash terminal (#), you exit the container, stop the process and can be verified from the ps -a from the host machine. The process, i.e. the container runs in its own file system.
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
359147593a16 0458a4468cbc "/bin/bash" 16 minutes ago Exited (0) 14 minutes ago peaceful_pike
6ee0ff632350 hello-world "/hello" 32 minutes ago Exited (0) 32 minutes ago fervent_yalow
b97bc0f39158 hello-world "/hello" 45 minutes ago Exited (0) 45 minutes ago loving_shockley
2c0c087e6daa ubuntu "bash" 14 hours ago Exited (0) 14 hours ago myLinuxContainer
3b85875ba70a hello-world "/hello" 15 hours ago Exited (0) 15 hours ago drunk_carson
c69a73ebbe91 hello-world "/hello" 15 hours ago Exited (0) 15 hours ago adoring_archimedes
98524ced1d73 hello-world "/hello" 15 hours ago Exited (0) 15 hours ago amazing_roentgen
-------------------------------------------------------------------------------------
Output of command docker ps -a will give listing of the container as below
sudo docker run --name myHello1 hello-world (This time a new container will be named as myHello1, and you can run the app with this name)
--------------------------------------------------------------------
I never stop myself to say something about it. You’re doing a great job. Keep it up... DevOps Training in Bangalore | Certification | Online Training Course institute | DevOps Training in Hyderabad | Certification | Online Training Course institute | DevOps Training in Coimbatore | Certification | Online Training Course institute | DevOps Online Training | Certification | Devops Training Online