CentOS 7 Installation Docker Service detail process _docker

Source: Internet
Author: User
Tags file url gpg centos docker ps fully qualified domain name docker run


Docker Introduction



Docker is an open source application container engine that allows developers to package their apps and dependencies into a portable container, and then publish it to any popular Linux machine or virtualization. Containers are completely using the sandbox mechanism, and there will be no interface between each other.
Docker official website :http://www.docker.com/
Docker Official Document: https://docs.docker.com/
Docker Github Address: Https://github.com/docker/docker
Docker Warehouse: https://hub.docker.com/
Docker Chinese Community: Http://www.docker.org.cn/book/docker
Docker Application Scenario: https://www.zhihu.com/question/22969309






1.1, what is Docker?



Docker is a cloud open source project based on the Go language, which was born in early 2013 and was originally initiated by DotCloud Corporation.
Docker is an open-source engine that can easily create a lightweight, portable, self-contained container for any application. Developers compiling tests on notebooks can be deployed in bulk in a production environment, including VMS, bare metal, OpenStack clusters, and other basic application platforms.
Docker Chinese Community
The main goal of Docker is ' build,ship and Run any App Anywhere ', that is, by encapsulating the application components (packing), distributing (distribution), deploying (Deployment), Operation (Runtime), such as the management of life cycle, to apply the component level of "one encapsulation, multiple runs." The application component here can be either a Web application or a set of database services, or even an operating system or editor.



1.2. Why to use Docker?



Docker in the right place, the right time to adapt to the right trends-that is, efficient construction of applications.



Faster delivery and deployment.



More efficient use of resources



Easier deployment of updates



Simpler update Management



Comparison of Docker and virtual machines



Docker containers very quickly, start and stop can be implemented in seconds, compared to the traditional virtual machine way much faster
Docker containers have little demand for system resources, and a single host can run thousands of Docker containers
Docker through a git-like operation to facilitate user access, distribution, and updating of application mirroring, simple instruction, low learning cost
Docker through Dockerfile configuration files to support flexible automated creation and deployment mechanisms to improve productivity



1.3, Virtualization and Docker



Virtualization is a common concept and has different understandings in the field of communication. In the domain of computers, it is generally referred to as computational virtualization (Computing Virtualization) or server virtualization.



The core of virtualization is the abstraction of resources, which is often aimed at running multiple operating systems or applications on the same host, thus increasing the utilization of system resources while bringing about cost reduction, ease of management and fault tolerance.



Virtualization can be divided into hardware-based virtualization and software-based virtualization. Software based virtualization is divided into application virtualization and platform virtualization. Platform virtualization also subdivides the following subclasses:



full virtualization. the virtual machine simulates the execution of the complete underlying hardware environment and privileged instructions, and the client operating system does not need to be modified. such as VMware WORKSTATION,VIRTULBOX,QEMU, etc.
Hardware-assisted virtualization. the ability to use hardware-assisted support to handle sensitive directives for full virtualization requires no changes to the client operating system, such as XEN,KVM
part of virtualization. virtualization is only for some hardware resources and the client operating system needs to be changed.
Hyper-Virtualization. Some hardware interfaces are provided to the client operating system in the form of software, and the client operating system needs to be changed.
operating system-level virtualization. the kernel Docker technology by creating multiple virtual operating system instances to isolate different processes.



Docker installation



Installation Docker is an operating system-level virtualization tool that automates the deployment of applications in containers
Install Docker



[root@linuxprobe~]# yum-y Install Docker [root@linuxprobe~]# systemctl start Docker [root@linuxprobe~]# Systemctl Enable
 Docker [Root@linuxprobe ~]# systemctl Status Docker # View Docker status Docker.service-docker application Container Engine  Loaded:
loaded (/usr/lib/systemd/system/docker.service; vendor preset:disabled) active:active (running) since Wed 2016-10-26 19:38:40 CST; 
12s ago docs:http://docs.docker.com Main pid:3762 (docker-current) Cgroup:/system.slice/docker.service└─3762/u Sr/bin/docker-current 
Daemon--exec-opt native.cgroupdriver=systemd--selinux-enabled--log-driver=journald Oct 26 19:38:39 linuxprobe.org docker-current[3762]: time= "2016-10-26t19:38:39.844803185+08:00" 
Level=info msg= "Devmapper: Successfully created filesystem XFS on device docker-253:0-104354176-base "Oct 19:38:39 linuxprobe.org 3762]: time= "2016-10-26t19:38:39.994708787+08:00" 
Level=info msg= "Graph migration to Content-addressability took 0.00 Seconds "OcT-19:38:40 linuxprobe.org docker-current[3762]: time= "2016-10-26t19:38:40.018129400+08:00"
 Level=info msg= " Firewalld running:true "Oct 19:38:40 linuxprobe.org docker-current[3762]:
 time=" 2016-10-26t19:38:40.294869786+ 08:00 "Level=info msg=" the Default Bridge (DOCKER0) are assigned with a IP address 172.17.0.0/16. Daemon option--bip can ... red IP address "Oct 19:38:40 linuxprobe.org docker-current[3762]: time=" 2016-10-26t19:38:40.
567994904+08:00 "Level=info msg=" Loading containers:start. " OCT 19:38:40 linuxprobe.org docker-current[3762]: time= "2016-10-26t19:38:40.568039413+08:00" Level=info msg= "
Loading Containers:done. " OCT 19:38:40 linuxprobe.org docker-current[3762]: time= "2016-10-26t19:38:40.568047306+08:00" Level=info msg= " 
Daemon has completed initialization "OCT 19:38:40 linuxprobe.org docker-current[3762]: time=" 2016-10-26t19 : 38:40.568058527+08:00 "Level=info msg="
 Docker daemon "commit=cb079f6-unsupported execdriver=native-0.2 graphdriver= Devicemapper 
Version=1.10.3 Oct 19:38:40 linuxprobe.org docker-current[3762]: 
time= "2016-10-26t19:38:40.572491688+08:00" Level=info msg= " API Listen On/var/run/docker.sock "Oct 19:38:40 linuxprobe.org systemd[1]: Started Docker application Container Engine
.

 Hint:some lines were ellipsized, use-l.



Download the official image and create a container and output "Welcome to the Docker world" in container


[Root@linuxprobe ~]# Docker pull CentOS
Using default tag:latest
trying to pull repository Tos ... 
Latest:pulling from Docker.io/library/centos
08d48e6f1cff:pull complete 
digest:sha256: b2f9d1c0ff5f87a4743104d099a3d561002ac500db1b9bfa02a783a46e0d366c
status:downloaded Newer image for docker.io/  Centos:latest
[Root@linuxprobe ~]# Docker run Centos/bin/echo ' Welcome to the ' Docker world ' Welcome to the Docker
World


Use the "I" and "T" options to connect to the container interactive session, as shown below. If you exit from the container session, the container process completes


[Root@linuxprobe ~]# Docker run-i-t Centos/bin/bash
[root@82699d79557c/]# uname-a Linux 82699d79557c 3.10.0
-327.el7.x86_64 #1 SMP Thu Nov 22:10:57 UTC 2015 x86_64 x86_64 x86_64 gnu/linux
[root@82699d79557c/]# exit
E XIT
[Root@linuxprobe ~]# #back


If you exit from a container session and hold the container's process, press CTRL + P and CTRL + Q keys


[Root@linuxprobe ~]# Docker run-i-t Centos/bin/bash
[root@a05c7fd0a54f/]# [Root@linuxprobe ~]# [ 
Root@linuxprobe ~]# Docker PS
CONTAINER ID  IMAGE    COMMAND    CREATED    STATUS    PORTS    NAMES
a05c7fd0a54f  centos    "/bin/bash"   seconds ago up  seconds       Trusting_fermat
[ Root@linuxprobe ~]# Docker Attach a05c7fd0a54f # connect DOCEKR process
[root@a05c7fd0a54f/]# [Root@linuxprobe ~]# D Ocker kill a05c7fd0a54f # Kill Docker Process
a05c7fd0a54f
[Root@linuxprobe ~]# Docker PS # view running Docker Services
CONTAINER ID  IMAGE    COMMAND    CREATED    STATUS    PORTS    NAMES


Docker: Adding mirrors



To add a mirrored file to a container
For example, install httpd with an updated official image and add it as a new image for the container. The container is generated each time the Docker Run command is executed, so add the most recently executed container as follows


[Root@linuxprobe ~]# Docker images
REPOSITORY    TAG     IMAGE ID   CREATED     SIZE
Docker.io/centos  latest    0584b3d2cf6d  less than a second ago 196.5 MB
# Start a Container and install httpd
[Root@lin Uxprobe ~]# Docker Run centos/bin/bash-c "yum-y update; Yum-y install httpd "
[root@linuxprobe ~]# docker ps-a | head-2
CONTAINER ID  IMAGE    COMMAND     CRE ated    STATUS      PORTS    NAMES
f36383194ad4  centos    "/bin/bash-c ' yum-y" 2 minutes ago  Exited (0) seconds ago       jolly_cray
      elegant_wright
[root@linuxprobe ~]# Docker commit f36383194ad4 My_ IMAGE/CENTOS_HTTPD
[Root@linuxprobe ~]# docker images
REPOSITORY    TAG     IMAGE ID   CREATED       SIZE
docker.io/centos  latest    0584b3d2cf6d  less than a second ago 196.5 MB
my_image/ CENTOS_HTTPD Latest   b0be2940865a  7 seconds ago    338.3 MB


Access container




client browser access






Docker: Using Dockerfile



Using Dockerfile and automatically creating Docker mirrors
[1] The format of dockerfile is [instruction arguments], see the following instructions for instruction.
Instruction description
Maintainer It sets the author field of the generated image.
Run When you create a Docker mirror, it executes any commands.
CMD It will execute any command when the Docker container will be executed.
LABEL that adds metadata to the image.
expose It notifies the Docker that the container will listen for the specified network port at run time.
ADD it to copy the new file, directory or remote file URL.
Copy it to duplicate the new file or directory. The difference between [ADD] is that it is not possible to specify the Remore URL or to automatically extract the archive.
VOLUME It creates a mount point with the specified name and marks it as saving externally mounted volume user from a native host or other container it sets the user name or UID.
Workdir it to set the working directory.



For example, create a dockerfile to install httpd and add index.html, and start with 80 ports httpd


[Root@linuxprobe ~]# vim Dockerfile # Create New from CentOS maintainer linuxprobe <admin@linuxprobe.org> 
RUN Yum -y install httpd RUN echo "Hello linuxprobe dockerfile" >/var/www/html/index.html expose-CMD ["D", "foreground"] E 
Ntrypoint ["/usr/sbin/httpd"] [root@linuxprobe ~]# Docker build-t. Sending build context to Docker daemon 21.5 kB step 1:
from CentOS---> 0584b3d2cf6d step 2:maintainer linuxprobe & Lt;admin@linuxprobe.org>---> Running in 8064d0091e44---> 
940c8fbe4161 removing Intermediate container 8064d00 91e44 Step 3:run yum-y Install httpd---> Running in 3d37e4919fa9 Loaded plugins:fastestmirror,
 OVL determining FA Stest Mirrors * base:mirrors.163.com * extras:ftp.sjtu.edu.cn * updates:mirrors.163.com resolving ;
 Running transaction Check---> Package httpd.x86_64 0:2.4.6-40.el7.centos.4 won't be installed-->
 processing Depende Ncy:httpd-tools = 2.4.6-40.el7.centos.4 for package:httpd-2.4.6-40.el7.centos.4.x86_64--> 
processing Dependency:system-logos >= 7.92.1-1 for package: httpd-2.4.6-40.el7.centos.4.x86_64-->
 processing Dependency:/etc/mime.types for package: httpd-2.4.6-40.el7.centos.4.x86_64--> 
Processing dependency:libaprutil-1.so.0 () (64bit) for package: httpd-2.4.6-40.el7.centos.4.x86_64-->
 Processing dependency:libapr-1.so.0 () (64bit) for package: httpd-2.4.6-40.el7.centos.4.x86_64--> Running Transaction Check---> 
Package apr.x86_64 0:1.4.8-3.el7 would be inst alled---> Package apr-util.x86_64 0:1.5.2-6.el7 would be installed--->
 Package centos-logos.noarch. CentOS would be installed---> Package httpd-tools.x86_64 0:2.4.6-40.el7.centos.4 would be installed--->
 Package mail Cap.noarch 0:2.1.41-2.el7 'll be installed--> finished Dependency resolution dependencies resolved ================ ================================================================ 
Package Arch Version Repository Size
================================================================================ installing:httpd x86_64    2.4.6-40.el7.centos.4 Updates 2.7 M installing for DEPENDENCIES:APR x86_64 1.4.8-3.el7 base-K Apr-util x86_64 1.5.2-6.EL7 Base Centos-logos noarch 70.0.6-3.el7.centos 
base M httpd-tools x86_64 2.4. 6-40.el7.centos.4 updates k mailcap Noarch 2.1.41-2.el7 base to K Transaction Summary ============================================================= Install 1 Package (+5 Dependent packages) Total download size:24 m installed size:31 m downloading packages:warning:/var/cache/yum/x86_64/7/base/packages/ Apr-util-1.5.2-6.el7.x86_64.rpm:header V3 rsa/sha256 Signature,
 key ID F4a80eb5:nokey public key for Apr-util-1.5.2-6.el 7.X86_64.RPM is isn't installed public key for httpd-tools-2.4.6-40.el7.centos.4.x86_64.rpm are not installed-------------- ------------------------------------------------------------------
Total 382 kb/s | MB 01:05 retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 importing GPG key 0xf4a80eb5:userid: "C EntOS-7 Key (CentOS 7 official signing Key)
 <security@centos.org> "fingerprint:6341 ab27 53d7 8a78 a7c2 7bb1 24c6 A8a7 f4a8 0eb5 package:centos-release-7-2.1511.el7.centos.2.10.x86_64 (@CentOS) from:/etc/pki/rpm-gpg/rpm-gpg-key-c EntOS-7 Running Transaction Check Running Transaction Test transaction test succeeded Running transaction Installing:ap r-1.4.8-3.el7.x86_64 1/6 installing:apr-util-1.5.2-6.el7.x86_64 2/6 installing:
httpd-tools-2.4.6- 40.el7.centos.4.x86_64 3/6 installing:centos-logos-70.0.6-3.el7.centos.noarch 4/6 installing:
mailcap-2.1 .41-2.el7.noarch 5/6 installing:httpd-2.4.6-40.el7.centos.4.x86_64 6/6 verifying:apr-1.4.8-3.el7.x86 _64 1/6 verifying:httpd-tools-2.4.6-40.el7.centos.4.x86_64 2/6 verifying:apr-util-1.5.2-6.el7.x86_64 3/6 verifying:httpd-2.4.6-40.el7.centos.4.x86_64 4/6 verifying:mailcap-2.1.41-2.el7.no Arch 5/6 verifying:centos-logos-70.0.6-3.el7.centos.noarch 6/6 Installed:httpd.x86_64 0:2.4.6-40.el7.             
 Centos.4 Dependency Installed:apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7 Centos-logos.noarch 0:70.0.6-3.el7.centos httpd-tools.x86_64 0:2.4.6-40.el7.centos.4 mailcap.no
 Arch 0:2.1.41-2.el7 complete! ---> 3ce9abf4dfea removing Intermediate container 3d37e4919fa9 step 4:run echo "Hello linuxprobe dockerfile" >/va
r/www/html/index.html---> Running in 297d8d666c8d---> 3d185363045b removing Intermediate container 297d8d666c8d Step 5:expose---> Running in 017db517e06a---> 5c855e478c3c removing intermediate container 017db517e06a P 6:cmd-d Foreground---> Running in 6ADD13FCA3CB---> 7a219d9fa6e1 removing IntermediateContainer 6ADD13FCA3CB Step 7:entrypoint/usr/sbin/httpd---> Running in da4671709ee1---> c0d84e256068 removing  \
   Intermediate container da4671709ee1 successfully built c0d84e256068 [Root@linuxprobe ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/centos latest 0584b3d2cf6d 
less than a second ago 196.5 MB web_server LA Test c0d84e256068 seconds ago 338.3 MB MY_IMAGE/CENTOS_HTTPD latest b0be2940865a 4 hours ago 338.3 MB [Roo T@linuxprobe ~]
# Docker run-d-P 80:80 web_server c37d25a405a8e0599bf54fe77d78c807a520242a21ccb15b18d6b6ee4d13415b [ ~]
# Docker PS CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c37d25a405a8 web_s root@linuxprobe Erver "/usr/sbin/httpd-d F" 6 seconds ago up 5 seconds 0.0.0.0:80->80/tcp Condescending_knuth 2f0d06526d42 my_i

 MAGE/CENTOS_HTTPD "/bin/bash" about a hour ago up about a hour 0.0.0.0:8081->80/tcp Hopeful_gat



 



The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.