Docker Install for centos 7

Install Docker which is the Operating System-Level Virtualization Tool, which automates the deployment of applications inside Containers.

[1] Install Docker.

1
2
3
4
[[email protected] ~]#  yum -y install docker

[[email protected] ~]# systemctl start docker
[[email protected] ~]# systemctl enable docker

[2] Download the official image and create a Container and output the words “Welcome to the Docker World” inside the Container.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# download a centos image
[[email protected] ~]# docker pull centos
Using default tag: latest
Trying to pull repository docker.io/library/centos ...
latest: Pulling from docker.io/library/centos
3d8673bd162a: Pulling fs layer
.....
.....
3d8673bd162a: Pull complete
Digest: sha256:a66ffcb73930584413de83311ca11a4cb4938c9b2521d331026dad970c19adf4
Status: Downloaded newer image for docker.io/centos:latest

# show images
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/centos latest 970633036444 2 weeks ago 196.7 MB

# run echo inside Container
[[email protected] ~]# docker run centos /bin/echo "Welcome to the Docker World"
WARNING: IPv4 forwarding is disabled. Networking will not work.
Welcome to the Docker World

[3] Connect to the interactive session of a Container with “i” and “t” option like follows. If exit from the Container session, the process of a Container finishes.

1
2
3
4
5
6
7
8
9
10
[[email protected] ~]# docker run -i -t centos /bin/bash 
[[email protected] /]# # Container's console

[[email protected] /]# uname -a
Linux 97e4ec079410 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

[[email protected] /]# exit
exit

[[email protected] ~]# # success run docker images

[4] If exit from the Container session with keeping container’s process, push Ctrl+p, and Ctrl+q key

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[[email protected] ~]# docker run -i -t centos /bin/bash 
[[email protected] /]#

# Ctrl+p, Ctrl+q key to back to Host's console
[[email protected] /]# [[email protected] ~]#


# show docker last run container process
[[email protected] ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dedab2202eb5 centos "/bin/bash" About a minute ago Up About a minute fervent_rosalind


# connect to container's session
[[email protected] ~]# docker attach dedab2202eb5
[[email protected] /]# # connected success


# shutdown container's process from Host's console

[[email protected] ~]# docker kill dedab2202eb5

[[email protected] ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES