Category Archives: Docker

AWS DevOps Course for Freshers with Project level tasks:

This course is designed for the Freshers by a three Decades globally experienced IT professional after studying many consulting projects and the skill gap issues of different project teams.
They can show these course project tasks, done by them during the course, in their profile.
The participant will be able to attend the interview for an AWS-DevOps fresher position, along with the live screen test without a Proxy interview. Interview preparation coaching will be given.
During the job; they will be honored for their skills learnt from this course and self demonstration in the team to complete the project task before the schedule. This can add value for the candidate’s future appraisals and for their IT ladder growth.
Its Purely, A job oriented course for Freshers with Live similar project activities through IT experienced professional. You will be enforced to do the tasks in the session. The Coacher/trainer will not touch the screen for lab demo.
Note: All the tasks the student will do as a demo in the session. Before coming to the demo he/she need to practice through material given to them. This makes the participant highly self motivated with confidence on technical learning. It motivates them for the job activities also, during their job.

For the course details, watch the below video:

If somebody want to attend the Basic AWS Course, before understanding the AWS-DevOps course they can see the below video and come for a call to know the details on it.

NOTE: This play list contains the videos made on the list of AWS courses made for freshers. The freshers when they are in project, they need to understand the infrastructure requirements and their tasks. During the course they coached on these areas well. And also they will be enforced to do some project activities with a requirement. And they need to present it in a team. This can give very high confidence to them not only to perform well in the interviews and also on the live project activity comparatively with many proxy interviews managed freshers.

https://www.facebook.com/watch/347538165828643/309818167129036/

For some more details on the course, visit:

https://vskumar.blog/2020/10/08/cloud-cum-devops-coaching-your-investigation-and-actions/

You can see some of the learners sessions:

For freshers/OPTs: For Agile/DevOps/AWS training contact for schedules

For course:

  1. This is for OPTs and the Indian colleges fresh graduates who came/passed out in 2019.

  2. who are self driven and try for jobs with the given skills learning without getting into somebody shoes, come and get trained. You wouldn’t see the labs as demos. You will be practicing the labs as per the coacher guidelines with his watching. So that you will gain the technical competency with self confidence.

  3. A new batch is planned in a cost effective way. Contact in the given FB links from the blog. Good luck in your job search and in IT profession.

  4. Also, visit the below blogs for  AWS Basic course and the AWS-DevOps: https://vskumar.blog/2019/05/04/for-freshers-opts-for-agile-devops-aws-training-contact-for-schedules/
  5. https://vskumar.blog/2020/08/21/aws-devops-course-for-freshers-with-project-level-tasks/
  6. If you are keen in doing a fast track course to attack the job market instead of learning by self for months together and  getting struck to move forward, you can opt for #4 and #5.  Read the videos descriptions also. The contact details are given on this web page logo.

For specimen sessions you can watch the below videos:

  1. Agile: What are Agile manifesto Principles & How they can be used for SW ?
    https://www.facebook.com/328906801086961/videos/617149372179077/
  2. Agile: What are the phases of Agile Project ?
    https://www.facebook.com/328906801086961/videos/183496779674097/
  3. Agile: What is Disciplined Agile Delivery[DAD] ?
    https://www.facebook.com/328906801086961/videos/184822556096397/
  4. Agile: What is Model Storming ?
    https://www.facebook.com/328906801086961/videos/493982721500147/
  5. Agile: What is Scrum Framework and its roles ?
    https://www.facebook.com/328906801086961/videos/878197645967794/

Free-orientation-for Freshers-2019

Join in the below group to follow the above guidelines:

https://www.facebook.com/groups/817762795246646/

This group is meant only for freshers/OPTs coaching on the topics mentioned in the group Logo. You can forward to your circles who all came out from college for latest passed out year. They need to provide evidences as they are from latest batch only. The FB ID need to have photo with profile details. With these specs only they are allowed in this group.

For course: This is for OPTs and the Indian college graduate who came/passed out in 2019. who are self driven and try for jobs with the given skills learning without getting into somebody shoes, come and get trained. A new batch is planned in a cost effective way. Contact in the given FB links from the blog. Good luck in your job search and in IT profession.

https://www.linkedin.com/jobs/aws-jobs/

You can also see the Basic AWS and DevOps course details from the below blog/videos:

https://vskumar.blog/2020/08/21/aws-devops-course-for-freshers-with-project-level-tasks/

Simplifying Monolithic Applications with Microservices Architecture

Micro-services-1

Introduction

Monolithic applications have been around for a long time and have been a popular approach for building complex software systems. However, as the complexity of the systems grew, so did the size and complexity of monolithic applications. This led to several challenges, such as scalability, maintenance, and deployment issues. Microservices architecture is a new approach that has gained popularity in recent years due to its ability to simplify monolithic applications. In this blog post, we will discuss how microservices can be used to simplify monolithic applications.

What are Microservices?

Microservices architecture is a software development approach that emphasizes the creation of small, independent services that work together to form a larger application. These services are loosely coupled and communicate with each other through APIs. Each service is responsible for a specific business function, and they can be deployed and scaled independently of each other.

How can Microservices simplify Monolithic Applications?

  1. Scalability

One of the main advantages of microservices architecture is scalability. With monolithic applications, scaling requires scaling the entire application, which can be a challenging and expensive process. With microservices, individual services can be scaled independently, making it easier and more cost-effective to scale the system. This means that the system can handle increasing traffic and load without sacrificing performance.

  1. Maintenance

Monolithic applications are often difficult to maintain due to their size and complexity. Making changes to a monolithic application requires extensive testing and can be time-consuming. Microservices, on the other hand, are smaller and more modular, making them easier to maintain. Changes to a single service can be made without affecting other services, which reduces the risk of unintended consequences.

  1. Deployment

Deploying monolithic applications can be a complicated process. A small change to the code can require the entire application to be re-deployed. This can lead to downtime and disruptions for users. Microservices architecture simplifies deployment by allowing each service to be deployed independently. This means that changes to a single service can be deployed without affecting other services.

  1. Flexibility

Microservices architecture provides greater flexibility than monolithic applications. Services can be written in different programming languages and can be hosted on different servers or cloud providers. This allows organizations to choose the best technology for each service, which can improve performance and reduce costs.

  1. Resilience

Monolithic applications are more susceptible to failures because a single failure can bring down the entire application. With microservices, individual services can fail without affecting other services. This makes the system more resilient and reduces the risk of downtime.

Conclusion

Microservices architecture provides several benefits over monolithic applications. It simplifies scalability, maintenance, deployment, and provides greater flexibility and resilience. However, it’s important to note that microservices architecture is not a silver bullet solution. It requires careful planning and implementation, and it may not be suitable for every application. Nonetheless, microservices architecture has become a popular approach for building complex software systems, and it’s worth considering for organizations looking to simplify their monolithic applications.

Microservices can be called as another revolution in IT Industry to simplify the applications engineering/maintenance/operation. These can be operated through Containers.

https://www.facebook.com/MicroServices-and-Docker-328906801086961

The attached Video class has the discussion on this topic for your free learning:

19. DevOps:How to upload your docker image to your dockerhub account ?

Docker-logo

How to upload your docker image to your dockerhub account from Ubuntu  ?

In my previous session, we have created the MySQL docker image.

Now let us assume, we need to move into a private registry of dockerhub to save it.

In this exercise we will see:
1. How to use dockerid and tag the image ?
2. How to list the images with dockerid ?
3. How to login to dockerhub with your id ?
4. How to upload your docker image to your docker account and registry ?

Pre-requisites: You need to have your dockerid from https://hub.docker.com/

======>Current mysql images====>
vskumar@ubuntu:~$ sudo docker image ls mysql*
[sudo] password for vskumar:
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 5d4d51c57ea8 5 weeks ago 374MB
vskumar@ubuntu:~$
==================>

1. How to use dockerid and tag the image ?

My docker id is: vskumardocker
== Using docker id into local variable====>
vskumar@ubuntu:~$
vskumar@ubuntu:~$ export DOCKERID=vskumardocker
vskumar@ubuntu:~$ echo $DOCKERID
vskumardocker
vskumar@ubuntu:~$
==================>

= Tagging with dockerid ====>
vskumar@ubuntu:~$ sudo docker image build –tag $DOCKERID/mysql .
ERRO[0301] Can’t add file /home/vskumar/.gnupg/S.gpg-agent to tar: archive/tar: sockets not supported
ERRO[0324] Can’t add file /home/vskumar/.local/share/ubuntu-amazon-default/ubuntu-amazon-default/SingletonSocket to tar: archive/tar: sockets not supported
Sending build context to Docker daemon 808MB
Step 1/2 : FROM mysql
—> 5d4d51c57ea8
Step 2/2 : CMD [“echo”, “This is Mysql done by vskumar for a lab practice of dockerfile”]
—> Using cache
—> 659477c48f0a
Successfully built 659477c48f0a
Successfully tagged vskumardocker/mysql:latest
vskumar@ubuntu:~$
== Tagged mysql image =======>

=== Let us check it ===>
vskumar@ubuntu:~$ sudo docker image ls |more
REPOSITORY TAG IMAGE ID CREATED SIZE
vskumardocker/mysql latest 659477c48f0a 4 weeks ago 374MB
mysql latest 5d4d51c57ea8 5 weeks ago 374MB
== Newly tagged image is there ====>

2. How to list the images with dockerid ?

You can also list the images with dockerid assigned as below:

= How to list the images with dockerid? ====>
vskumar@ubuntu:~$ sudo docker image ls -f reference=”$DOCKERID/*”
REPOSITORY TAG IMAGE ID CREATED SIZE
vskumardocker/mysql latest 659477c48f0a 4 weeks ago 374MB
vskumar@ubuntu:~$
=======>

3. How to login to dockerhub with your id ?

=== Login to dockerhub====>
vskumar@ubuntu:~$ sudo docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don’t have a Docker ID, head over to https://hub.docker.com to create one.
Username: vskumardocker
Password:
Login Succeeded
vskumar@ubuntu:~$
============>

4. How to upload your docker image to your docker account and registry ?

Now, let us use docker push command to push the image to dockerhub:

=== Pushing the image to dockerhub account registry ===>
vskumar@ubuntu:~$ sudo docker image push $DOCKERID/mysql:latest
The push refers to repository [docker.io/vskumardocker/mysql]
12ea28f10d69: Mounted from library/mysql
400836ab4664: Mounted from library/mysql
17d36ba94219: Mounted from library/mysql
d7758e0ab2b0: Mounted from library/mysql
921bf5c178ac: Mounted from library/mysql
3cf1630a511d: Mounted from library/mysql
b80c494a1fdc: Mounted from library/mysql
7b2001677ac9: Mounted from library/mysql
8b452d78b126: Mounted from library/mysql
292c1ee413d0: Mounted from library/mysql
014cf8bfcb2d: Mounted from library/mysql
latest: digest: sha256:09ebaab0035b1955a83646ea41f43a2cd870c934a2255da090918ff7ad37dd0f size: 2621
vskumar@ubuntu:~$
==Note, repository name, TAG should be there correctly ===>

Now, we can see this image on the web page of the docker account:
===== pushed Image onto dockerhub web page ====>
I found the image on the web page with the below name:
vskumardocker/mysql
public
=====================>

 

 

 

20. DevOps:How to Install docker for Windows 10 and use for containers creation ?

How to Install docker for Windows 10 and use for containers creation ?:

Docker-logo

 In this blog,  I have shown the steps for  docker installation on Windows10 OS.

To install the docker for windows 10 OS, you need to download the docker-install.exe from the below url:

https://github.com/boot2docker/windows-installer/releases/tag/v1.8.0

 I have copied all the screens below, while doing my installation.  

You can follow the same.

Docker-Win10-install-screens.jpg

Check on your desktop for boot2docker icon.

You can also install docker toolbox as below:

Dockertoolbox-steps.jpg

Now, go to your Boot2Dcoker icon on your desktop.

Double Click on it.

In the following screens you can see with its start process.

Start-Bootdocker-screens.jpg

You can use the below blogs for containers creation.

https://vskumar.blog/2017/11/27/4-devops-how-to-work-with-docker-containers/

https://vskumar.blog/2017/11/28/5-devops-how-to-work-with-docker-images/

https://vskumar.blog/2017/12/12/13-devops-working-with-dockerfile-to-build-apache2-container-2/

2. Graph database/Docker: How to install Neo4j on a docker container? [for Ubuntu 18.04 VM]

Neo4j                                                                                                      Docker-logo

I have shown in this blog/video on the “Installing Neo4j DB on a Docker container using Ubuntu 18.04 VM”.

Through this blog and video, I have demonstrated the below functions:

a) How to install docker on an Ubuntu 18.04 VM?

b) How to create the Neo4j container from the image ?

c) How to use the container for neo4j browser ?

d) How to login and operate the options ?

c) Then how to shutdown the neo4j container ?

On all the above steps, a practiced video is made for your lab practice.

This is attached at the end of this blog.

Step1:
Initially, we need to check whether the prerequisite packages are installed.
To check, perform the following:

sudo apt-get -y install apt-transport-https ca-certificates curl

Step2:
Then, add the docker.com keys to our local keyset:

sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add –

Step3:
Next, Add the Docker repository to our system (Ubuntu users, I am assuming you have a 64-bit CPU in your VM):

sudo add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable”

Step4:
Now, we need to work on Preparing the filesystem.
As we planned want need to keep track of the logs and be able to reuse our data, we will need to give the
Docker image some access to our filesystem.
In our home folder [~], let’s create a Neo4j folder and two subfolders named logs and data.
This below script will do it on a Linux platform:
cd ~
mkdir neo4j
cd neo4j
mkdir logs
mkdir data

Enter the above steps in a .sh script.

Step5:
How to Run Neo4j in a Docker container ?:
I need to run the below command;

sudo apt install docker.io

Now, we can run the below long command in a Terminal to run Docker with a Neo4j image.

sudo docker run –rm –publish=7474:7474 –publish=7687:7687 –volume=$HOME/neo4j/data:/data \
–volume=$HOME/neo4j/logs:/logs neo4j:3.1.2

This command triggered some downloading because our local Docker repository does not have the
Neo4j image available in its 3.1.2 version yet.

Ports used by Neo4j are 7474, 7473, and 7687, for the protocols http, https, and bolt, respectively .
In the parameters part, you can see–volume twice.
Its use is to link the folder on the local filesystem to the container filesystem.

Step6:
Providing the port numbers given as parameters were not in use,
the Terminal should display something like this:

Remote interface available at : http://localhost:7474

Now, it denotes our Docker container started for Neo4j.

This informs us that Neo4j is expecting us to connect on port 7474 as usual.
So let us fire our browser and browse to the very same
URL we saw earlier, http://localhost:7474, and go graphing!
(Make sure our data will be persisted on disk.)

Step7:
now, How to stop Docker running your image ?

In order to stop Docker , you need to pass not the name (of the image)
but the identifier of the running container (based on the image).

So, in another Terminal, let us type as follows to know the status of containers:
docker ps

This will list all the containers running, in our case, only one.
So we look at the first column, container_id, and use it as a parameter:
docker stop container_id

You can watch the terminal screen.
Docker container stopped as it should be stopped with this command.

For typical installation procedure of neo4j visit my blog:

https://vskumar.blog/2017/12/08/how-to-install-neo4j-3-2-6-graph-database-on-ubuntu/

 

 

Vcard-Shanthi Kumar V-v3

Advt-course3rd page

18. DevOps: How to create a MySQL docker container ?

Docker-logo

MySql DB docker container:

In this blog I would like to demonstrate the container creation for MYSQL DB.

The following dockerfile code can be used to create the mysqldb container:
I have made this as  group of commands to be executed from Ubuntu CLI.
=== Dockerfile code for MySql DB=====>
sudo docker container run \
–detach \
–name mysqldb \
-e MYSQL_ROOT_PASSWORD=my-secret-pw \
mysql:latest
=== To create mysqldb container ====>

=== Screen output ====>
vskumar@ubuntu:~$
vskumar@ubuntu:~$ sudo docker container run \
> –detach \
> –name mysqldb \
> -e MYSQL_ROOT_PASSWORD=my-secret-pw \
> mysql:latest
dcfc16b7fba9075c59035e29a0efed91b7872e5f5cf72c8656afade824651041
vskumar@ubuntu:~$
==== Created mysql =====>

Please note this time, I have not copied the complete display contents.

=== listed ====>
vskumar@ubuntu:~$ sudo docker image ls mysql
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest 5d4d51c57ea8 5 weeks ago 374MB
vskumar@ubuntu:~$

vskumar@ubuntu:~$ sudo docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dcfc16b7fba9 mysql:latest “docker-entrypoint.s…” 3 minutes ago Up 3 minutes 3306/tcp mysqldb
a5f1ce30c02d swarm “/swarm manage” 11 days ago Restarting (1) 28 seconds ago gracious_bhabha
vskumar@ubuntu:~$
=================>

So we can have the mysql container also running in background currently.

Let us understand the commands/options used for dockerfile syntax:

Using ‘–detach’ command it runs the container in background.
I have given the container name ‘mysqldb’ with ‘–name’ option.
MySql DB needs the root password.
It has been executed with ‘-e’ option.
Since the mysql db image is not available in my current images list,
it pulls it from dockerhub.

You can try to use the same container for your db usage.

12. DevOps: How to build docker images using dockerfile ? -1

 

Docker-logo

In continuation of my  previous session on :”11. DevOps: How to Launch a container as a daemon ?”, in this session I would like to demonstrate the exercises on:

“How to build docker images using dockerfile ?:”

These images are basic operating environments, such as ubuntu.
We found these while doing the other lab exercises.
The docker images can craft advanced application stacks for the enterprise and cloud IT environments.
Currently let us craft an image manually by launching a container from a base image.
A best practices is, we can build an automated approach of crafting the images using Dockerfile.
The dockerfile is a a text-based build script which contains special instructions in a sequence for building the correct and the relevant images from the base images.

Please note; we will explore all these combinations in different sessions.

Now, let us understand this automated approach from the below steps:
1. The sequential instructions inside Dockerfile can include selecting the base image as 1st statement.
2. And in the later statements; installing the required application, adding the configuration and the data files, and automatically running the services as well as exposing those services to the external world.

This way the dockerfile based automated build approach has simplified the image building process.

It also offers a great deal of flexibility in organizing the build instructions and in visualizing the complete build process, while running the script instructions.

The Docker Engine tightly integrates this build process with the help of the docker ‘build’ subcommand.

This process involes the below steps:
1. Let us imagine; in the client server scenario of Docker, the Docker server (or daemon) is responsible towards complete build process.
2. And the Docker command-line interface is responsible for transferring the build context, including transferring Dockerfile to the daemon.
Now, let us list our existing images as below, in continuation of previous exercise:
=============>
vskumar@ubuntu:~$
vskumar@ubuntu:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker-exercise/ubuntu-wgetinstall latest e34304119838 7 days ago 169MB
<none> <none> fc7e4564eb92 7 days ago 169MB
hello-world latest f2a91732366c 12 days ago 1.85kB
ubuntu 16.04 20c44cd7596f 2 weeks ago 123MB
ubuntu latest 20c44cd7596f 2 weeks ago 123MB
busybox latest 6ad733544a63 4 weeks ago 1.13MB
busybox 1.24 47bcc53f74dc 20 months ago 1.11MB
vskumar@ubuntu:~$
====================>
Now,  let us create a simple container from the ubuntu base image.
To create it, we can create ‘dockerfile’ without extension using vi in the current pwd.

Please note we do not have vim utility in this Ubuntu base image.
=================>
vskumar@ubuntu:~$ pwd
/home/vskumar
vskumar@ubuntu:~$ vi dockerfile
============>
Now, let us cat the dockerfile as below:
=============>
vskumar@ubuntu:~$ ls -l
total 48
drwxr-xr-x 3 vskumar vskumar 4096 Nov 24 23:32 Desktop
-rw-rw-r– 1 vskumar vskumar 86 Dec 3 04:29 dockerfile
drwxr-xr-x 2 vskumar vskumar 4096 Nov 22 21:23 Documents
drwxr-xr-x 2 vskumar vskumar 4096 Nov 25 06:33 Downloads
-rw-r–r– 1 vskumar vskumar 8980 Nov 22 21:03 examples.desktop
drwxr-xr-x 2 vskumar vskumar 4096 Nov 22 21:23 Music
drwxr-xr-x 2 vskumar vskumar 4096 Nov 25 06:02 Pictures
drwxr-xr-x 2 vskumar vskumar 4096 Nov 22 21:23 Public
drwxr-xr-x 2 vskumar vskumar 4096 Nov 22 21:23 Templates
drwxr-xr-x 2 vskumar vskumar 4096 Nov 22 21:23 Videos
vskumar@ubuntu:~$
vskumar@ubuntu:~$ cat dockerfile
FROM ubuntu
CMD [“echo”, “This is done by vskumar for a lab practice of dockerfile”]
vskumar@ubuntu:~$
================>
From the above dockerfile contents:
1st line FROM ubuntu – denotes it is using the buntu as the base image to create the container.
2nd line: CMD [“echo”, “This is done by vskumar for a lab practice of dockerfile”]
denotes using CMD echo command is executed to print the message “This is done by vskumar for a lab practice of dockerfile”.
Now let us run this file through the below command:
$ sudo docker build .
We can see the output as below:
===============>
vskumar@ubuntu:~$ sudo docker build .
Sending build context to Docker daemon 112MB
Step 1/2 : FROM ubuntu
—> 20c44cd7596f
Step 2/2 : CMD [“echo”, “This is done by vskumar for a lab practice of dockerfile”]
—> Running in 1de59a4799fa
Removing intermediate container 1de59a4799fa
—> 8de083612fef
Successfully built 8de083612fef
vskumar@ubuntu:~$
===================>
Now, let us list the images:
==================>
vskumar@ubuntu:~$
vskumar@ubuntu:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 8de083612fef About a minute ago 123MB
docker-exercise/ubuntu-wgetinstall latest e34304119838 7 days ago 169MB
<none> <none> fc7e4564eb92 7 days ago 169MB
hello-world latest f2a91732366c 12 days ago 1.85kB
ubuntu 16.04 20c44cd7596f 2 weeks ago 123MB
ubuntu latest 20c44cd7596f 2 weeks ago 123MB
busybox latest 6ad733544a63 4 weeks ago 1.13MB
busybox 1.24 47bcc53f74dc 20 months ago 1.11MB
vskumar@ubuntu:~$
==========================>
We can see Imgae id: 8de083612fef is created just now.
Look into that line there is no tag given.
Now let us tag it as below:
$ sudo docker tag 8de083612fef ubuntu-testbox1
================>
vskumar@ubuntu:~$
vskumar@ubuntu:~$ sudo docker tag 8de083612fef ubuntu-testbox1
vskumar@ubuntu:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu-testbox1 latest 8de083612fef 4 minutes ago 123MB
docker-exercise/ubuntu-wgetinstall latest e34304119838 7 days ago 169MB
<none> <none> fc7e4564eb92 7 days ago 169MB
hello-world latest f2a91732366c 12 days ago 1.85kB
ubuntu 16.04 20c44cd7596f 2 weeks ago 123MB
ubuntu latest 20c44cd7596f 2 weeks ago 123MB
busybox latest 6ad733544a63 4 weeks ago 1.13MB
busybox 1.24 47bcc53f74dc 20 months ago 1.11MB
vskumar@ubuntu:~$
====================>
Now, let us do some housekeeping on these containers.
Let us list the containers using ps -a command
====================>
vskumar@ubuntu:~$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0fe495fc93ed ubuntu “/bin/bash -c ‘while…” 8 hours ago Exited (137) 4 hours ago hungry_engelbart
10ffea6140f9 ubuntu “bash” 7 days ago Exited (0) 7 days ago quizzical_lalande
b2a79f8d2fe6 ubuntu “/bin/bash -c ‘while…” 7 days ago Exited (255) 7 days ago goofy_borg
155f4b0764b1 ubuntu:16.04 “/bin/bash” 7 days ago Exited (0) 7 days ago zen_volhard
vskumar@ubuntu:~$
=====================>
I want to remove all of them. We can recreate with the dockerfile as an exercise.
$ Sudo docker containers prune
=======================================>
vskumar@ubuntu:~$ sudo docker ps -aq
0fe495fc93ed
10ffea6140f9
b2a79f8d2fe6
155f4b0764b1
vskumar@ubuntu:~$ sudo docker container prune
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Deleted Containers:
0fe495fc93edee3aaadc7fc0fbf21997f0ca3cde4d7e563aa8c61352a43957dd
10ffea6140f9c93b37bad2f9d159ad53aa121c0de69a9d145f07cc12f9591324
b2a79f8d2fe65453fce19f00d7adf03ed6dcced69ae68fba94ad0c416545263e
155f4b0764b16f1c8776a101cced6ea95c55eeabe69aeab8520cbe925bedc456

Total reclaimed space: 186B
vskumar@ubuntu:~$ sudo docker ps -aq
vskumar@ubuntu:~$
============== so now there are no containers =========>
Let us build the container.
Before building let us check the available images:
==================>
vskumar@ubuntu:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu-testbox1 latest 8de083612fef 24 minutes ago 123MB
docker-exercise/ubuntu-wgetinstall latest e34304119838 7 days ago 169MB
<none> <none> fc7e4564eb92 7 days ago 169MB
hello-world latest f2a91732366c 12 days ago 1.85kB
ubuntu 16.04 20c44cd7596f 2 weeks ago 123MB
ubuntu latest 20c44cd7596f 2 weeks ago 123MB
busybox latest 6ad733544a63 4 weeks ago 1.13MB
busybox 1.24 47bcc53f74dc 20 months ago 1.11MB
vskumar@ubuntu:~$
====================>
Let us remove some more images also.
We need to use the below commands:
=========== Let us try one image removal =========>
vskumar@ubuntu:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu-testbox1 latest 8de083612fef 33 minutes ago 123MB
docker-exercise/ubuntu-wgetinstall latest e34304119838 7 days ago 169MB
<none> <none> fc7e4564eb92 7 days ago 169MB
hello-world latest f2a91732366c 12 days ago 1.85kB
ubuntu 16.04 20c44cd7596f 2 weeks ago 123MB
ubuntu latest 20c44cd7596f 2 weeks ago 123MB
busybox latest 6ad733544a63 4 weeks ago 1.13MB
busybox 1.24 47bcc53f74dc 20 months ago 1.11MB
vskumar@ubuntu:~$ sudo docker rmi image 47bcc53f74dc
Untagged: busybox:1.24
Untagged: busybox@sha256:8ea3273d79b47a8b6d018be398c17590a4b5ec604515f416c5b797db9dde3ad8
Deleted: sha256:47bcc53f74dc94b1920f0b34f6036096526296767650f223433fe65c35f149eb
Deleted: sha256:f6075681a244e9df4ab126bce921292673c9f37f71b20f6be1dd3bb99b4fdd72
Deleted: sha256:1834950e52ce4d5a88a1bbd131c537f4d0e56d10ff0dd69e66be3b7dfa9df7e6
Error: No such image: image
vskumar@ubuntu:~$
=================================>
So, by using :
sudo docker rmi image [image id], we can remove the image.

Now, further continuation of our dockerfile exercise;
We can create a container from ubuntu base image and install vim package on it with the help of dockerfile.
To do this we need to have following dockerfile script.
——————>
FROM ubuntu
RUN apt-get update
RUN apt-get -y install vim
CMD [“echo”, “This is done by vskumar for a lab demo on dockerfile”]
—————–>
Before doing it, let me do some housekeeping.
I have removed the below image:
==================>
vskumar@ubuntu:~$
vskumar@ubuntu:~$ sudo docker rmi image 6ad733544a63
Untagged: busybox:latest
Untagged: busybox@sha256:bbc3a03235220b170ba48a157dd097dd1379299370e1ed99ce976df0355d24f0
Deleted: sha256:6ad733544a6317992a6fac4eb19fe1df577d4dec7529efec28a5bd0edad0fd30
Deleted: sha256:0271b8eebde3fa9a6126b1f2335e170f902731ab4942f9f1914e77016540c7bb
Error: No such image: image
=====================>
See the current status:
===================>
vskumar@ubuntu:~$ ls
Desktop dockerfile Documents Downloads examples.desktop Music Pictures Public Templates Videos
vskumar@ubuntu:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu-testbox1 latest 8de083612fef About an hour ago 123MB
docker-exercise/ubuntu-wgetinstall latest e34304119838 7 days ago 169MB
<none> <none> fc7e4564eb92 7 days ago 169MB
hello-world latest f2a91732366c 12 days ago 1.85kB
ubuntu 16.04 20c44cd7596f 2 weeks ago 123MB
vskumar@ubuntu:~$
======================>
Now let me update the dockerfile through vi and cat that file:
====================>
vskumar@ubuntu:~$
vskumar@ubuntu:~$ pwd
/home/vskumar
vskumar@ubuntu:~$ vi dockerfile
vskumar@ubuntu:~$ cat dockerfile
FROM ubuntu
RUN apt-get update
RUN apt-get -y install vim
CMD [“echo”, “This is done by vskumar for a lab practice of dockerfile”]
vskumar@ubuntu:~$
====================>
Now let me run the below command:
$ sudo docker build -t ubuntu-vmbox .
This time; I have added the tag name as ‘ ubuntu-vmbox’.
We need to understand; there are below tasks it involves:
1. Updating the ubuntu libraries – it takes some time by displaying lot of output.
2. Installing vim utility. — This also takes some time.
3. Displaying the message.
We can see this large size output:
=========== Update the packages and install the vim in a conatiner ==========>
vskumar@ubuntu:~$ pwd
/home/vskumar
vskumar@ubuntu:~$ sudo docker build -t ubuntu-vmbox .
Sending build context to Docker daemon 112MB
Step 1/4 : FROM ubuntu
latest: Pulling from library/ubuntu
Digest: sha256:7c67a2206d3c04703e5c23518707bdd4916c057562dd51c74b99b2ba26af0f79
Status: Downloaded newer image for ubuntu:latest
—> 20c44cd7596f
Step 2/4 : RUN apt-get update
—> Running in df81eaef9437
Get:1 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial/universe Sources [9802 kB]
Get:6 http://security.ubuntu.com/ubuntu xenial-security/universe Sources [53.1 kB]
Get:7 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages [1558 kB]
Get:8 http://archive.ubuntu.com/ubuntu xenial/restricted amd64 Packages [14.1 kB]
Get:9 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [9827 kB]
Get:10 http://archive.ubuntu.com/ubuntu xenial/multiverse amd64 Packages [176 kB]
Get:11 http://archive.ubuntu.com/ubuntu xenial-updates/universe Sources [231 kB]
Get:12 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [866 kB]
Get:13 http://archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [13.7 kB]
Get:14 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [719 kB]
Get:15 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [18.5 kB]
Get:16 http://archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [5174 B]
Get:17 http://archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [7150 B]
Get:18 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [505 kB]
Get:19 http://security.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [12.9 kB]
Get:20 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [229 kB]
Get:21 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [3479 B]
Fetched 24.6 MB in 2min 5s (196 kB/s)
Reading package lists…
Removing intermediate container df81eaef9437
—> 13cd766374bc
Step 3/4 : RUN apt-get -y install vim
—> Running in d37783a8cb7d
Reading package lists…
Building dependency tree…
Reading state information…
The following additional packages will be installed:
file libexpat1 libgpm2 libmagic1 libmpdec2 libpython3.5 libpython3.5-minimal
libpython3.5-stdlib libsqlite3-0 libssl1.0.0 mime-support vim-common
vim-runtime
Suggested packages:
gpm ctags vim-doc vim-scripts vim-gnome-py2 | vim-gtk-py2 | vim-gtk3-py2
| vim-athena-py2 | vim-nox-py2
The following NEW packages will be installed:
file libexpat1 libgpm2 libmagic1 libmpdec2 libpython3.5 libpython3.5-minimal
libpython3.5-stdlib libsqlite3-0 libssl1.0.0 mime-support vim vim-common
vim-runtime
0 upgraded, 14 newly installed, 0 to remove and 2 not upgraded.
Need to get 12.2 MB of archives.
After this operation, 58.3 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu xenial/main amd64 libgpm2 amd64 1.20.4-6.1 [16.5 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial/main amd64 libmagic1 amd64 1:5.25-2ubuntu1 [216 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial/main amd64 file amd64 1:5.25-2ubuntu1 [21.2 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libexpat1 amd64 2.1.0-7ubuntu0.16.04.3 [71.2 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial/main amd64 libmpdec2 amd64 2.4.2-1 [82.6 kB]
Get:6 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libssl1.0.0 amd64 1.0.2g-1ubuntu4.9 [1085 kB]
Get:7 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libpython3.5-minimal amd64 3.5.2-2ubuntu0~16.04.4 [523 kB]
Get:8 http://archive.ubuntu.com/ubuntu xenial/main amd64 mime-support all 3.59ubuntu1 [31.0 kB]
Get:9 http://archive.ubuntu.com/ubuntu xenial/main amd64 libsqlite3-0 amd64 3.11.0-1ubuntu1 [396 kB]
Get:10 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libpython3.5-stdlib amd64 3.5.2-2ubuntu0~16.04.4 [2132 kB]
Get:11 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 vim-common amd64 2:7.4.1689-3ubuntu1.2 [103 kB]
Get:12 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libpython3.5 amd64 3.5.2-2ubuntu0~16.04.4 [1360 kB]
Get:13 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 vim-runtime all 2:7.4.1689-3ubuntu1.2 [5164 kB]
Get:14 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 vim amd64 2:7.4.1689-3ubuntu1.2 [1036 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 12.2 MB in 12s (949 kB/s)
Selecting previously unselected package libgpm2:amd64.
(Reading database … 4768 files and directories currently installed.)
Preparing to unpack …/libgpm2_1.20.4-6.1_amd64.deb …
Unpacking libgpm2:amd64 (1.20.4-6.1) …
Selecting previously unselected package libmagic1:amd64.
Preparing to unpack …/libmagic1_1%3a5.25-2ubuntu1_amd64.deb …
Unpacking libmagic1:amd64 (1:5.25-2ubuntu1) …
Selecting previously unselected package file.
Preparing to unpack …/file_1%3a5.25-2ubuntu1_amd64.deb …
Unpacking file (1:5.25-2ubuntu1) …
Selecting previously unselected package libexpat1:amd64.
Preparing to unpack …/libexpat1_2.1.0-7ubuntu0.16.04.3_amd64.deb …
Unpacking libexpat1:amd64 (2.1.0-7ubuntu0.16.04.3) …
Selecting previously unselected package libmpdec2:amd64.
Preparing to unpack …/libmpdec2_2.4.2-1_amd64.deb …
Unpacking libmpdec2:amd64 (2.4.2-1) …
Selecting previously unselected package libssl1.0.0:amd64.
Preparing to unpack …/libssl1.0.0_1.0.2g-1ubuntu4.9_amd64.deb …
Unpacking libssl1.0.0:amd64 (1.0.2g-1ubuntu4.9) …
Selecting previously unselected package libpython3.5-minimal:amd64.
Preparing to unpack …/libpython3.5-minimal_3.5.2-2ubuntu0~16.04.4_amd64.deb …
Unpacking libpython3.5-minimal:amd64 (3.5.2-2ubuntu0~16.04.4) …
Selecting previously unselected package mime-support.
Preparing to unpack …/mime-support_3.59ubuntu1_all.deb …
Unpacking mime-support (3.59ubuntu1) …
Selecting previously unselected package libsqlite3-0:amd64.
Preparing to unpack …/libsqlite3-0_3.11.0-1ubuntu1_amd64.deb …
Unpacking libsqlite3-0:amd64 (3.11.0-1ubuntu1) …
Selecting previously unselected package libpython3.5-stdlib:amd64.
Preparing to unpack …/libpython3.5-stdlib_3.5.2-2ubuntu0~16.04.4_amd64.deb …
Unpacking libpython3.5-stdlib:amd64 (3.5.2-2ubuntu0~16.04.4) …
Selecting previously unselected package vim-common.
Preparing to unpack …/vim-common_2%3a7.4.1689-3ubuntu1.2_amd64.deb …
Unpacking vim-common (2:7.4.1689-3ubuntu1.2) …
Selecting previously unselected package libpython3.5:amd64.
Preparing to unpack …/libpython3.5_3.5.2-2ubuntu0~16.04.4_amd64.deb …
Unpacking libpython3.5:amd64 (3.5.2-2ubuntu0~16.04.4) …
Selecting previously unselected package vim-runtime.
Preparing to unpack …/vim-runtime_2%3a7.4.1689-3ubuntu1.2_all.deb …
Adding ‘diversion of /usr/share/vim/vim74/doc/help.txt to /usr/share/vim/vim74/doc/help.txt.vim-tiny by vim-runtime’
Adding ‘diversion of /usr/share/vim/vim74/doc/tags to /usr/share/vim/vim74/doc/tags.vim-tiny by vim-runtime’
Unpacking vim-runtime (2:7.4.1689-3ubuntu1.2) …
Selecting previously unselected package vim.
Preparing to unpack …/vim_2%3a7.4.1689-3ubuntu1.2_amd64.deb …
Unpacking vim (2:7.4.1689-3ubuntu1.2) …
Processing triggers for libc-bin (2.23-0ubuntu9) …
Setting up libgpm2:amd64 (1.20.4-6.1) …
Setting up libmagic1:amd64 (1:5.25-2ubuntu1) …
Setting up file (1:5.25-2ubuntu1) …
Setting up libexpat1:amd64 (2.1.0-7ubuntu0.16.04.3) …
Setting up libmpdec2:amd64 (2.4.2-1) …
Setting up libssl1.0.0:amd64 (1.0.2g-1ubuntu4.9) …
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can’t locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.22.1 /usr/local/share/perl/5.22.1 /usr/lib/x86_64-linux-gnu/perl5/5.22 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.22 /usr/share/perl/5.22 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base .) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
debconf: falling back to frontend: Teletype
Setting up libpython3.5-minimal:amd64 (3.5.2-2ubuntu0~16.04.4) …
Setting up mime-support (3.59ubuntu1) …
Setting up libsqlite3-0:amd64 (3.11.0-1ubuntu1) …
Setting up libpython3.5-stdlib:amd64 (3.5.2-2ubuntu0~16.04.4) …
Setting up vim-common (2:7.4.1689-3ubuntu1.2) …
Setting up libpython3.5:amd64 (3.5.2-2ubuntu0~16.04.4) …
Setting up vim-runtime (2:7.4.1689-3ubuntu1.2) …
Setting up vim (2:7.4.1689-3ubuntu1.2) …
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vim (vim) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vimdiff (vimdiff) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rvim (rvim) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rview (rview) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vi (vi) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/view (view) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/ex (ex) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/editor (editor) in auto mode
Processing triggers for libc-bin (2.23-0ubuntu9) …
Removing intermediate container d37783a8cb7d
—> c07c6f2d2c65
Step 4/4 : CMD [“echo”, “This is done by vskumar for a lab practice of dockerfile”]
—> Running in f7e85f87b578
Removing intermediate container f7e85f87b578
—> f6675f4738b7
Successfully built f6675f4738b7
Successfully tagged ubuntu-vmbox:latest
vskumar@ubuntu:~$
=== Finally you can see the ‘ubuntu-vmbox’ tagged conatiner ======>
We can see the latest image from the below images:
===== Current images list =====>
vskumar@ubuntu:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu-vmbox latest f6675f4738b7 3 minutes ago 220MB
ubuntu-testbox1 latest 8de083612fef About an hour ago 123MB
docker-exercise/ubuntu-wgetinstall latest e34304119838 7 days ago 169MB
<none> <none> fc7e4564eb92 7 days ago 169MB
hello-world latest f2a91732366c 12 days ago 1.85kB
ubuntu 16.04 20c44cd7596f 2 weeks ago 123MB
ubuntu latest 20c44cd7596f 2 weeks ago 123MB
vskumar@ubuntu:~$
=======================>
Now, I want to work with this newly created container. Please recollect my blog “https://vskumar.blog/2017/11/29/6-devops-how-to-work-with-interactive-docker-containers/”.
As we did practice in it; we can use the below command to work with this new container:

sudo docker run -i -t ubuntu-vmbox /bin/bash
I want to test the vim is working on it. See the below output:
==================>
vskumar@ubuntu:~$ sudo docker run -i -t ubuntu-vmbox /bin/bash

root@1169bb1285cf:/#
root@1169bb1285cf:/# pwd
/
root@1169bb1285cf:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@1169bb1285cf:/# vim test1
===== I have created the file with vim successfully ====>
Now let me use cat command and see its output:

================>
root@1169bb1285cf:/#
root@1169bb1285cf:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys test1 tmp usr var
root@1169bb1285cf:/# cat test1
testing this vim box……
root@1169bb1285cf:/#
=================>

So, in this exercise we have updated the ubuntu libraries and installed vim utility.
And tested the container for vim usage by using interactive mode.

=========== Now let me exit and check the list of images =====>
root@1169bb1285cf:/#
root@1169bb1285cf:/# exit
exit
vskumar@ubuntu:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu-vmbox latest f6675f4738b7 13 minutes ago 220MB
ubuntu-testbox1 latest 8de083612fef About an hour ago 123MB
docker-exercise/ubuntu-wgetinstall latest e34304119838 7 days ago 169MB
<none> <none> fc7e4564eb92 7 days ago 169MB
hello-world latest f2a91732366c 12 days ago 1.85kB
ubuntu 16.04 20c44cd7596f 2 weeks ago 123MB
ubuntu latest 20c44cd7596f 2 weeks ago 123MB
vskumar@ubuntu:~$
=============================>
So, the new container ‘ubuntu-vmbox’ is existing.

Now, I want to remove some images:
sudo docker rmi 20c44cd7596f
================>
vskumar@ubuntu:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu-vmbox latest f6675f4738b7 18 minutes ago 220MB
ubuntu-testbox1 latest 8de083612fef About an hour ago 123MB
docker-exercise/ubuntu-wgetinstall latest e34304119838 7 days ago 169MB
<none> <none> fc7e4564eb92 7 days ago 169MB
hello-world latest f2a91732366c 12 days ago 1.85kB
ubuntu 16.04 20c44cd7596f 2 weeks ago 123MB
ubuntu latest 20c44cd7596f 2 weeks ago 123MB
vskumar@ubuntu:~$ sudo docker rmi 20c44cd7596f
Error response from daemon: conflict: unable to delete 20c44cd7596f (cannot be forced) – image has dependent child images
vskumar@ubuntu:~$
== Please note the last image was the base to build the top tow containers ===>
Hence it has the child and parent relationship.
First we need to remove the child images and later the parent need to be removed.
=== You can see the removal of child one and one more image=====>
vskumar@ubuntu:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu-vmbox latest f6675f4738b7 20 minutes ago 220MB
ubuntu-testbox1 latest 8de083612fef 2 hours ago 123MB
docker-exercise/ubuntu-wgetinstall latest e34304119838 7 days ago 169MB
<none> <none> fc7e4564eb92 7 days ago 169MB
hello-world latest f2a91732366c 12 days ago 1.85kB
ubuntu 16.04 20c44cd7596f 2 weeks ago 123MB
ubuntu latest 20c44cd7596f 2 weeks ago 123MB
vskumar@ubuntu:~$ sudo docker rmi 8de083612fef
Untagged: ubuntu-testbox1:latest
Deleted: sha256:8de083612fefbf9723913748f7db4aba4154b17adc500d011f44df356736f06c
vskumar@ubuntu:~$ sudo docker rmi e34304119838
Untagged: docker-exercise/ubuntu-wgetinstall:latest
Deleted: sha256:e34304119838d79da60e12776529106c350b1972cd517648e8ab90311fad7b1a
vskumar@ubuntu:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu-vmbox latest f6675f4738b7 21 minutes ago 220MB
<none> <none> fc7e4564eb92 7 days ago 169MB
hello-world latest f2a91732366c 12 days ago 1.85kB
ubuntu 16.04 20c44cd7596f 2 weeks ago 123MB
ubuntu latest 20c44cd7596f 2 weeks ago 123MB
vskumar@ubuntu:~$
=================>
Let me do some more exercises on housekeeping.
I would like to present some more dependency issues for the above images. You can clearly see the output:
========= Dependencies =======>
vskumar@ubuntu:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu-vmbox latest f6675f4738b7 22 minutes ago 220MB
<none> <none> fc7e4564eb92 7 days ago 169MB
hello-world latest f2a91732366c 12 days ago 1.85kB
ubuntu 16.04 20c44cd7596f 2 weeks ago 123MB
ubuntu latest 20c44cd7596f 2 weeks ago 123MB
vskumar@ubuntu:~$ sudo docker rmi fc7e4564eb92
Deleted: sha256:fc7e4564eb928ccfe068c789f0d650967e8d5dc42d4e8d92409aab6614364075
Deleted: sha256:b16d78406b12e6dbc174f4e71bedb7b9edc0593cad10458ddf042738694c06db
vskumar@ubuntu:~$ sudo docker rmi 20c44cd7596f
Error response from daemon: conflict: unable to delete 20c44cd7596f (cannot be forced) – image has dependent child images
vskumar@ubuntu:~$ sudo docker rmi f6675f4738b7
Error response from daemon: conflict: unable to delete f6675f4738b7 (must be forced) – image is being used by stopped container 1169bb1285cf
vskumar@ubuntu:~$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1169bb1285cf ubuntu-vmbox “/bin/bash” 15 minutes ago Exited (0) 11 minutes ago heuristic_mayer
vskumar@ubuntu:~$
====================>
It means the container “1169bb1285cf ubuntu-vmbox” is the child to image id:f6675f4738b7.
===========>
vskumar@ubuntu:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu-vmbox latest f6675f4738b7 27 minutes ago 220MB
hello-world latest f2a91732366c 12 days ago 1.85kB
ubuntu 16.04 20c44cd7596f 2 weeks ago 123MB
ubuntu latest 20c44cd7596f 2 weeks ago 123MB
vskumar@ubuntu:~$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1169bb1285cf ubuntu-vmbox “/bin/bash” 19 minutes ago Exited (0) 14 minutes ago heuristic_mayer
vskumar@ubuntu:~$
==============>
So if I want to remove Image id: f6675f4738b7, I need to remove the container id:1169bb1285cf , and later I need to remove this image.
$ sudo docker rm container 1169bb1285cf
And later image removal command need to be used as below.
======================>
vskumar@ubuntu:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu-vmbox latest f6675f4738b7 31 minutes ago 220MB
hello-world latest f2a91732366c 12 days ago 1.85kB
ubuntu 16.04 20c44cd7596f 2 weeks ago 123MB
ubuntu latest 20c44cd7596f 2 weeks ago 123MB
vskumar@ubuntu:~$ sudo docker rmi f6675f4738b7
Untagged: ubuntu-vmbox:latest
Deleted: sha256:f6675f4738b721780721f345906a0c78c13a67ee8239a16f071504b217f41658
Deleted: sha256:c07c6f2d2c651dd406977d42d5504c941d7f975a84c8547abaf3869b50942820
Deleted: sha256:4855cfb7ae6f84279bbbfe87e7691377531a541785c613014f64909e6e0f4528
Deleted: sha256:13cd766374bcb31cc0e8cac971e82754bb8e1bc66780abaff264f847e00a94b2
Deleted: sha256:dc6fab8a33a18a8c840e19612253657c4610ab865a26de5a31260f71bcef5f76
vskumar@ubuntu:~$
========================>
So we have the below images only now:
==== Current images ======>
vskumar@ubuntu:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest f2a91732366c 12 days ago 1.85kB
ubuntu 16.04 20c44cd7596f 2 weeks ago 123MB
ubuntu latest 20c44cd7596f 2 weeks ago 123MB
vskumar@ubuntu:~$
==========================>
We can try to remove the above images:
========= See it is declined due to it is base image ===========>
vskumar@ubuntu:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest f2a91732366c 12 days ago 1.85kB
ubuntu 16.04 20c44cd7596f 2 weeks ago 123MB
ubuntu latest 20c44cd7596f 2 weeks ago 123MB
vskumar@ubuntu:~$ sudo docker rmi 20c44cd7596f
Error response from daemon: conflict: unable to delete 20c44cd7596f (must be forced) – image is referenced in multiple repositories
vskumar@ubuntu:~$
=========================>
Both ubuntu images are interlinked and they can not be removed as the base docker engine is working on top of their OS.

We will stop this session at this time.

We will continue some more sessions on “dockerfile”.

 

Vcard-Shanthi Kumar V-v3

11. DevOps: How to Launch a container as a daemon ?

Docker-logo

In continuation of my previous blog on “10. DevOps: How to Build images from Docker containers?”, I am continuing my lab exercises. In this session we can see ”

How to Launch a container as a daemon ?:

Note: If you want to recollect the docker commands to be used during your current lab practice, visit my blog link:

https://vskumarblogs.wordpress.com/2017/12/13/some-useful-docker-commands-for-handling-images-and-containers/

 

Let us recap the past exercises; So far we have experimented with an interactive container, tracked the changes that were made to the containers., created images from the containers, and then gained insights in the containerization scenarios.

Now, let us see the container usage in a detached mode.

When we run the container in a detached mode it runs under a daemon process.

I want to use the “ubuntu” image and run detached mode command.

First, let me check my current docker images:

==================>

vskumar@ubuntu:~$

vskumar@ubuntu:~$ sudo docker images

[sudo] password for vskumar:

REPOSITORY TAG IMAGE ID CREATED SIZE

docker-exercise/ubuntu-wgetinstall latest e34304119838 7 days ago 169MB

<none> <none> fc7e4564eb92 7 days ago 169MB

hello-world latest f2a91732366c 12 days ago 1.85kB

ubuntu 16.04 20c44cd7596f 2 weeks ago 123MB

ubuntu latest 20c44cd7596f 2 weeks ago 123MB

busybox latest 6ad733544a63 4 weeks ago 1.13MB

busybox 1.24 47bcc53f74dc 20 months ago 1.11MB

vskumar@ubuntu:~$

===================>

You can see my previous image with ‘docker-exercise/ubuntu-wgetinstall ‘. This was created in the previous exercise.

As per our plan in this session I am using the below commands to run the ubuntu image as below:

sudo docker run -d ubuntu \

    /bin/bash -c "while true; do date; sleep 5; done";

========== Output ======>
vskumar@ubuntu:~$  sudo docker run -d ubuntu \
>     /bin/bash -c "while true; do date; sleep 5; done";
0fe495fc93edee3aaadc7fc0fbf21997f0ca3cde4d7e563aa8c61352a43957dd
vskumar@ubuntu:~$ $ 
=======================>

Now, to view the docker logs I want to run the docker logs subcommand on image id: ‘ 0fe495fc93edee3aaadc7fc0fbf21997f0ca3cde4d7e563aa8c61352a43957dd’

$ sudo docker logs 0fe495fc93edee3aaadc7fc0fbf21997f0ca3cde4d7e563aa8c61352a43957dd;

=====See the output of the Daemon process running with the ubuntu image ===============>

vskumar@ubuntu:~$ sudo docker logs 0fe495fc93edee3aaadc7fc0fbf21997f0ca3cde4d7e563aa8c61352a43957dd;

Sun Dec 3 05:11:57 UTC 2017

Sun Dec 3 05:12:02 UTC 2017

Sun Dec 3 05:12:07 UTC 2017

Sun Dec 3 05:12:12 UTC 2017

Sun Dec 3 05:12:17 UTC 2017

Sun Dec 3 05:12:22 UTC 2017

Sun Dec 3 05:12:27 UTC 2017

Sun Dec 3 05:12:32 UTC 2017

Sun Dec 3 05:12:37 UTC 2017

Sun Dec 3 05:12:42 UTC 2017

Sun Dec 3 05:12:48 UTC 2017

Sun Dec 3 05:12:53 UTC 2017

Sun Dec 3 05:12:58 UTC 2017

Sun Dec 3 05:13:03 UTC 2017

Sun Dec 3 05:13:08 UTC 2017

Sun Dec 3 05:13:13 UTC 2017

Sun Dec 3 05:13:18 UTC 2017

Sun Dec 3 05:13:23 UTC 2017

Sun Dec 3 05:13:28 UTC 2017

Sun Dec 3 05:13:33 UTC 2017

Sun Dec 3 05:13:38 UTC 2017

Sun Dec 3 05:13:43 UTC 2017

Sun Dec 3 05:13:48 UTC 2017

Sun Dec 3 05:13:53 UTC 2017

Sun Dec 3 05:13:58 UTC 2017

Sun Dec 3 05:14:03 UTC 2017

Sun Dec 3 05:14:08 UTC 2017

Sun Dec 3 05:14:13 UTC 2017

Sun Dec 3 05:14:18 UTC 2017

Sun Dec 3 05:14:23 UTC 2017

Sun Dec 3 05:14:28 UTC 2017

Sun Dec 3 05:14:33 UTC 2017

Sun Dec 3 05:14:38 UTC 2017

Sun Dec 3 05:14:43 UTC 2017

Sun Dec 3 05:14:48 UTC 2017

Sun Dec 3 05:14:53 UTC 2017

Sun Dec 3 05:14:58 UTC 2017

Sun Dec 3 05:15:03 UTC 2017

Sun Dec 3 05:15:08 UTC 2017

Sun Dec 3 05:15:13 UTC 2017

Sun Dec 3 05:15:18 UTC 2017

Sun Dec 3 05:15:23 UTC 2017

vskumar@ubuntu:~$

=================You can see the output for every few seconds listed =======>

It means the container is running as a daemon.

Now, let us use ps -eaf command to check the processed running in linux by using :

$ ps -eaf | grep ‘daemon’

========= See the output of daemon processes ==========>

vskumar@ubuntu:~$

vskumar@ubuntu:~$ ps -eaf | grep ‘daemon’

message+ 837 1 0 20:26 ? 00:00:05 /usr/bin/dbus-daemon –system –address=systemd: –nofork –nopidfile –systemd-activation

root 871 1 0 20:26 ? 00:00:03 /usr/sbin/NetworkManager –no-daemon

avahi 873 1 0 20:26 ? 00:00:00 avahi-daemon: running [ubuntu.local]

root 876 1 0 20:26 ? 00:00:01 /usr/lib/accountsservice/accounts-daemon

avahi 893 873 0 20:26 ? 00:00:00 avahi-daemon: chroot helper

rtkit 1370 1 0 20:28 ? 00:00:00 /usr/lib/rtkit/rtkit-daemon

vskumar 2426 1 0 20:55 ? 00:00:00 /usr/bin/gnome-keyring-daemon –daemonize –login

vskumar 2508 2428 0 20:55 ? 00:00:00 upstart-udev-bridge –daemon –user

vskumar 2515 2428 0 20:55 ? 00:00:04 dbus-daemon –fork –session –address=unix:abstract=/tmp/dbus-nPaV5rWlQc

vskumar 2570 2428 0 20:55 ? 00:00:03 /usr/lib/x86_64-linux-gnu/bamf/bamfdaemon

vskumar 2572 2428 0 20:55 ? 00:00:04 /usr/bin/ibus-daemon –daemonize –xim –address unix:tmpdir=/tmp/ibus

vskumar 2575 2428 0 20:55 ? 00:00:00 upstart-file-bridge –daemon –user

vskumar 2579 2428 0 20:55 ? 00:00:00 upstart-dbus-bridge –daemon –system –user –bus-name system

vskumar 2582 2428 0 20:55 ? 00:00:00 upstart-dbus-bridge –daemon –session –user –bus-name session

vskumar 2605 2428 0 20:55 ? 00:00:00 /usr/lib/ibus/ibus-x11 –kill-daemon

vskumar 2630 2428 0 20:56 ? 00:00:00 gpg-agent –homedir /home/vskumar/.gnupg –use-standard-socket –daemon

vskumar 2645 2428 0 20:56 ? 00:00:02 /usr/lib/unity-settings-daemon/unity-settings-daemon

vskumar 2664 2653 0 20:56 ? 00:00:00 /usr/bin/dbus-daemon –config-file=/etc/at-spi2/accessibility.conf –nofork –print-address 3

vskumar 2851 2654 0 20:56 ? 00:00:01 /usr/lib/unity-settings-daemon/unity-fallback-mount-helper

vskumar 2914 2428 0 20:57 ? 00:00:00 /bin/sh -c /usr/lib/x86_64-linux-gnu/zeitgeist/zeitgeist-maybe-vacuum; /usr/bin/zeitgeist-daemon

vskumar 2920 2914 0 20:57 ? 00:00:00 /usr/bin/zeitgeist-daemon

vskumar 3094 2428 0 21:00 ? 00:00:01 /usr/lib/x86_64-linux-gnu/unity-lens-files/unity-files-daemon

root 4148 1253 0 21:11 ? 00:00:00 docker-containerd-shim –namespace moby –workdir /var/lib/docker/containerd/daemon/io.containerd.runtime.v1.linux/moby/0fe495fc93edee3aaadc7fc0fbf21997f0ca3cde4d7e563aa8c61352a43957dd –address /var/run/docker/containerd/docker-containerd.sock –runtime-root /var/run/docker/runtime-runc

vskumar 4480 3206 0 21:19 pts/19 00:00:00 grep –color=auto daemon

vskumar@ubuntu:~$

======== You can see the list of processes running currently ========>

So we are successful! to run a container in a detached mode [not in an interactive mode!] using the command: ‘ sudo docker run -d ubuntu’

You can think in an application architecture having multiple servers or SOA running with different services.

You can simulate the same services using the docker containers, by setting up as images by configuring the required services and connect them to the architecture.

This way the advantages of containers can be utilized well. Where different companies are using and implementing their applications into containers architecture by saving lot of infrastructure cost. No hardware or physical servers are required. Lot of space also can be saved. The microservices architecture leads to the same way.

At this point, I would like to stop this session and in the next blog we will see other exercises.

Vcard-Shanthi Kumar V-v3

 

 

10. DevOps: How to Build images from Docker containers?

Docker-logo

This is in continuation of my last blog “9. DevOps: How to do Containers housekeeping ?”. In this blog I would like to demonstrate on:

How to Build images from docker containers?:

Note: If you want to recollect the docker commands to be used during your current lab practice, visit my blog link:

https://vskumarblogs.wordpress.com/2017/12/13/some-useful-docker-commands-for-handling-images-and-containers/

So far we have built the containers and operated them through the previous exercises. Now, let us see how  can we add  software to our base image on a running container and then convert that container into an image for future usage.

Let’s take ubuntu:16.04 as our base image, install the wget application, and then convert the running container to an image with the below steps:

To make ubuntu:16.04 container is our base image, we need to install the wget application, and then convert it as the running container to a docker image by using the below steps:

  1. Launch an ubuntu:16.04 container using the docker run subcommand, as shown below:
      $ sudo docker run -i -t ubuntu:16.04 /bin/bash
========================>
vskumar@ubuntu:~$ sudo docker ps -aq
155f4b0764b1
vskumar@ubuntu:~$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
155f4b0764b1        ubuntu:16.04        "/bin/bash"         2 hours ago         Up 11 minutes                           zen_volhard
vskumar@ubuntu:~$ sudo docker run -i -t ubuntu:16.04 /bin/bash
root@3484664d454a:/# 
=========================>
2. Now, let's  verify is wget  available for this image or not.
============== the display shows there is no wget in this image =========>

root@3484664d454a:/# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@3484664d454a:/# which wget
root@3484664d454a:/# 

      root@472c96295678:/# apt-get update
==================>
As we know that it is a brand new ubuntu container we built it, before installing wget we must synchronize it with the Ubuntu package repository, as shown below:
====================>
root@3484664d454a:/# apt-get update
Get:1 http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]         
Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]                                                                      
Get:4 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]                                                                    
Get:5 http://archive.ubuntu.com/ubuntu xenial/universe Sources [9802 kB]                                                                      
Get:6 http://security.ubuntu.com/ubuntu xenial-security/universe Sources [53.1 kB]                                                            
Get:7 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [504 kB]                                                          
Get:8 http://security.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [12.9 kB]                                                   
Get:9 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [229 kB]                                                      
Get:10 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [3479 B]                                                   
Get:11 http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages [1558 kB]                                                                  
Get:12 http://archive.ubuntu.com/ubuntu xenial/restricted amd64 Packages [14.1 kB]                                                            
Get:13 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [9827 kB]                                                              
Get:14 http://archive.ubuntu.com/ubuntu xenial/multiverse amd64 Packages [176 kB]                                                             
Get:15 http://archive.ubuntu.com/ubuntu xenial-updates/universe Sources [228 kB]                                                              
Get:16 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [864 kB]                                                           
Get:17 http://archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [13.7 kB]                                                    
Get:18 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [711 kB]                                                       
Get:19 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [18.5 kB]                                                    
Get:20 http://archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [5174 B]                                                         
Get:21 http://archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [7135 B]                                                     
Fetched 24.6 MB in 59s (412 kB/s)                                                                                                             
Reading package lists... Done
root@3484664d454a:/# 
================================>
Now, we can install wget as below:
=========== Output of wget installation on container ===========>

root@3484664d454a:/# 
root@3484664d454a:/# apt-get install -y wget
Reading package lists... Done
Building dependency tree        
Reading state information... Done
The following additional packages will be installed:
  ca-certificates libidn11 libssl1.0.0 openssl
The following NEW packages will be installed:
  ca-certificates libidn11 libssl1.0.0 openssl wget
0 upgraded, 5 newly installed, 0 to remove and 1 not upgraded.
Need to get 2089 kB of archives.
After this operation, 6027 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libidn11 amd64 1.32-3ubuntu1.2 [46.5 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libssl1.0.0 amd64 1.0.2g-1ubuntu4.9 [1085 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 openssl amd64 1.0.2g-1ubuntu4.9 [492 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 ca-certificates all 20170717~16.04.1 [168 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 wget amd64 1.17.1-1ubuntu1.3 [299 kB]
Fetched 2089 kB in 4s (421 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libidn11:amd64.
(Reading database ... 4768 files and directories currently installed.)
Preparing to unpack .../libidn11_1.32-3ubuntu1.2_amd64.deb ...
Unpacking libidn11:amd64 (1.32-3ubuntu1.2) ...
Selecting previously unselected package libssl1.0.0:amd64.
Preparing to unpack .../libssl1.0.0_1.0.2g-1ubuntu4.9_amd64.deb ...
Unpacking libssl1.0.0:amd64 (1.0.2g-1ubuntu4.9) ...
Selecting previously unselected package openssl.
Preparing to unpack .../openssl_1.0.2g-1ubuntu4.9_amd64.deb ...
Unpacking openssl (1.0.2g-1ubuntu4.9) ...
Selecting previously unselected package ca-certificates.
Preparing to unpack .../ca-certificates_20170717~16.04.1_all.deb ...
Unpacking ca-certificates (20170717~16.04.1) ...
Selecting previously unselected package wget.
Preparing to unpack .../wget_1.17.1-1ubuntu1.3_amd64.deb ...
Unpacking wget (1.17.1-1ubuntu1.3) ...
Processing triggers for libc-bin (2.23-0ubuntu9) ...
Setting up libidn11:amd64 (1.32-3ubuntu1.2) ...
Setting up libssl1.0.0:amd64 (1.0.2g-1ubuntu4.9) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.22.1 /usr/local/share/perl/5.22.1 /usr/lib/x86_64-linux-gnu/perl5/5.22 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.22 /usr/share/perl/5.22 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base .) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
debconf: falling back to frontend: Teletype
Setting up openssl (1.0.2g-1ubuntu4.9) ...
Setting up ca-certificates (20170717~16.04.1) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.22.1 /usr/local/share/perl/5.22.1 /usr/lib/x86_64-linux-gnu/perl5/5.22 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.22 /usr/share/perl/5.22 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base .) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
debconf: falling back to frontend: Teletype
Setting up wget (1.17.1-1ubuntu1.3) ...
Processing triggers for libc-bin (2.23-0ubuntu9) ...
Processing triggers for ca-certificates (20170717~16.04.1) ...
Updating certificates in /etc/ssl/certs...
148 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
root@3484664d454a:/# 
=========================== End of installation ===========>
Now, we can verify with  'which wget ' command
============>
root@3484664d454a:/# which wget
/usr/bin/wget
root@3484664d454a:/# 
============>
Please let us recollect; installation of any software would alter the Dockwer base image composition. In which, we can also trace using the docker diff subcommand as we did in the previous exercises. 
I will open a second Terminal/screen, the docker diff subcommand can be issued from it, as below:
      $ sudo docker diff 472c96295678
===============>
vskumar@ubuntu:~$  
vskumar@ubuntu:~$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
3484664d454a        ubuntu:16.04        "/bin/bash"         15 minutes ago      Up 15 minutes                           jolly_cray
155f4b0764b1        ubuntu:16.04        "/bin/bash"         2 hours ago         Up 40 minutes                           zen_volhard
vskumar@ubuntu:~$ sudo docker diff 155f4b0764b1
C /root
A /root/.bash_history
vskumar@ubuntu:~$ 
============>

How to save this container ?:
The docker commit subcommand can be performed on a running or a stopped container. When a commit is performed on a running container, the Docker Engine pauses the container during the commit operation in order to avoid any data inconsistency. 
Now we can stop our running container.
We can commit a container to an image with the docker commit subcommand, as shown here:
      $ sudo docker commit 

================== Using commit for container ============>

root@3484664d454a:/# 
root@3484664d454a:/# exit
exit
vskumar@ubuntu:~$ sudo docker commit 3484664d454a
[sudo] password for vskumar: 
Sorry, try again.
[sudo] password for vskumar: 
sha256:fc7e4564eb928ccfe068c789f0d650967e8d5dc42d4e8d92409aab6614364075
vskumar@ubuntu:~$ 
=======================>
You can see the container id from the above output.

=========== We can also give a message to the commit command as below ===>
vskumar@ubuntu:~$ sudo docker commit 3484664d454a  Docker-exercise/ubuntu-wgetinstall
invalid reference format: repository name must be lowercase
vskumar@ubuntu:~$ sudo docker commit 3484664d454a  docker-exercise/ubuntu-wgetinstall
sha256:e34304119838d79da60e12776529106c350b1972cd517648e8ab90311fad7b1a
vskumar@ubuntu:~$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                       PORTS               NAMES
3484664d454a        ubuntu:16.04        "/bin/bash"         24 minutes ago      Exited (130) 6 minutes ago                       jolly_cray
155f4b0764b1        ubuntu:16.04        "/bin/bash"         2 hours ago         Up About an hour                                 zen_volhard
vskumar@ubuntu:~$ 
===================== Note there are two containers created  ====>
Now, I want to remove one container :
==========>

vskumar@ubuntu:~$ sudo docker rm 3484664d454a
3484664d454a
vskumar@ubuntu:~$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
155f4b0764b1        ubuntu:16.04        "/bin/bash"         3 hours ago         Up About an hour                        zen_volhard
vskumar@ubuntu:~$ 
========================>

Now let us check the docker images how many we have in our store :
=========== List of images ==========>
vskumar@ubuntu:~$ 
vskumar@ubuntu:~$ sudo docker images
REPOSITORY                           TAG                 IMAGE ID            CREATED             SIZE
docker-exercise/ubuntu-wgetinstall   latest              e34304119838        5 minutes ago       169MB
<none>                               <none>              fc7e4564eb92        7 minutes ago       169MB
hello-world                          latest              f2a91732366c        5 days ago          1.85kB
ubuntu                               16.04               20c44cd7596f        8 days ago          123MB
ubuntu                               latest              20c44cd7596f        8 days ago          123MB
busybox                              latest              6ad733544a63        3 weeks ago         1.13MB
busybox                              1.24                47bcc53f74dc        20 months ago       1.11MB
vskumar@ubuntu:~$ 

==============================>
How to remove images:

by using :

sudo docker rmi image [image id], we can remove the image. For example; if you want to remove the image id:
47bcc53f74dc
you can use: $ sudo docker rmi image 47bcc53f74dc
=================>
vskumar@ubuntu:~$ sudo docker rmi image 47bcc53f74dc
Untagged: busybox:1.24
Untagged: busybox@sha256:8ea3273d79b47a8b6d018be398c17590a4b5ec604515f416c5b797db9dde3ad8
Deleted: sha256:47bcc53f74dc94b1920f0b34f6036096526296767650f223433fe65c35f149eb
Deleted: sha256:f6075681a244e9df4ab126bce921292673c9f37f71b20f6be1dd3bb99b4fdd72
Deleted: sha256:1834950e52ce4d5a88a1bbd131c537f4d0e56d10ff0dd69e66be3b7dfa9df7e6
Error: No such image: image
vskumar@ubuntu:~$ 
=================>
 

So by using :

sudo docker rmi image [image id], we can remove the image.  Just recollect the difference between the image removal and container removal. For containers removal refer to my blog on "Housekeeping containers". Now we have learned how to create an image from containers using a few easy steps by installing the wget application. You can also add some other software applications to the same or different container(s) in the similar way.

You can use this method for testing also.  Let us say, you want to test a set of java programs. Then you need to install jdk and copy your programs. Write a shell script to compile and execute the programs by piping their output into a text file in a Linux background. So this way, you will be using the container as a test environment also.

The most easy and recommended way of creating an image is to use the Dockerfile method.

Within dockerfile we can mention the setup required to build a container through different steps. Then dockerfile creates the required setup for a container, under docker’s building activity.

We will see it in future exercises.

Please leave your feedback!

Vcard-Shanthi Kumar V-v39. DevOps: How to do Containers housekeeping ?

9. DevOps: How to do Containers housekeeping ?

Docker-logo

In  continuation of my previous blog on “8. DevOps:How to control and operate docker containers”, in this blog I would like to show some lab practice on “docker Containers housekeeping”.

From the previous lab sessions, we have seen many containers when we used ps -a option.

We have used two containers most of the times.

Others are not required. This time we will see how to remove a container physically.

Let us consider the below containers to remove using rm command:

32bc16b508d4        ubuntu 
a744246ffb8e        hello-world
1dd55efde43f        hello-world

$sudo docker rm 1dd55efde43f 
$sudo docker rm a744246ffb8e 
$sudo docker rm 32bc16b508d4 
================ You can see the above three containers are removed =========>
vskumar@ubuntu:~$ sudo docker rm 1dd55efde43f 
1dd55efde43f
vskumar@ubuntu:~$ sudo docker rm a744246ffb8e 
a744246ffb8e
vskumar@ubuntu:~$ sudo docker rm 32bc16b508d4 
32bc16b508d4
vskumar@ubuntu:~$ sudo docker ps -a |more
CONTAINER ID        IMAGE               COMMAND                 CREATED         
    STATUS                         PORTS               NAMES
f123dbd09116        ubuntu:16.04        "/bin/bash"             18 minutes ago  
    Exited (0) 18 minutes ago                          elastic_nightingale
3cfdea29ce6e        ubuntu              "bash"                  27 minutes ago  
    Exited (0) 26 minutes ago                          gallant_nobel
155f4b0764b1        ubuntu:16.04        "/bin/bash"             About an hour ag
o   Exited (0) 12 minutes ago                          zen_volhard
11e293722c64        ubuntu:16.04        "/bin/bash"             About an hour ag
o   Exited (0) About an hour ago                       dreamy_bassi
d10ad2bd62f7        ubuntu:16.04        "/bin/bash"             About an hour ag
o   Exited (0) About an hour ago                       cranky_dijkstra
cb1ff260d48e        ubuntu              "ls /usr/src"           11 hours ago    
    Exited (0) 11 hours ago                            wonderful_hawking
b20691fd8fb5        ubuntu              "ls /usr"               11 hours ago    
    Exited (0) 11 hours ago                            friendly_mirzakhani
431ba4c53028        ubuntu              "ls"                    11 hours ago    
    Exited (0) 28 minutes ago                          affectionate_nobel
2c31684bb1f4        ubuntu              "ls -la"                11 hours ago    
    Exited (0) 11 hours ago                            zealous_meitner
fe2e3b449daf        ubuntu              "ls -la /home/."        11 hours ago    
    Exited (0) 11 hours ago                            dreamy_shirley
c44bdd05b94d        ubuntu              "ls -la home."          11 hours ago    
    Exited (2) 11 hours ago                            elastic_pasteur
8b8afa82859a        ubuntu              "ls -la"                11 hours ago    
    Exited (0) 11 hours ago                            festive_panini
2811eb37af61        ubuntu              "ls -la 604831dbce2a"   11 hours ago    
    Exited (2) 11 hours ago                            jolly_swartz
604831dbce2a        ubuntu:16.04        "/bin/bash"             11 hours ago    
    Exited (0) 11 hours ago                            vibrant_ride
718636415a7f        ubuntu:16.04        "/bin/bash"             12 hours ago    
    Exited (0) 12 hours ago                            reverent_noyce
53a7751d4673        ubuntu:16.04        "/bin/bash"             13 hours ago    
    Exited (0) 13 hours ago                            musing_chandrasekhar
1ba71598b7b8        hello-world         "/hello"                16 hours ago    
    Exited (0) 16 hours ago                            musing_kare
vskumar@ubuntu:~$  
==============>
Now let us consider some more examples  as below:
3cfdea29ce6e        ubuntu 
cb1ff260d48e        ubuntu 
b20691fd8fb5        ubuntu 
431ba4c53028        ubuntu 
c31684bb1f4        ubuntu 
2c31684bb1f4        ubuntu 
fe2e3b449daf        ubuntu
c44bdd05b94d        ubuntu 
2811eb37af61        ubuntu
Now, let us use the below rm commands:
$sudo docker rm 3cfdea29ce6e
$sudo docker rm cb1ff260d48e
$sudo docker rm b20691fd8fb5 
$sudo docker rm 431ba4c53028 
$sudo docker rm 2c31684bb1f4
$sudo docker rm fe2e3b449daf 
$sudo docker rm c44bdd05b94d
$sudo docker rm 2811eb37af61
=================>
See the below output also:
 ================== Container removal ==========>
vskumar@ubuntu:~$ clear

vskumar@ubuntu:~$ sudo docker rm 3cfdea29ce6e
3cfdea29ce6e
vskumar@ubuntu:~$ sudo docker rm cb1ff260d48e
cb1ff260d48e
vskumar@ubuntu:~$ sudo docker rm b20691fd8fb5
b20691fd8fb5
vskumar@ubuntu:~$ sudo docker rm 431ba4c53028
431ba4c53028
vskumar@ubuntu:~$ sudo docker rm 2c31684bb1f4
2c31684bb1f4
vskumar@ubuntu:~$ sudo docker rm fe2e3b449daf
fe2e3b449daf
vskumar@ubuntu:~$ sudo docker rm fc44bdd05b94d
Error: No such container: fc44bdd05b94d
vskumar@ubuntu:~$ sudo docker rm c44bdd05b94d
c44bdd05b94d
vskumar@ubuntu:~$ sudo docker rm 2811eb37af61
2811eb37af61
vskumar@ubuntu:~$ 
==========================>
Now we can see the list of available containers:
============= List of latest containers ==============>
vskumar@ubuntu:~$ sudo docker ps -a |more
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                         PORTS               NAMES
f123dbd09116        ubuntu:16.04        "/bin/bash"         28 minutes ago      Exited (0) 28 minutes ago                          elastic_nigh
tingale
155f4b0764b1        ubuntu:16.04        "/bin/bash"         About an hour ago   Exited (0) 22 minutes ago                          zen_volhard
11e293722c64        ubuntu:16.04        "/bin/bash"         About an hour ago   Exited (0) About an hour ago                       dreamy_bassi
d10ad2bd62f7        ubuntu:16.04        "/bin/bash"         2 hours ago         Exited (0) About an hour ago                       cranky_dijks
tra
8b8afa82859a        ubuntu              "ls -la"            11 hours ago        Exited (0) 11 hours ago                            festive_pani
ni
604831dbce2a        ubuntu:16.04        "/bin/bash"         12 hours ago        Exited (0) 11 hours ago                            vibrant_ride
718636415a7f        ubuntu:16.04        "/bin/bash"         12 hours ago        Exited (0) 12 hours ago                            reverent_noy
ce
53a7751d4673        ubuntu:16.04        "/bin/bash"         13 hours ago        Exited (0) 13 hours ago                            musing_chand
rasekhar
1ba71598b7b8        hello-world         "/hello"            16 hours ago        Exited (0) 16 hours ago                            musing_kare
vskumar@ubuntu:~$ 
===========================>
Now, I wan to keep very few containers only and remove the below containers:

604831dbce2a        ubuntu:16.04
718636415a7f        ubuntu:16.04 
53a7751d4673        ubuntu:16.04
8b8afa82859a        ubuntu 
I want to use the below  commands to remove  the above containers:
$sudo docker rm 604831dbce2a
$sudo docker rm 718636415a7f
$sudo docker rm 53a7751d4673
$sudo docker rm 8b8afa82859a

========================= We can see the latest/limited containers =======>
vskumar@ubuntu:~$ sudo docker rm 604831dbce2a
604831dbce2a
vskumar@ubuntu:~$ sudo docker rm 718636415a7f
718636415a7f
vskumar@ubuntu:~$ sudo docker rm 53a7751d4673
53a7751d4673
vskumar@ubuntu:~$ sudo docker rm 8b8afa82859a
8b8afa82859a
vskumar@ubuntu:~$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                         PORTS               NAMES
f123dbd09116        ubuntu:16.04        "/bin/bash"         36 minutes ago      Exited (0) 36 minutes ago                          elastic_nightingale
155f4b0764b1        ubuntu:16.04        "/bin/bash"         About an hour ago   Exited (0) 30 minutes ago                          zen_volhard
11e293722c64        ubuntu:16.04        "/bin/bash"         About an hour ago   Exited (0) About an hour ago                       dreamy_bassi
d10ad2bd62f7        ubuntu:16.04        "/bin/bash"         2 hours ago         Exited (0) About an hour ago                       cranky_dijkstra
1ba71598b7b8        hello-world         "/hello"            16 hours ago        Exited (0) 16 hours ago                            musing_kare
vskumar@ubuntu:~$ sudo docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
vskumar@ubuntu:~$ 
================================>
We can also see the current container ids as below:
========== Listing containers ids ===============>
vskumar@ubuntu:~$ sudo docker ps -aq
f123dbd09116
155f4b0764b1
11e293722c64
d10ad2bd62f7
1ba71598b7b8
vskumar@ubuntu:~$ 
===============================>
To remove the inactive containers there is a prune command. Let us try with it.
Before doing it I want to make a container active and try this prune command on it:
================= I have made one container Active ======>
vskumar@ubuntu:~$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                         PORTS               NAMES
f123dbd09116        ubuntu:16.04        "/bin/bash"         About an hour ago   Exited (0) About an hour ago                       elastic_nightingale
155f4b0764b1        ubuntu:16.04        "/bin/bash"         2 hours ago         Exited (0) 40 minutes ago                          zen_volhard
11e293722c64        ubuntu:16.04        "/bin/bash"         2 hours ago         Exited (0) 2 hours ago                             dreamy_bassi
d10ad2bd62f7        ubuntu:16.04        "/bin/bash"         2 hours ago         Exited (0) 2 hours ago                             cranky_dijkstra
1ba71598b7b8        hello-world         "/hello"            17 hours ago        Exited (0) 17 hours ago                            musing_kare
vskumar@ubuntu:~$ sudo docker start 155f4b0764b1
155f4b0764b1
vskumar@ubuntu:~$ sudo docker ps 
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
155f4b0764b1        ubuntu:16.04        "/bin/bash"         2 hours ago         Up 6 seconds                            zen_volhard
vskumar@ubuntu:~$ 
========================>
To use prune , below format should be used:
$ sudo docker container prune
=========== The usage of prune command =======>
vskumar@ubuntu:~$ 
vskumar@ubuntu:~$ sudo docker container prune
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Deleted Containers:
f123dbd09116561a042e12060f449daa9a36d9a59034b1dd1b96846e66ead14d
11e293722c646a0def7a8a1f2cdf85a47654eb62ef7701bd2d7221c7e69a943f
d10ad2bd62f7a8de379272f21dfccec89c0e5829b3a58ce01927530b6b44ea01
1ba71598b7b8d97fcbd3a589a6665238690be99936b6782647b5040eeb82aafa
Total reclaimed space: 844B
vskumar@ubuntu:~$ 
========== You can see the removed container ids =============>
You can see the existing  containers:
====== Available containers after Housekeeping is done =========>
vskumar@ubuntu:~$ 
vskumar@ubuntu:~$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
155f4b0764b1        ubuntu:16.04        "/bin/bash"         2 hours ago         Up 6 minutes                            zen_volhard
vskumar@ubuntu:~$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
155f4b0764b1        ubuntu:16.04        "/bin/bash"         2 hours ago         Up 6 minutes                            zen_volhard
vskumar@ubuntu:~$ sudo docker ps -aq
155f4b0764b1
vskumar@ubuntu:~$
===================>
In this exercise we have seen the housekeeping of containers well.
Please note if you have deleted all the containers by mistake, you need to install the containers again. 
Follow the containers creation exercise.

I would like to break this session at this point. In the next blog I would like to present the lab practice on:

 “How to Build images from Docker containers?

Vcard-Shanthi Kumar V


					

8. DevOps:How to control and operate docker containers

Docker-logo

In  continuation of my previous blog on “7. DevOps: How to track changes in a container”, in this blog I would like to show some lab practice “How to control and operate docker containers”.

Controlling/operating Docker container:

In this exercise initially, we can see on how to start/stop/restart the containers.

The Docker Engine enables us to start, stop, and restart a container with a set of docker subcommands.

Let me display the docker images:

=======================>

vskumar@ubuntu:~$ sudo service docker status

docker.service – Docker Application Container Engine

Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: e

Active: active (running) since Sat 2017-11-25 15:09:35 PST; 2min 24s ago

Docs: https://docs.docker.com

Main PID: 1356 (dockerd)

Tasks: 30

Memory: 95.2M

CPU: 3.998s

=========================>

vskumar@ubuntu:~$ sudo docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

hello-world latest f2a91732366c 4 days ago 1.85kB

ubuntu 16.04 20c44cd7596f 8 days ago 123MB

ubuntu latest 20c44cd7596f 8 days ago 123MB

busybox latest 6ad733544a63 3 weeks ago 1.13MB

busybox 1.24 47bcc53f74dc 20 months ago 1.11MB

vskumar@ubuntu:~$

=======================>

Now, I want to launch our container ubuntu 16.04 with start subcommand and experiment with the docker stop subcommand, as given below:

$ sudo docker run -i -t ubuntu:16.04 /bin/bash

======================>
vskumar@ubuntu:~$ 
vskumar@ubuntu:~$ sudo docker run -i -t ubuntu:16.04 /bin/bash
root@d10ad2bd62f7:/# 
======================>
Now, we are with this container in interactive mode.
Let us apply some linux commands as below:
========================>
root@d10ad2bd62f7:/# pwd
/
root@d10ad2bd62f7:/# ls
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr
root@d10ad2bd62f7:/# cd home
root@d10ad2bd62f7:/home# ls
root@d10ad2bd62f7:/home# cd ../var
root@d10ad2bd62f7:/var# ls
backups  cache  lib  local  lock  log  mail  opt  run  spool  tmp
root@d10ad2bd62f7:/var# cd tmp
root@d10ad2bd62f7:/var/tmp# pwd
/var/tmp
root@d10ad2bd62f7:/var/tmp# ls
root@d10ad2bd62f7:/var/tmp# cd ../lib
root@d10ad2bd62f7:/var/lib# ls
apt  dpkg  initscripts  insserv  misc  pam  systemd  update-rc.d  urandom
root@d10ad2bd62f7:/var/lib# 
================================>

Now I want to create a file as below in this container:
==================>

root@d10ad2bd62f7:/var/lib# pwd
/var/lib
root@d10ad2bd62f7:/var/lib# cd ../../home
root@d10ad2bd62f7:/home# ls
root@d10ad2bd62f7:/home# touch file1.txt
===================>

Let me add some text into this file as below:
==========>
root@d10ad2bd62f7:/home# echo " Testing containers " > file1.txt
root@d10ad2bd62f7:/home# echo " Applying stop command on containers " > file1.txt
root@d10ad2bd62f7:/home# cat file1.txt
 Applying stop command on containers 
root@d10ad2bd62f7:/home# echo " Testing containers " > file1.txtroot@d10ad2bd62f7:/home# echo " Applying stop command on containers " >> file1.txt
root@d10ad2bd62f7:/home# ls
file1.txt
root@d10ad2bd62f7:/home# ls -l
total 4
-rw-r--r-- 1 root root 59 Nov 25 23:20 file1.txt
root@d10ad2bd62f7:/home# cat file1.txt 
Testing containers 
Applying stop command on containers 
root@d10ad2bd62f7:/home# 
===============>

I have applied some more linux file operations on this container as below:
=================>
root@d10ad2bd62f7:/home#      
root@d10ad2bd62f7:/home# cat file1.txt >> file2.txt
root@d10ad2bd62f7:/home# ls
file1.txt  file2.txt
root@d10ad2bd62f7:/home# ls -l
total 8
-rw-r--r-- 1 root root 59 Nov 25 23:20 file1.txt
-rw-r--r-- 1 root root 59 Nov 25 23:22 file2.txt
root@d10ad2bd62f7:/home# diff file1.txt file2.txt
root@d10ad2bd62f7:/home# echo " Applying restart command also on containers " >> file1.txt
root@d10ad2bd62f7:/home# ls -l
total 8
-rw-r--r-- 1 root root 105 Nov 25 23:23 file1.txt
-rw-r--r-- 1 root root  59 Nov 25 23:22 file2.txt
root@d10ad2bd62f7:/home# diff file1.txt file2.txt3d2
<  Applying restart command also on containers 
root@d10ad2bd62f7:/home# 
====================>
Now, let me apply a stop command on this container and see as 
below by using exit to come out and stop:
=====================>
root@155f4b0764b1:/# 
root@155f4b0764b1:/# exit
exit
vskumar@ubuntu:~$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              f2a91732366c        4 days ago          1.85kB
ubuntu              16.04               20c44cd7596f        8 days ago          123MB
ubuntu              latest              20c44cd7596f        8 days ago          123MB
busybox             latest              6ad733544a63        3 weeks ago         1.13MB
busybox             1.24                47bcc53f74dc        20 months ago       1.11MB
vskumar@ubuntu:~$ sudo docker stop  d10ad2bd62f7
d10ad2bd62f7
vskumar@ubuntu:~$ 
=============>
Now, I want to check the containers status using ps -a command as below:
==============>
vskumar@ubuntu:~$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND                 CREATED             STATUS                     PORTS               NAMES
155f4b0764b1        ubuntu:16.04        "/bin/bash"             2 minutes ago       Exited (0) 2 minutes ago                       zen_volhard
cb1ff260d48e        ubuntu              "ls /usr/src"           10 hours ago        Exited (0) 10 hours ago                        wonderful_hawking
b20691fd8fb5        ubuntu              "ls /usr"               10 hours ago        Exited (0) 10 hours ago                        friendly_mirzakhani
431ba4c53028        ubuntu              "ls"                    10 hours ago        Exited (0) 10 hours ago                        affectionate_nobel
2c31684bb1f4        ubuntu              "ls -la"                10 hours ago        Exited (0) 10 hours ago                        zealous_meitner
fe2e3b449daf        ubuntu              "ls -la /home/."        10 hours ago        Exited (0) 10 hours ago                        dreamy_shirley
c44bdd05b94d        ubuntu              "ls -la home."          10 hours ago        Exited (2) 10 hours ago                        elastic_pasteur
8b8afa82859a        ubuntu              "ls -la"                10 hours ago        Exited (0) 10 hours ago                        festive_panini
2811eb37af61        ubuntu              "ls -la 604831dbce2a"   10 hours ago        Exited (2) 10 hours ago                        jolly_swartz
604831dbce2a        ubuntu:16.04        "/bin/bash"             10 hours ago        Exited (0) 10 hours ago                        vibrant_ride
718636415a7f        ubuntu:16.04        "/bin/bash"             11 hours ago        Exited (0) 10 hours ago                        reverent_noyce
53a7751d4673        ubuntu:16.04        "/bin/bash"             12 hours ago        Exited (0) 12 hours ago                        musing_chandrasekhar
32bc16b508d4        ubuntu              "bash"                  13 hours ago        Exited (0) 13 hours ago                        eager_goldberg
1dd55efde43f        hello-world         "/hello"                13 hours ago        Exited (0) 13 hours ago                        peaceful_pasteur
a744246ffb8e        hello-world         "/hello"                15 hours ago        Exited (0) 15 hours ago                        naughty_wing
1ba71598b7b8        hello-world         "/hello"                15 hours ago        Exited (0) 15 hours ago                        musing_kare
vskumar@ubuntu:~$ 
===================>
you can see the latest status of our container;
155f4b0764b1        ubuntu:16.04        "/bin/bash"             2 minutes ago       Exited (0) 2 minutes ago                       zen_volhard
It means Docker  maintains in the logs on the usage of containers also.
Now, I want to start the previously stopped container using the docker start subcommand 
by specifying the container ID as an argument, as follows:
$ sudo docker start 155f4b0764b1
===============>
vskumar@ubuntu:~$ sudo docker start 155f4b0764b1
155f4b0764b1
vskumar@ubuntu:~$ 
===============>
Let us check the images status also as below:
==================> Copied the 1st two lines only ----->
vskumar@ubuntu:~$ sudo docker ps -a |more
CONTAINER ID        IMAGE               COMMAND                 CREATED         
    STATUS                      PORTS               NAMES
155f4b0764b1        ubuntu:16.04        "/bin/bash"             10 minutes ago  
    Up About a minute                               zen_volhard
11e293722c64        ubuntu:16.04        "/bin/bash"             12 minutes ago  
    Exited (0) 12 minutes ago  
====================>
It means it shows the current status of the container id:155f4b0764b1 
We need to notice one thing here.

By default, the docker start subcommand will not attach to the container.

We can attach it to the container either using the -a option in the docker start subcommand or by explicitly using the docker attach subcommand.

Now let us try these options.

We will see attach command

$ sudo docker attach 155f4b0764b1
=================>
vskumar@ubuntu:~$ 
vskumar@ubuntu:~$ sudo docker attach 155f4b0764b1
root@155f4b0764b1:/# 
root@155f4b0764b1:/#
=================>
So the attach command brought the container into interactive mode.
Now let me exit it and try the -a option with docker start command:
==================>
root@155f4b0764b1:/home# 
root@155f4b0764b1:/home# exit
exit
===============>
with start -a option:
=============>
vskumar@ubuntu:~$ sudo docker start -a 155f4b0764b1
root@155f4b0764b1:/# 
=================>
After exit, I have tried ps command:
=====================>
vskumar@ubuntu:~$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
155f4b0764b1        ubuntu:16.04        "/bin/bash"         21 minutes ago      Up 3 minutes                            zen_volhard
vskumar@ubuntu:~$ 
======================>
From the above display you can see that its start and current status.
It means the container is active and running.
Now, I want to make another [below] container active.
1dd55efde43f        hello-world         "/hello"                13 hours ago Exited (0) 13 hours ago                        peaceful_pasteur
Let us see the ps command after these 2 containers are in active state.
I want to use the below command:
$ sudo docker start -a 1dd55efde43f
===================>
vskumar@ubuntu:~$ sudo docker start -a 1dd55efde43f

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.

Let us  try something more ambitious, we can run an Ubuntu container with:
 $ docker run -it ubuntu bash

If you want to;
Share images, automate workflows, and more with a free Docker ID:
visit: https://cloud.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/

vskumar@ubuntu:~$ 
===================>
Please note the above container doesn't have a any os related process to 
keep running continuously. 
Just it displays the message only. Hence 
in the list it will not appear. 
Now, let me list the current processes using docker ps command:
===========>
vskumar@ubuntu:~$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
155f4b0764b1        ubuntu:16.04        "/bin/bash"         32 minutes ago      Up 14 minutes                           zen_volhard
vskumar@ubuntu:~$ 
==============>
So as on now one container is running.

The next set of container controlling subcommands are docker pause and docker unpause.

The docker pause subcommand will freeze the execution of all the processes within the container.

The docker unpause subcommand will unfreeze the execution of all the processes within the container and resume the execution from the point where it was frozen.

Let us try the below command 
$sudo docker pause 155f4b0764b1
========================>
vskumar@ubuntu:~$ 
vskumar@ubuntu:~$ sudo docker pause 155f4b0764b1
155f4b0764b1
vskumar@ubuntu:~$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                   PORTS               NAMES
155f4b0764b1        ubuntu:16.04        "/bin/bash"         About an hour ago   Up 30 minutes (Paused)                       zen_volhard
vskumar@ubuntu:~$ 
==========================>
You can see the current status as Paused.
Now let me try unpause command also.
$ sudo docker unpause 155f4b0764b1
You can see the total output of this container with pause and unpause statuses:
===================>
vskumar@ubuntu:~$ 
vskumar@ubuntu:~$ sudo docker pause 155f4b0764b1
155f4b0764b1
vskumar@ubuntu:~$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                   PORTS               NAMES
155f4b0764b1        ubuntu:16.04        "/bin/bash"         About an hour ago   Up 30 minutes (Paused)                       zen_volhard
vskumar@ubuntu:~$ ^C
vskumar@ubuntu:~$ sudo docker unpause 155f4b0764b1
155f4b0764b1
vskumar@ubuntu:~$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
155f4b0764b1        ubuntu:16.04        "/bin/bash"         About an hour ago   Up 32 minutes                           zen_volhard
vskumar@ubuntu:~$ 
======================>
Now, in this lab session finally we will use the stop command:

The container and the script running within it can be stopped using the docker stop subcommand, as shown below:

$ sudo docker stop 155f4b0764b1
=====================> 
vskumar@ubuntu:~$ sudo docker stop 155f4b0764b1
155f4b0764b1
vskumar@ubuntu:~$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED STATUS              PORTS               NAMES
=============== It shows there is no active container =============>
Now, let me try with -a and more options.
=========== Partial display is shown here upto the container ===========>
vskumar@ubuntu:~$ sudo docker ps -a |more
CONTAINER ID        IMAGE               COMMAND                 CREATED         
    STATUS                         PORTS               NAMES
f123dbd09116        ubuntu:16.04        "/bin/bash"             6 minutes ago   
    Exited (0) 5 minutes ago                           elastic_nightingale
3cfdea29ce6e        ubuntu              "bash"                  14 minutes ago  
    Exited (0) 14 minutes ago                          gallant_nobel
155f4b0764b1        ubuntu:16.04        "/bin/bash"             About an hour ag
o   Exited (0) 17 seconds ago  
================================>

So far in this lab session, we have seen the differences of different commands to operate and control the containers. I would like to break this session for now. In the next blog we will see on how to manage “Housekeeping containers“.

 Vcard-Shanthi Kumar V

 

7. DevOps: How to track changes in a container

Docker-logo

In  continuation of my previous blog on “6. DevOps: How to work with interactive docker containers”, in this blog I would like to show some lab practice “How to track changes in a container”.

Tracking changes inside containers:

Now, let us see the container operations and tracking them.

Let’s launch a container in interactive mode, as we have done in previous session, we can use the below command.

$ sudo docker run -i -t ubuntu:16.04 /bin/bash 
=================>
vskumar@ubuntu:/var/log$ sudo docker run -i -t ubuntu:16.04 /bin/bash  
root@718636415a7f:/# ps
   PID TTY          TIME CMD
     1 pts/0    00:00:00 bash
     9 pts/0    00:00:00 ps
root@718636415a7f:/# ps -ef
UID         PID   PPID  C STIME TTY          TIME CMD
root          1      0  0 12:39 pts/0    00:00:00 /bin/bash
root         10      1  0 12:53 pts/0    00:00:00 ps -ef
root@718636415a7f:/# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@718636415a7f:/# 
======================>
Now, let us go to home directory:
========>
root@718636415a7f:/# pwd
/
root@718636415a7f:/# cd home
root@718636415a7f:/home# pwd
/home
root@718636415a7f:/home# ls
root@718636415a7f:/home# 
==============>
Now, as a standalone machine of this docker container, 
I want to create 4 text files using touch command as below:
==============>
root@718636415a7f:/home# ls
root@718636415a7f:/home# ls -l
total 0
root@718636415a7f:/home# touch {vsk1,vsk2,vsk3,vsk4}
root@718636415a7f:/home# ls -l
total 0
-rw-r--r-- 1 root root 0 Nov 25 12:57 vsk1
-rw-r--r-- 1 root root 0 Nov 25 12:57 vsk2
-rw-r--r-- 1 root root 0 Nov 25 12:57 vsk3
-rw-r--r-- 1 root root 0 Nov 25 12:57 vsk4
root@718636415a7f:/home# 
======================>

I am adding some text to each of them as below:

====================>

root@718636415a7f:/home# pwd

/home

root@718636415a7f:/home# echo ‘Testing vsk1’ > vsk1

root@718636415a7f:/home# ls -l

total 4

-rw-r–r– 1 root root 13 Nov 25 13:02 vsk1

-rw-r–r– 1 root root 0 Nov 25 12:57 vsk2

-rw-r–r– 1 root root 0 Nov 25 12:57 vsk3

-rw-r–r– 1 root root 0 Nov 25 12:57 vsk4

root@718636415a7f:/home# echo ‘Testing vsk2’ > vsk2

root@718636415a7f:/home# echo ‘Testing vsk3’ > vsk3

root@718636415a7f:/home# echo ‘NOT Testing vsk4’ > vsk4

root@718636415a7f:/home# ls -l

total 16

-rw-r–r– 1 root root 13 Nov 25 13:02 vsk1

-rw-r–r– 1 root root 13 Nov 25 13:02 vsk2

-rw-r–r– 1 root root 13 Nov 25 13:02 vsk3

-rw-r–r– 1 root root 17 Nov 25 13:02 vsk4

root@718636415a7f:/home#

=====================>

I have created 4 files and added some text into them.

Now, I want to execute a diff command on them:

==========================>

root@718636415a7f:/home# diff vsk1 vsk2

1c1

< Testing vsk1

> Testing vsk2

root@718636415a7f:/home# diff vsk2 vsk3

1c1

< Testing vsk2

> Testing vsk3

root@718636415a7f:/home# echo ‘NOT Testing vsk4’ > vsk1

root@718636415a7f:/home# diff vsk1 vsk4

root@718636415a7f:/home# diff vsk2 vsk4

1c1

< Testing vsk2

> NOT Testing vsk4

root@718636415a7f:/home#

===========================>

Now, I want to exit this container and go back to docker host.

I have detached it using exit.

And back to docker host.

Now, I want to use the diff command as below from host machine to the container:

===========================>

root@718636415a7f:/home# ls -l

total 16

-rw-r–r– 1 root root 17 Nov 25 13:05 vsk1

-rw-r–r– 1 root root 13 Nov 25 13:02 vsk2

-rw-r–r– 1 root root 13 Nov 25 13:02 vsk3

-rw-r–r– 1 root root 17 Nov 25 13:02 vsk4

root@718636415a7f:/home# exit

exit

vskumar@ubuntu:/var/log$ sudo docker diff 718636415a7f

[sudo] password for vskumar:

C /home

A /home/vsk1

A /home/vsk2

A /home/vsk3

A /home/vsk4

C /root

A /root/.bash_history

vskumar@ubuntu:/var/log$

=====================>

The 1st line ‘C /home’ shows; the home directory is modified by showing ‘C’ as changed.

The ‘A’ shows;  before each line denotes the file is added.

If you have a deleted file, it can show as ‘D’ before the file.

Also please let us note here on how docker engine picks up the image with the below priority;

When we work with an image and if we don’t specify that image name, then the latest image (recently generated) will be identified and used by the Docker Engine.

We can check the status of the containers as below using ps -a:

You can see a detailed output from this command from the below display:

==================================>

vskumar@ubuntu:/var/log$ ls

alternatives.log bootstrap.log dmesg fsck kern.log speech-dispatcher unattended-upgrades wtmp

apport.log btmp dpkg.log gpu-manager.log lastlog syslog upstart Xorg.0.log

apt cups faillog hp lightdm syslog.1 vmware Xorg.0.log.old

auth.log dist-upgrade fontconfig.log installer samba syslog.2.gz vmware-vmsvc.log

vskumar@ubuntu:/var/log$ sudo docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

cb1ff260d48e ubuntu “ls /usr/src” 3 minutes ago Exited (0) 3 minutes ago wonderful_hawking

b20691fd8fb5 ubuntu “ls /usr” 3 minutes ago Exited (0) 3 minutes ago friendly_mirzakhani

431ba4c53028 ubuntu “ls” 3 minutes ago Exited (0) 3 minutes ago affectionate_nobel

2c31684bb1f4 ubuntu “ls -la” 3 minutes ago Exited (0) 3 minutes ago zealous_meitner

fe2e3b449daf ubuntu “ls -la /home/.” 4 minutes ago Exited (0) 4 minutes ago dreamy_shirley

c44bdd05b94d ubuntu “ls -la home.” 4 minutes ago Exited (2) 4 minutes ago elastic_pasteur

8b8afa82859a ubuntu “ls -la” 4 minutes ago Exited (0) 4 minutes ago festive_panini

2811eb37af61 ubuntu “ls -la 604831dbce2a” 4 minutes ago Exited (2) 4 minutes ago jolly_swartz

604831dbce2a ubuntu:16.04 “/bin/bash” 8 minutes ago Exited (0) 6 minutes ago vibrant_ride

718636415a7f ubuntu:16.04 “/bin/bash” 45 minutes ago Exited (0) 18 minutes ago reverent_noyce

53a7751d4673 ubuntu:16.04 “/bin/bash” 2 hours ago Exited (0) 2 hours ago musing_chandrasekhar

32bc16b508d4 ubuntu “bash” 3 hours ago Exited (0) 3 hours ago eager_goldberg

1dd55efde43f hello-world “/hello” 3 hours ago Exited (0) 3 hours ago peaceful_pasteur

a744246ffb8e hello-world “/hello” 5 hours ago Exited (0) 5 hours ago naughty_wing

1ba71598b7b8 hello-world “/hello” 5 hours ago Exited (0) 5 hours ago musing_kare

vskumar@ubuntu:/var/log$

============================>

I would like to terminate the session at this point. In the next blog I would like to present “How to control and operate docker containers”.

Vcard-Shanthi Kumar V-v3

6. DevOps: How to work with interactive Docker containers

Docker-logo

In  continuation of my previous blog on “5. DevOps: How to work with Docker Images”, in this blog I would like to show some lab practice on Interactive Docker containers.

Working with an interactive Docker container:

In the previous lab session, we worked with first Hello World container. And we came to know how the containerization works. Now, we are going to run a container in interactive mode.

What is docker run command ?:

The docker run subcommand takes an image as an input and launches it as a container.

What flags we need to use ?:

We have to pass the -t and -i flags to the docker run subcommand in order to make the container interactive.

The -i flag is the key driver, it makes the container interactive by grabbing the standard input (STDIN) of the container into the terminal.

The -t flag allocates a pseudo-TTY or a pseudo Terminal (Terminal emulator) and then assigns that to the container.

Note: Please note in the earlier session we have executed a container on unbuntu name.

But now, we will explore completely the interactive container operations.

In the below example, we are going to launch an interactive container using the ubuntu:16.04 image and /bin/bash as the command:

$ sudo docker run -i -t ubuntu:16.04 /bin/bash 

=========== Output ============>

vskumar@ubuntu:/var/log$ sudo docker run -i -t ubuntu:16.04 /bin/bash

Unable to find image ‘ubuntu:16.04’ locally

16.04: Pulling from library/ubuntu

Digest: sha256:7c67a2206d3c04703e5c23518707bdd4916c057562dd51c74b99b2ba26af0f79

Status: Downloaded newer image for ubuntu:16.04

root@53a7751d4673:/#

===================>

Why the error messages [Unable to find image] appear ?:

As the ubuntu 16.04 image is not downloaded yet, we get the above message and with the docker run command it will start pulling the ubuntu 16.04 image automatically with following message:

Unable to find image 'ubuntu:16.04' locally
16.04: Pulling from library/ubuntu

When the download is completed, the container will get launched along with the ubuntu:16.04 image.

It will also launch a Bash shell within the container, because we have specified /bin/bash as the command to be executed. This landed us in a Bash prompt, as shown below:

root@53a7751d4673:/#

What is ’53a7751d4673′?:

It is the hostname of the container. In Docker, the hostname is the same as the container ID.

Now, let us run a few commands interactively and confirm what we mentioned about the prompt is correct, as shown below:

To check the hostname below commands need to be executed:

root@53a7751d4673:/# hostname

root@53a7751d4673:/# id

root@53a7751d4673:/# echo $PS1

When we execute them, can see the below output:

==============>

root@53a7751d4673:/#

root@53a7751d4673:/# hostname

53a7751d4673

root@53a7751d4673:/# id

uid=0(root) gid=0(root) groups=0(root)

root@53a7751d4673:/# echo $PS1

\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$

root@53a7751d4673:/#

=====================>

So, we have seen the Host name as ’53a7751d4673′.

Id as ‘root ‘

Using ‘PS1’, —>Displays username, hostname and current working directory in the prompt.

PS1 in this example displays the following three information in the prompt:

\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$

  • \u – Username
  • \h – Hostname
  • \w – Full path of the current working directory

==============>

root@53a7751d4673:/# pwd

/

root@53a7751d4673:/#

==========>

Note, we are within the ubuntu 16.04 container and it works as Linux machine. So we can try some Linux commands also:

===============>

root@53a7751d4673:/# ps

PID TTY TIME CMD

1 pts/0 00:00:00 bash

26 pts/0 00:00:00 ps

root@53a7751d4673:/# ps -ef

UID PID PPID C STIME TTY TIME CMD

root 1 0 0 11:28 pts/0 00:00:00 /bin/bash

root 27 1 0 11:48 pts/0 00:00:00 ps -ef

root@53a7751d4673:/#

root@53a7751d4673:/# ls

bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var

root@53a7751d4673:/# ls -l

total 64

drwxr-xr-x 2 root root 4096 Nov 14 13:49 bin

drwxr-xr-x 2 root root 4096 Apr 12 2016 boot

drwxr-xr-x 5 root root 360 Nov 25 11:28 dev

drwxr-xr-x 45 root root 4096 Nov 25 11:28 etc

drwxr-xr-x 2 root root 4096 Apr 12 2016 home

drwxr-xr-x 8 root root 4096 Sep 13 2015 lib

drwxr-xr-x 2 root root 4096 Nov 14 13:49 lib64

drwxr-xr-x 2 root root 4096 Nov 14 13:48 media

drwxr-xr-x 2 root root 4096 Nov 14 13:48 mnt

drwxr-xr-x 2 root root 4096 Nov 14 13:48 opt

dr-xr-xr-x 250 root root 0 Nov 25 11:28 proc

drwx—— 2 root root 4096 Nov 14 13:49 root

drwxr-xr-x 6 root root 4096 Nov 14 13:49 run

drwxr-xr-x 2 root root 4096 Nov 17 21:59 sbin

drwxr-xr-x 2 root root 4096 Nov 14 13:48 srv

dr-xr-xr-x 13 root root 0 Nov 25 11:28 sys

drwxrwxrwt 2 root root 4096 Nov 14 13:49 tmp

drwxr-xr-x 11 root root 4096 Nov 14 13:48 usr

drwxr-xr-x 13 root root 4096 Nov 14 13:49 var

root@53a7751d4673:/#

================>

So, ubuntu 16.04 container is nothing but a linux machine and we executed the above commands.

Now, I want to change the root permissions as below:

==============>

root@53a7751d4673:/# chmod +777 root

root@53a7751d4673:/# ls -l

total 64

drwxr-xr-x 2 root root 4096 Nov 14 13:49 bin

drwxr-xr-x 2 root root 4096 Apr 12 2016 boot

drwxr-xr-x 5 root root 360 Nov 25 11:28 dev

drwxr-xr-x 45 root root 4096 Nov 25 11:28 etc

drwxr-xr-x 2 root root 4096 Apr 12 2016 home

drwxr-xr-x 8 root root 4096 Sep 13 2015 lib

drwxr-xr-x 2 root root 4096 Nov 14 13:49 lib64

drwxr-xr-x 2 root root 4096 Nov 14 13:48 media

drwxr-xr-x 2 root root 4096 Nov 14 13:48 mnt

drwxr-xr-x 2 root root 4096 Nov 14 13:48 opt

dr-xr-xr-x 255 root root 0 Nov 25 11:28 proc

drwxrwxrwx 2 root root 4096 Nov 14 13:49 root

drwxr-xr-x 6 root root 4096 Nov 14 13:49 run

drwxr-xr-x 2 root root 4096 Nov 17 21:59 sbin

drwxr-xr-x 2 root root 4096 Nov 14 13:48 srv

dr-xr-xr-x 13 root root 0 Nov 25 11:48 sys

drwxrwxrwt 2 root root 4096 Nov 14 13:49 tmp

drwxr-xr-x 11 root root 4096 Nov 14 13:48 usr

drwxr-xr-x 13 root root 4096 Nov 14 13:49 var

root@53a7751d4673:/#

================>

Now, I want to exit from container and come back to host machine.

==================>

root@53a7751d4673:/#

root@53a7751d4673:/# exit

exit

vskumar@ubuntu:/var/log$

===============>

Whenever the Bash exit command is used in the interactive container, it will terminate the Bash shell process.

In turn it will stop the container and returns to the docker host machine.

As a result, we can see the Docker host’s prompt $


You can see the status of docker images as below when I used ‘sudo docker images’ :

==================>

vskumar@ubuntu:/var/log$

vskumar@ubuntu:/var/log$ sudo docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

hello-world latest f2a91732366c 4 days ago 1.85kB

ubuntu 16.04 20c44cd7596f 7 days ago 123MB

ubuntu latest 20c44cd7596f 7 days ago 123MB

busybox latest 6ad733544a63 3 weeks ago 1.13MB

busybox 1.24 47bcc53f74dc 20 months ago 1.11MB

vskumar@ubuntu:/var/log$

=====================>

You can see whatever containers; we have have used in the past exercises.

At this point, I would like to stop this lab session. And in the next blog we can see on “How to track changes in a container?”.

 

Vcard-Shanthi Kumar V

 

 

5. DevOps: How to work with Docker Images

Docker-logo

In  continuation of my previous blog on “4. DevOps: How to work with Docker Containers”, in this blog I would like to give some lab practice on Docker Images.

How to pull the docker public images ?:
Docker portal will have numerous images available  under public.
Now, there is a need for us to know the usage of docker pull command, which is the defacto command to download Docker images.

Now, in this section, we will use the busybox image, one of the smallest but a very handy Docker image, to dive deep into Docker image handling:
$sudo docker pull busybox
============= Output ============>
vskumar@ubuntu:/var/tmp$ sudo docker pull busybox
Using default tag: latest
latest: Pulling from library/busybox
0ffadd58f2a6: Pull complete
Digest: sha256:bbc3a03235220b170ba48a157dd097dd1379299370e1ed99ce976df0355d24f0
Status: Downloaded newer image for busybox:latest
vskumar@ubuntu:/var/tmp$
=================>
Sometimes it might reject this request. We need to keep on trying to get it. I tried 4 times at different timings to connect to it.
Please note now, we have three images as below through all of our so far exercises:
===================>
vskumar@ubuntu:/var/log$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest f2a91732366c 4 days ago 1.85kB
ubuntu latest 20c44cd7596f 7 days ago 123MB
busybox latest 6ad733544a63 3 weeks ago 1.13MB
vskumar@ubuntu:/var/log$
===============>
Now, let us stop the docker services and check the status as below:
=================>
vskumar@ubuntu:/var/log$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest f2a91732366c 4 days ago 1.85kB
ubuntu latest 20c44cd7596f 7 days ago 123MB
busybox latest 6ad733544a63 3 weeks ago 1.13MB
vskumar@ubuntu:/var/log$ sudo service docker stop
vskumar@ubuntu:/var/log$ sudo service docker status
● docker.service – Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: e
Active: inactive (dead) since Sat 2017-11-25 02:52:25 PST; 8s ago
Docs: https://docs.docker.com
Process: 1224 ExecStart=/usr/bin/dockerd -H fd:// (code=exited, status=0/SUCCE
Main PID: 1224 (code=exited, status=0/SUCCESS)
Nov 25 02:21:42 ubuntu dockerd[1224]: time=”2017-11-25T02:21:42.863518710-08:00″
Nov 25 02:21:43 ubuntu dockerd[1224]: time=”2017-11-25T02:21:43-08:00″ level=inf
Nov 25 02:27:08 ubuntu dockerd[1224]: time=”2017-11-25T02:27:08.010096274-08:00″
Nov 25 02:27:08 ubuntu dockerd[1224]: time=”2017-11-25T02:27:08-08:00″ level=inf
Nov 25 02:27:08 ubuntu dockerd[1224]: time=”2017-11-25T02:27:08.199685599-08:00″
Nov 25 02:52:25 ubuntu dockerd[1224]: time=”2017-11-25T02:52:25.010875880-08:00″
Nov 25 02:52:25 ubuntu systemd[1]: Stopping Docker Application Container Engine.
Nov 25 02:52:25 ubuntu dockerd[1224]: time=”2017-11-25T02:52:25.081714537-08:00″
Nov 25 02:52:25 ubuntu systemd[1]: Stopped Docker Application Container Engine.
Nov 25 02:52:25 ubuntu systemd[1]: Stopped Docker Application Container Engine.
vskumar@ubuntu:/var/log$
====================>
You can see the inactive status of docker.
In such cases, restart the Docker service, as shown here:

$ sudo service docker restart
You can see the output as below:
==================>
vskumar@ubuntu:/var/log$ sudo service docker restart
vskumar@ubuntu:/var/log$ sudo service docker status 
docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: e
   Active: active (running) since Sat 2017-11-25 02:54:42 PST; 6s ago
     Docs: https://docs.docker.com
 Main PID: 3769 (dockerd)
    Tasks: 18
   Memory: 24.6M
      CPU: 989ms
   CGroup: /system.slice/docker.service
           ├─3769 /usr/bin/dockerd -H fd://
           └─3778 docker-containerd --config /var/run/docker/containerd/containe

Nov 25 02:54:41 ubuntu dockerd[3769]: time="2017-11-25T02:54:41.159062708-08:00"
Nov 25 02:54:41 ubuntu dockerd[3769]: time="2017-11-25T02:54:41.159806997-08:00"
Nov 25 02:54:41 ubuntu dockerd[3769]: time="2017-11-25T02:54:41.163503112-08:00"
Nov 25 02:54:41 ubuntu dockerd[3769]: time="2017-11-25T02:54:41.743276580-08:00"
Nov 25 02:54:41 ubuntu dockerd[3769]: time="2017-11-25T02:54:41.955217284-08:00"
Nov 25 02:54:41 ubuntu dockerd[3769]: time="2017-11-25T02:54:41.975961283-08:00"
Nov 25 02:54:42 ubuntu dockerd[3769]: time="2017-11-25T02:54:42.092220161-08:00"
Nov 25 02:54:42 ubuntu dockerd[3769]: time="2017-11-25T02:54:42.094334663-08:00"
Nov 25 02:54:42 ubuntu systemd[1]: Started Docker Application Container Engine.
Nov 25 02:54:42 ubuntu dockerd[3769]: time="2017-11-25T02:54:42.190194886-08:00"

vskumar@ubuntu:/var/log$ 

========================>

Now, let us reconfirm the existing docker images as below:
================>

vskumar@ubuntu:/var/log$ ^C
vskumar@ubuntu:/var/log$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              f2a91732366c        4 days ago          1.85kB
ubuntu              latest              20c44cd7596f        7 days ago          123MB
busybox             latest              6ad733544a63        3 weeks ago         1.13MB
vskumar@ubuntu:/var/log$ 
=======================>

By default, Docker always uses the image that is tagged as latest.

Each image variant can be directly identified by qualifying it with an appropriate tag.

An image can be tag-qualified by adding a colon (:) between the tag and the repository name (<repository>:<tag>). For demonstration, we will pull the 1.24 tagged version of busybox as shown here:

Now, For lab demonstration, we will pull the 1.24 tagged version of busybox as shown here:

$ sudo docker pull busybox:1.24

Now. You can see the total output before and after executing the above command:

==============================>

vskumar@ubuntu:/var/log$ ^C

vskumar@ubuntu:/var/log$ sudo docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

hello-world latest f2a91732366c 4 days ago 1.85kB

ubuntu latest 20c44cd7596f 7 days ago 123MB

busybox latest 6ad733544a63 3 weeks ago 1.13MB

vskumar@ubuntu:/var/log$ ^C

vskumar@ubuntu:/var/log$

vskumar@ubuntu:/var/log$

vskumar@ubuntu:/var/log$ sudo docker pull busybox:1.24

1.24: Pulling from library/busybox

385e281300cc: Pull complete

a3ed95caeb02: Pull complete

Digest: sha256:8ea3273d79b47a8b6d018be398c17590a4b5ec604515f416c5b797db9dde3ad8

Status: Downloaded newer image for busybox:1.24

vskumar@ubuntu:/var/log$ sudo docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

hello-world latest f2a91732366c 4 days ago 1.85kB

ubuntu latest 20c44cd7596f 7 days ago 123MB

busybox latest 6ad733544a63 3 weeks ago 1.13MB

busybox 1.24 47bcc53f74dc 20 months ago 1.11MB

vskumar@ubuntu:/var/log$

==============================>

There are two busybox containers with different versions.

So, on the basis of TAG values the containers are being pulled.

How to Search Docker images:

So far we have pulled the known images from the docker-hub.

Let us identify some docker images by using a search option as below. We can search for Docker images in the Docker Hub Registry using the docker search subcommand, as shown in this example:

$ sudo docker search mysql

You can see the displayed output of mysql images from the Docker Hub Registry:

=============>

vskumar@ubuntu:/var/log$ sudo docker search mysql

NAME DESCRIPTION STARS OFFICIAL AUTOMATED

mysql MySQL is a widely used, open-source relation… 5278 [OK]

mariadb MariaDB is a community-developed fork of MyS… 1634 [OK]

mysql/mysql-server Optimized MySQL Server Docker images. Create… 368 [OK]

percona Percona Server is a fork of the MySQL relati… 303 [OK]

hypriot/rpi-mysql RPi-compatible Docker Image with Mysql 74

zabbix/zabbix-server-mysql Zabbix Server with MySQL database support 64 [OK]

centurylink/mysql Image containing mysql. Optimized to be link… 53 [OK]

sameersbn/mysql 48 [OK]

zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server wi… 38 [OK]

tutum/mysql Base docker image to run a MySQL database se… 29

1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 17 [OK]

schickling/mysql-backup-s3 Backup MySQL to S3 (supports periodic backup… 16 [OK]

centos/mysql-57-centos7 MySQL 5.7 SQL database server 15

linuxserver/mysql A Mysql container, brought to you by LinuxSe… 12

centos/mysql-56-centos7 MySQL 5.6 SQL database server 6

openshift/mysql-55-centos7 DEPRECATED: A Centos7 based MySQL v5.5 image… 6

frodenas/mysql A Docker Image for MySQL 3 [OK]

dsteinkopf/backup-all-mysql backup all DBs in a mysql server 3 [OK]

circleci/mysql MySQL is a widely used, open-source relation… 2

cloudfoundry/cf-mysql-ci Image used in CI of cf-mysql-release 0

cloudposse/mysql Improved `mysql` service with support for `m… 0 [OK]

ansibleplaybookbundle/rhscl-mysql-apb An APB which deploys RHSCL MySQL 0 [OK]

astronomerio/mysql-sink MySQL sink 0 [OK]

inferlink/landmark-mysql landmark-mysql 0 [OK]

astronomerio/mysql-source MySQL source 0 [OK]

vskumar@ubuntu:/var/log$ ^C

vskumar@ubuntu:/var/log$

====================>

You can get the top 5 images by suing head -5 linux command.

$sudo docker search mysql | head -5

=============>

vskumar@ubuntu:/var/log$ sudo docker search mysql | head -5

NAME DESCRIPTION STARS OFFICIAL AUTOMATED

mysql MySQL is a widely used, open-source relation… 5278 [OK]

mariadb MariaDB is a community-developed fork of MyS… 1634 [OK]

mysql/mysql-server Optimized MySQL Server Docker images. Create… 368 [OK]

percona Percona Server is a fork of the MySQL relati… 303 [OK]

vskumar@ubuntu:/var/log$

===============>

If you see the above list, The mysql image curated and hosted by Docker Inc has a 5278 star rating, which is indicated as this is the most popular mysql image and aslo as Official image to use it. For security reasons we should use the official and highly rated images only.

As we planned, in this blog we have worked with the Docker images.

At this point we can stop this session and in the next blog we can see on “How to work with interactive containers”.

Vcard-Shanthi Kumar V-v3

Feel free to Contact me :

 

4. DevOps: How to create and work with Docker Containers

Docker-logo

In continuation of my previous blog on 2. DevOps: How to install Docker 17.03.0 community edition and start working with it on Ubuntu 16.x VM [https://vskumar.blog/2017/11/25/2-devops-how-to-install-docker-17-03-0-community-edition-and-start-working-with-it-on-ubuntu-16-x-vm/], in this blog I would like to cover the lab practice on Docker containers.

Assuming you have the same setup as we did in the previous lab session,

using the below subcommand, you can view the current image hello-world

Use the below command:

sudo docker run -it hello-world

$docker history hello-world

You can run this image and see:

======================>

vskumar@ubuntu:~$ sudo docker history hello-world

[sudo]

password for vskumar:
IMAGE CREATED CREATED BY SIZE COMMENT
f2a91732366c 5 days ago /bin/sh -c #(nop) CMD [“/hello”] 0B
<missing> 5 days ago /bin/sh -c #(nop) COPY file:f3dac9d5b1b0307f… 1.85kB
vskumar@ubuntu:~$

======================>

Check the current docker information:

sudo docker info |more

======================================>

vskumar@ubuntu:~$ sudo docker info |more
Containers: 2
Running: 1
Paused: 0
Stopped: 1
Images: 6
Server Version: 17.11.0-ce
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 14
Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 992280e8e265f491f7a624ab82f3e238be086e49
runc version: 0351df1c5a66838d0c392b4ac4cf9450de844e2d
–More–WARNING: No swap limit support
init version: 949e6fa
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 4.10.0-40-generic
Operating System: Ubuntu 16.04.3 LTS
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 1.933GiB
Name: ubuntu
ID: KH7E:PWA2:EJGE:MZCA:3RVJ:LU2W:BA7S:DTIQ:32HP:XXO7:RXBR:4XQI
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false

vskumar@ubuntu:~$

=============================>

Now, let us work on the Docker images operations:

In the previous session, we demonstrated the typical Hello World example using the
hello-world image.

you can run an Ubuntu container with:

$ sudo docker run -it ubuntu bash

you can run an Ubuntu container with:

======= We are in Docker container =====>

vskumar@ubuntu:~$ sudo docker run -it ubuntu bash
root@10ffea6140f9:/#

============>

Now, let us apply some Linux commands as below:

==================>

root@10ffea6140f9:/# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
root@10ffea6140f9:/# ps -a
PID TTY TIME CMD
11 pts/0 00:00:00 ps
root@10ffea6140f9:/# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 05:36 pts/0 00:00:00 bash
root 12 1 0 05:38 pts/0 00:00:00 ps -ef
root@10ffea6140f9:/# cd lib
root@10ffea6140f9:/lib# ls
init lsb systemd terminfo udev x86_64-linux-gnu
root@10ffea6140f9:/lib# cd ..
root@10ffea6140f9:/# cd var
root@10ffea6140f9:/var# pwd
/var
root@10ffea6140f9:/var# ls
backups cache lib local lock log mail opt run spool tmp
root@10ffea6140f9:/var# cd log
root@10ffea6140f9:/var/log# ls
alternatives.log bootstrap.log dmesg faillog lastlog
apt btmp dpkg.log fsck wtmp

root@10ffea6140f9:/var/log# cat dpkg.log |more
2017-11-14 13:48:30 startup archives install
2017-11-14 13:48:30 install base-passwd:amd64 <none> 3.5.39
2017-11-14 13:48:30 status half-installed base-passwd:amd64 3.5.39
2017-11-14 13:48:30 status unpacked base-passwd:amd64 3.5.39
2017-11-14 13:48:30 status unpacked base-passwd:amd64 3.5.39
2017-11-14 13:48:30 configure base-passwd:amd64 3.5.39 3.5.39
2017-11-14 13:48:30 status unpacked base-passwd:amd64 3.5.39
2017-11-14 13:48:30 status half-configured base-passwd:amd64 3.5.39
2017-11-14 13:48:30 status installed base-passwd:amd64 3.5.39
2017-11-14 13:48:30 startup archives install
2017-11-14 13:48:30 install base-files:amd64 <none> 9.4ubuntu4
2017-11-14 13:48:30 status half-installed base-files:amd64 9.4ubuntu4
2017-11-14 13:48:30 status unpacked base-files:amd64 9.4ubuntu4
2017-11-14 13:48:30 status unpacked base-files:amd64 9.4ubuntu4
2017-11-14 13:48:30 configure base-files:amd64 9.4ubuntu4 9.4ubuntu4
2017-11-14 13:48:30 status unpacked base-files:amd64 9.4ubuntu4
2017-11-14 13:48:30 status unpacked base-files:amd64 9.4ubuntu4
2017-11-14 13:48:30 status unpacked base-files:amd64 9.4ubuntu4
2017-11-14 13:48:30 status unpacked base-files:amd64 9.4ubuntu4
2017-11-14 13:48:30 status unpacked base-files:amd64 9.4ubuntu4
2017-11-14 13:48:30 status unpacked base-files:amd64 9.4ubuntu4
2017-11-14 13:48:30 status unpacked base-files:amd64 9.4ubuntu4
2017-11-14 13:48:30 status unpacked base-files:amd64 9.4ubuntu4

root@10ffea6140f9:/var/log#

==================================>

WE have seen this container like a Linux machine only.

Now, to come out into Docker use ‘exit’ command.

====================>

root@10ffea6140f9:/var/log#
root@10ffea6140f9:/var/log# exit
exit
vskumar@ubuntu:~$

vskumar@ubuntu:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker-exercise/ubuntu-wgetinstall latest e34304119838 4 hours ago 169MB
<none> <none> fc7e4564eb92 4 hours ago 169MB
hello-world latest f2a91732366c 5 days ago 1.85kB
ubuntu 16.04 20c44cd7596f 8 days ago 123MB
ubuntu latest 20c44cd7596f 8 days ago 123MB
busybox latest 6ad733544a63 3 weeks ago 1.13MB
busybox 1.24 47bcc53f74dc 20 months ago 1.11MB
vskumar@ubuntu:~$

======================>

It means earlier when we run the command ‘$ sudo docker run -it ubuntu bash’ it went into terminal interactive mode of unbuntu container. When we applied ‘exit’ it came out from that container to ‘docker’ . Now through docker we have seen the list of docker images.

So, we have seen from the above session the container usage and the docker images.

Now, let us check the docker services status as below:

$sudo service docker status

vskumar@ubuntu:/var/tmp$ sudo service docker status

================================>

docker.service – Docker Application Container Engine

Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: e

Active: active (running) since Sat 2017-11-25 02:07:54 PST; 25min ago

Docs: https://docs.docker.com

Main PID: 1224 (dockerd)

Tasks: 18

Memory: 255.2M

CPU: 35.334s

CGroup: /system.slice/docker.service

├─1224 /usr/bin/dockerd -H fd://

└─1415 docker-containerd –config /var/run/docker/containerd/containe

================================>

Now, we will stop this session at this point in the next block we will learn how to download public docker image and work with images and containers.

Vcard-Shanthi Kumar V-v3

2. DevOps: How to install Docker 17.03.0 community edition and start working with it on Ubuntu 16.x VM

Docker-logo.png

In this blog, I would like to demonstrate the Docker 17.03.0  CE edition installation on Ubuntu 16.0.4 VM machine. And later on little practice can be shown  using containers in a series of blogs. Please keep visiting for weekly new blogs or subscribe it. If you are interested to follow this site blogs, please send e-mail [with your linkedin message ] to approve with authentication.

Assume you have an unbuntu machine or a Virtual machine [VM] configured. And in this blog you can see on how to install the Docker 17.03.0  CE [as on this blog’s date] with screen display outputs:

$ sudo service docker restart

However, if the Active column shows inactive or maintenance as the status, your Docker service is not running. In such cases, restart the Docker service, as shown here:

$ sudo service docker restart 
 
Install Docker on Unbuntu:

1.Add the Docker package repository path for Ubuntu 16.04 to your APT sources, as shown below:
 $ sudo sh -c "echo deb https://apt.dockerproject.org/repo \
 ubuntu-xenial main > /etc/apt/sources.list.d/docker.list"

2.Add the GNU Privacy Guard (GPG) key by  running the following command:
 $ sudo apt-key adv --keyserver \
 hkp://p80.pool.sks-keyservers.net:80 --recv-keys \ 
 
If the above format is expired; you can try as below:
==== Alternate method with screen output ====>
$sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

Executing: /tmp/apt-key-gpghome.YU0Rk7y5kX/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
gpg: key F76221572C52609D: 7 signatures not checked due to missing keys
gpg: key F76221572C52609D: public key "Docker Release Tool (releasedocker) <docker@docker.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1
=========================================>
The above format should work. Even if that is not working, please google the same keys for the latest validated keys.

3.Resynchronize with the package repository using the below command:
 $ sudo apt-get update
Now docker software is in your unbuntu machine.

4. Now, you can Install Docker and start  Docker service:
 $ sudo apt-get install -y docker-engine

5.Now you have  installed the Docker Engine, we need to  verify our installation by running docker --version as shown below:
 $ docker --version

We have successfully installed Docker version 17.03.0 community edition.
Other options is; in a single script by avoiding the above steps you can install it:

If you are working on Ubuntu, follow the below command:

==================== Screen output ==========>
vskumar@ubuntu:/var/log$ sudo wget -qO- https://get.docker.io/ | sh |more
[sudo] password for vskumar: 
# Executing docker install script, commit: 11aa13e
Warning: the "docker" command appears to already exist on this system.
If you already have  installed Docker, this script can cause trouble, which is
why we're displaying this warning and provide the opportunity to cancel the
installation.
If you installed the current Docker package using this script and are using it
again to update Docker, you can safely ignore this message.
You may press Ctrl+C now to abort this script.
+ sleep 20
+ sudo -E sh -c apt-get update -qq >/dev/null
============== Since I have already installed, I have breaked this process ====>
But, if you try this script; it takes some time to download and install docker for the whole process. 
Be patient to see the final result.  Later check the docker version to reconfirm. Using the below command.
$docker --version

It is very easy to install docker with the above step(s) in your Ubuntu machine.

Assuming you have studied the theory part of docker usage I am moving forward to lab practice.

Now, let us do some practice with docker images/containers.

We will do the below steps:

1. Downloading the first Docker image:
we will download a sample hello-world docker image using the following command:
$ sudo docker pull hello-world

2. Once the image is downloaded, 
they can be verified using the docker images subcommand, as given below:
To check the image run the below command:
$sudo docker run hello-world
It displays the message “Hello from Docker!”
You have set up your first Docker container and it is running now.

3. How to Troubleshoot with Docker containers?:
If you want to troubleshoot with container, the first step is  to check the Docker's running status by using the below command:
$ sudo service docker status 
It displays the status and shows as Docker 'Active running' message on the screen along with other messages.
Press ctrl+C to come out from the display.

=========== Partial content from the above command =====>
vskumar@ubuntu:/var/log$ sudo service docker status 
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2017-11-25 02:54:42 PST; 3h 56min ago
Docs: https://docs.docker.com
Main PID: 3769 (dockerd)
Tasks: 19
Memory: 43.6M
CPU: 1min 21.184s
CGroup: /system.slice/docker.service
├─3769 /usr/bin/dockerd -H fd://
└─3778 docker-containerd --config /var/run/docker/containerd/containerd.toml
===============================>
For some reasons, if the Active column shows inactive or maintenance as the status, it means your Docker service is not running. 
In that case to restart the Docker service, use the below command:

$ sudo service docker restart

We will see in the next blog, some more exercises on Docker containers and images.

Vcard-Shanthi Kumar V-v3