You are on page 1of 7

Process to create a docker container

1. Create a Dockerfile and add instructions

2. Using the Docker file create an image OR pull the image directly from the docker registry

3. Using the image create a docker container


Install Docker
# yum -y install docker
Complete!
Docker daemon may not start right away so you will see the following
# docker version
Client:
Version: 1.13.1
API version: 1.26
Package version:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Check the status as follows


# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: http://docs.docker.com

If the daemon is not running then start it as follows

# systemctl start docker


# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Sat 2020-02-15 14:33:42 PST; 11s ago
Docs: http://docs.docker.com

Check the docker version now


# docker version
Client:
Version: 1.13.1
API version: 1.26
Package version: docker-1.13.1-108.git4ef4b30.el7.centos.x86_64
Go version: go1.10.3
Git commit: 4ef4b30/1.13.1
Built: Tue Jan 21 17:16:25 2020
OS/Arch: linux/amd64

Server:
Version: 1.13.1
API version: 1.26 (minimum version 1.12)
Package version: docker-1.13.1-108.git4ef4b30.el7.centos.x86_64
Go version: go1.10.3
Git commit: 4ef4b30/1.13.1
Built: Tue Jan 21 17:16:25 2020
OS/Arch: linux/amd64
Experimental: false
Two different ways to create a docker container. How to create a container Option #1

Create a “Dockerfile” to start creating an image

# mkdir dock
# cd dock
#vi Dockerfile
FROM debian
RUN mkdir -p /opt/libeatmydata
ADD zip.txt /opt/libeatmydata/
RUN ls -lRt /opt/libeatmydata

Create an image using the Dockerfile with the instructions

# docker build -t hello1 . [In this command you are building an image with the name of “hello1”]

Sending build context to Docker daemon 15.87kB


Step 1/4 : FROM debian
---> a8797652cfd9
Step 2/4 : RUN mkdir -p /opt/libeatmydata
---> Using cache
---> 7138de4beed1
Step 3/4 : ADD zip.txt /opt/libeatmydata/
---> 3e5d42531840
Step 4/4 : RUN ls -lRt /opt/libeatmydata
---> Running in 28acee1e230c
/opt/libeatmydata:
total 0
-rw-r--r-- 1 root root 0 Feb 15 23:41 zip.txt
Removing intermediate container 28acee1e230c
---> fc3a3a910eab
Successfully built fc3a3a910eab
Successfully tagged hello1:latest

Check if the image has been created as follows

# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE


hello1 latest fc3a3a910eab 2 minutes ago 114MB

Create a docker container with the following command

# docker run hello1 [This command will finish the task in two secs but it will show you the container id]

a001a8a9c90ffb41e9e7387d197893f56bf26b4c7ed7b57068a1a7cf88355096

#
How to create a container Option #2
# docker pull hello-world [You are pulling an image from the docker registry called “hello-world”]

Using default tag: latest


Trying to pull repository docker.io/library/hello-world ...
latest: Pulling from docker.io/library/hello-world
1b930d010525: Pull complete
Digest: sha256:9572f7cdcee8591948c2963463447a53466950b3fc15a247fcad1917ca215a2f
Status: Downloaded newer image for docker.io/hello-world:latest

Check if the image has been downloaded as follows

# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE


hello1 latest fc3a3a910eab 2 minutes ago 114MB
docker.io/hello-world latest fce289e99eb9 13 months ago 1.84 kB

Create a container as follows

# docker run hello-world

Hello from Docker!


This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:


1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:


https://docs.docker.com/get-started/
Create a container using option #2

Run the following command

# docker run -it ubuntu bash [This command pulls an image from the docker registry and creates a running container]

Unable to find image 'ubuntu:latest' locally


Trying to pull repository docker.io/library/ubuntu ...
latest: Pulling from docker.io/library/ubuntu
5c939e3a4d10: Pull complete
c63719cdbe7a: Pull complete
19a861ea6baf: Pull complete
651c9d2d6c4f: Pull complete
Digest: sha256:8d31dad0c58f552e890d68bbfb735588b6b820a46e459672d96e585871acc110
Status: Downloaded newer image for docker.io/ubuntu:latest
root@b0f7a6eba968:/# [You are inside Ubuntu - try commands: ll, ls, ]
root@b0f7a6eba968:/# exit [After you are done testing you can type exit]

How many images have we created?

# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE


hello1 latest fc3a3a910eab 2 minutes ago 114MB
docker.io/ubuntu latest ccc6e87d482b 4 weeks ago 64.2 MB
docker.io/hello-world latest fce289e99eb9 13 months ago 1.84 kB

Why there is no containers running? Docker containers can run execute a task and terminate
# docker container ls

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

[root@nfs home]# docker run hello1 [Works for two seconds then stops]
a001a8a9c90ffb41e9e7387d197893f56bf26b4c7ed7b57068a1a7cf88355096 [This is the container id]
[root@nfs home]#

Other containers can run and keep running as daemons, the same way as we have them in Transformation Hub

# docker run -it ubuntu bash


Open another tab and run the command “docker container ls”. Now we can see a container running.

# docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a85c81c3859e ubuntu "bash" 15 seconds ago Up 14 seconds dazzling_jang
How do these concepts and commands apply/work on Transformation Hub?

Check the number of images in master and worker nodes of the Transformation Hub Installation. The number of images
between master and worker nodes should be different. The initial master works as the private docker registry and
worker nodes contain the images of the containers running in that node.

Remember: The scheduler assigns the containers to every node. The kubelet in every node constantly checks for pods
assigned to the node and signals the docker daemon to pull the images when the scheduler has assigned those images
to the node. The docker daemon starts and runs the containers.

# docker images [Checking the images on a master node]

# docker images [checking the images on a worker node]


Troubleshooting commands

There are several commands you can use as part of your troubleshooting session. But keep in mind that most of the
time the issue may not be inside a container, but with ports, daemons/services not running, etc. and you have to use
other commands to find the problem

# docker stats

# docker container ls

# docker logs containerid

Note: You can type “# docker” for additional commands you can try.

Note: You can also see the pods and their information by executing the following commands.

# kubectl get pods --all-namespaces -o wide

# kubectl describe pod itom-k8s-dashboard-86ccd46b6c-49b4x -n core [In this case you will see 2 Container IDs]

You might also like