In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
In this article, the editor introduces in detail "how to install Docker service in CentOS7". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to install Docker service in CentOS7" can help you solve your doubts.
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.
Docker is an open source engine that can easily create a lightweight, portable, self-sufficient container for any application. Containers that developers compile and test on notebooks can be deployed in batches in production environments, including vms (virtual machines), 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, through the management of the life cycle of application components, such as packing, distribution, deployment, runtime, etc., to achieve "one package, multiple runs" at the application component level. The application components here can be either a web application, a set of database services, or even an operating system or editor.
1.2.Why use docker?
Docker in the right place, at the right time, conforms to the right trend-to build applications efficiently.
Faster delivery and deployment.
More efficient use of resources
Easier update deployment
Simpler update management
Comparison between docker and virtual machine
The docker container is very fast, and start and stop can be realized in seconds, which is much faster than the traditional virtual machine.
Docker containers require few system resources, and thousands of docker containers can be run on a single host.
Docker makes it easy for users to obtain, distribute and update application images through operations similar to git. The instructions are simple and the learning cost is low.
Docker improves productivity by supporting flexible automated creation and deployment mechanisms through dockerfile configuration files
1.3.Virtualization and docker
Virtualization is a general concept with different understandings in the field of non-communication. In the computer field, it generally refers to computing virtualization (computing virtualization), or server virtualization.
The core of virtualization is to abstract resources, and the goal is often to run multiple operating systems or applications on the same host, so as to improve the utilization of system resources, reduce costs, facilitate 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 is subdivided into the following subcategories:
Completely virtualized. The virtual machine simulates the complete underlying hardware environment and the execution process of privileged instructions, and the guest operating system does not need to modify. Such as vmware workstation,virtulbox,qemu, etc.
Hardware-assisted virtualization. Use hardware-assisted support to process sensitive instructions to achieve full virtualization without any changes to the client operating system, such as xen,kvm, etc.
Partial virtualization. Virtualize only part of the hardware resources, and the client operating system needs to be changed.
Hypervirtualization. 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 isolates different processes by creating multiple virtual operating system instances, docker technology.
Docker installation
Installing docker is an operating system-level virtualization tool that automatically deploys 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; enabled; 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 / usr/bin/docker-current daemon-exec-opt native.cgroupdriver=systemd-selinux-enabled-log-driver=journaldoct 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 26 19 38:39 linuxprobe.org docker-current [3762]: time= "2016-10-26t19:38:39.994708787+08:00" level=info msg= "graph migration to content-addressability took 0.00 seconds" oct 26 19:38:40 linuxprobe.org docker-current [3762]: time= "2016-10-26t19:38:40.018129400+08:00" level=info msg= "firewalld running: true" oct 26 19:38:40 linuxprobe.org docker-current [3762]: time= "2016-10-26t19:38:40.294869786+08:00" level=info Msg= "default bridge (docker0) is assigned with an ip address 172.17.0.0 red ip address 16. Daemon option-- bip can... red ip address" oct 26 19:38:40 linuxprobe.org docker-current [3762]: time= "2016-10-26t19:38:40.567994904+08:00" level=info msg= "loading containers: start." oct 26 19:38:40 linuxprobe.org docker-current [3762]: time= "2016-10-26t19:38:40.568039413+08:00" level=info msg= "loading containers: done." Oct 26 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 26 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.3oct 26 19:38:40 linuxprobe.org docker-current [3762]: time= "2016-10-26t19:38: 40.57249168888 08oct 00 "level=info msg=" api listen on / var/run/docker.sock "oct 26 19:38:40 linuxprobe.org systemd [1]: started docker application container engine.hint: some lines were ellipsized Use-l to show in full.
Download the official image and create a container, and output "welcome to the docker world" in container
[root@linuxprobe ~] # docker pull centosusing default tag: latesttrying to pull repository docker.io/library/centos. Latest: pulling from docker.io/library/centos08d48e6f1cff: pull complete digest: sha256:b2f9d1c0ff5f87a4743104d099a3d561002ac500db1b9bfa02a783a46e0d366cstatus: 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
Connect to the interactive session of container using the "I" and "t" options, as shown below. If you exit from a container session, the process of container is completed
[root@linuxprobe ~] # docker run-I-t centos / bin/bash [root@82699d79557c /] # uname-alinux 82699d79557c 3.10.0-327.el7.x86_64 # 1 smp thu nov 19 22:10:57 utc 2015 x 86 "64 gnu/linux [root@82699d79557c /] # exitexit [root@linuxprobe ~] # back
If you exit from the container session and maintain the container's process, press ctrl + p and ctrl + Q
[root@linuxprobe ~] # docker run-I-t centos / bin/bash [root@a05c7fd0a54f /] # [root@linuxprobe ~] # [root@linuxprobe ~] # docker pscontainer id image command created status ports namesa05c7fd0a54f centos "/ bin/bash" 24 seconds ago up 23 seconds trusting_ [root @ linuxprobe ~] # docker attach a05c7fd0a54f # connect docekr process [root@a05c7fd0a54f /] # [root@linuxprobe ~] # docker kill a05c7fd0a54f # kill docker processa05c7fd0a54f [root@linuxprobe ~] # Docker ps # View the running docker service container id image command created status ports names
Docker: adding mirrors
Add an image file to the container
For example, install httpd with an updated official image and add it as a new image of the container. This container is generated each time the docker run command is executed, so the newly executed container is as follows
[root@linuxprobe ~] # docker imagesrepository tag image id created sizedocker.io/centos latest 0584b3d2cf6d less than a second ago 196.5 mb# start a container and install httpd [root@linuxprobe ~] # docker run centos / bin/bash-c "yum-y update Yum-y install httpd "[root@linuxprobe ~] # docker ps-a | head-2container id image command created status ports namesf36383194ad4 centos" / bin/bash-c 'yum-y "2 minutes ago exited (0) 45 seconds ago jolly_cray elegant_ [root @ linuxprobe ~] # docker commit f36383194ad4 my_image/centos_ httpd [root @ linuxprobe ~] # docker imagesrepository tag image id created sizedocker.io/centos latest 0584b3d2cf6d less than a second Ago 196.5 mbmy_image/centos_httpd latest b0be2940865a 7 seconds ago 338.3 mb
Access Container
Root@linuxprobe ~] # docker run-it-p 8081 my_image/centos_httpd / bin/bash [root@2f0d06526d42 /] # / usr/sbin/httpd & [1] 14 [root@2f0d06526d42 /] # ah00558: httpd: could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'servername' directive globally to suppress this message [1] + done / usr/sbin/httpd [root@2f0d06526d42 /] # echo "httpd on docker container" > / var/www/html/index.html # exit with ctrl+p Ctrl+q [root@2f0d06526d42 /] # [root@linuxprobe ~] # docker pscontainer id image command created status ports names2f0d06526d42 my_image/centos_httpd "/ bin/bash" 54 seconds ago up 52 seconds 0.0.0.0root@linuxprobe 8081-> 80/tcp hopeful_ gates [root @ linuxprobe ~] # docker ps-a | head-2container id image command created status ports names2f0d06526d42 my_image/centos_httpd "/ bin/bash" 27 minutes ago up 27 Minutes 0.0.0.0 8081-> 80/tcp hopeful_gates
Client browser access
Docker: using dockerfile
Use dockerfile and automatically create a docker mirror
[1] the format of dockerfile is [instruction arguments], see the following instructions for instruction.
Instruction description
Maintainer, which sets the author field of the generated image.
Run when creating a docker mirror, it executes any command.
Cmd it will execute any command when the docker container will be executed.
Label it adds metadata to the image.
Expose it informs the docker container that it will listen on the specified network port at run time.
Add it copies new files, directories, or remote files url.
Copy it copies a new file or directory. The difference between [add] is that it is not possible to specify remore url and does not automatically extract archived files.
Volume it creates a mount point with the specified name and marks it as a volume user mounted externally from the native host or other container it sets the user name or uid.
Workdir it sets the working directory.
For example, create a dockerfile to install httpd and add index.html, and start httpd using port 80
[root@linuxprobe ~] # vim dockerfile # create newfrom centosmaintainer linuxprobe run yum-y install httpdrun echo "hello linuxprobe dockerfile" > / var/www/html/index.htmlexpose 80cmd ["- d", "foreground"] entrypoint ["/ usr/sbin/httpd"] [root@linuxprobe ~] # docker build-t web_server:latest. Sending build context to docker daemon 21.5 kbstep 1: from centos-> 0584b3d2cf6dstep 2: maintainer linuxprobe-> running in 8064d0091e44-> 940c8fbe4161removing intermediate container 8064d0091e44step 3: run yum-y install httpd-> running in 3d37e4919fa9loaded plugins: fastestmirror Ovldetermining fastest mirrors * base: mirrors.163.com * extras: ftp.sjtu.edu.cn * updates: mirrors.163.comresolving dependencies-- > running transaction check--- > package httpd.x86_64 0VOV 2.4.6-40.el7.centos.4 will be installed-- > processing dependency: httpd-tools = 2.4.6-40.el7.centos.4 for package: httpd-2.4.6-40.el7.centos.4.x8654 httpd-tools-> processing dependency: system-logos > = 7 .92.1-1 for package: httpd-2.4.6-40.el7.centos.4.x86 centos.64 color-> processing dependency: / etc/mime.types for package: httpd-2.4.6-40.el7.centos.4.x8654 for package-> processing dependency: libaprutil-1.so.0 () (64bit) for package: httpd-2.4.6-40.el7.centos.4.x86 centos.4.x86 conversation 64-> processing dependency: libapr-1.so.0 () (64bit ) for package: httpd-2.4.6-40.el7.centos.4.x8654 3.el7.centos will be installed----> running transaction check--- > package apr.x86_64 0pur1.4.8-3.el7 will be installed--- > package apr-util.x86_64 0pur1.5.2-6.el7 will be installed--- > package centos-logos.noarch 0pur70.0.6-3.el7.centos will be installed--- > package httpd-tools.x86_64 0:2 .4.6-40.el7.centos.4 will be installed--- > package mailcap.noarch 0vir 2.1.41-2.el7 will be installed-- > finished dependency resolutiondependencies resolved==== package arch version repository size====installing: httpd x86 "64 2.4.6-40.el7.centos.4 updates 2.7 minstalling for dependencies: apr x86" 64 1.4.8-3.el7 base 103k apr-util x86 "64 1.5.2-6.el7 base 92k centos-logos noarch 70.0.6-3.el7.centos base 21m httpd-tools x861564 2.4.6-40.el7.centos.4 updates 83 k mailcap noarch 2.1.41-2.el7 base 31 ktransaction summary====install 1 package (+ 5 dependent packages) total download size: 24 minstalled size: 31 mdownloading 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: nokeypublic key for apr-util-1.5.2-6.el7.x86_64.rpm is not installedpublic key for httpd-tools-2.4.6-40.el7.centos.4.x86_64.rpm is not installed -total 382 kb/s | 24 mb 01:05 retrieving key from file:///etc/pki/rpm-gpg/rpm-gpg-key-centos-7importing gpg key 0xf4a80eb5: userid: "centos-7 key (centos 7 official signing key)" fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a80eb5 package: centos-release-7-2.1511.el7.centos.2.10.x86_64 (@ centos) from : / etc/pki/rpm-gpg/rpm-gpg-key-centos-7running transaction checkrunning transaction testtransaction test succeededrunning transaction installing: apr-1.4.8-3.el7.x86_64 1 installing 6 installing: apr-util-1.5.2-6.el7.x86_64 2 httpd-tools-2.4.6 6 installing: httpd-tools-2.4.6-40.el7.centos.4.x86_64 3 installing: centos-logos-70.0.6-3. El7.centos.noarch 4 3.el7.x86_64 6 installing: mailcap-2.1.41-2.el7.noarch 5 3.el7.x86_64 6 installing: httpd-2.4.6-40.el7.centos.4.x86_64 6 verifying: apr-1.4.8-3.el7.x86_64 1 3.el7.x86_64 6 verifying: httpd-tools-2.4.6-40.el7.centos.4.x86_64 2 verifying: apr-util-1.5 .2-6.el7.x86_64 33.el7.centos.noarch 6 verifying: httpd-2.4.6-40.el7.centos.4.x86_64 4 verifying 6 verifying: mailcap-2.1.41-2.el7.noarch 5 verifying: centos-logos-70.0.6-3.el7.centos.noarch 6 verifying: centos-logos-70.0.6-3.el7.centos.noarch 6 3.el7.centos.noarch 6 installed: httpd.x86_64 0 Switzerland 2.4.6-40.el7.centos.4 dependency installed: Apr.x86_64 0VOR 1.4.8-3.el7 apr-util.x86_64 0VOR 1.5.2-6.el7 centos-logos.noarch 0RU 70.0.6-3.el7.centos httpd-tools.x86_64 0VOR 2.4.6-40.el7.centos.4 mailcap.noarch 0VOR 2.1.41-2.el7 complete!- -- > 3ce9abf4dfearemoving intermediate container 3d37e4919fa9step 4: run echo "hello linuxprobe dockerfile" > / var/www/html/index.html-- > running in 297d8d666c8d-- > 3d185363045bremoving intermediate container 297d8d666c8dstep 5: expose 80-- > running in 017db517e06a-- > 5c855e478c3cremoving intermediate container 017db517e06astep 6: cmd-d foreground-- > running in 6add13fca3cb-> 7a219d9fa6e1removing intermediate container 6add13fca3cbstep 7: entrypoint / usr/sbin/httpd-- > running in da4671709ee1-> c0d84e256068removing intermediate container da4671709ee1successfully built c0d84e256068 [root@linuxprobe] # docker imagesrepository tag Image id created sizedocker.io/centos latest 0584b3d2cf6d less than a second ago 196.5 mbweb_server latest c0d84e256068 36 seconds ago 338.3 mbmy_image/centos_httpd latest b0be2940865a 4 hours ago 338.3 mb [root@linuxprobe ~] # docker run-d-p 80:80 web_server c37d25a405a8e0599bf54fe77d78c807a520242a21ccb15b18d6b6ee4d13415b [root@linuxprobe ~] # docker pscontainer id image command created status ports namesc37d25a405a8 web_server "/ usr/sbin/httpd-d f" 6 seconds ago up 5 Seconds 0.0.0.0 bin/bash 80-> 80/tcp condescending_knuth2f0d06526d42 my_image/centos_httpd "/ bin/bash" 8081-> 80/tcp hopeful_gat read here This article "how to install CentOS7 Docker service" has been introduced. If you want to grasp the knowledge of this article, you still need to practice and use it. If you want to know more about the article, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.