如何在centos 7上安装docker
Docker是一个开源项目,可以自动在软件容器内部署应用程序。该容器允许开发人员打包所有项目资源,例如库,依赖项,资产等。Docker用Go编程语言编写,由Dotcloud开发。它基本上是一个容器引擎,使用诸如命名空间和控制组之类的Linux内核功能在操作系统之上创建容器,并自动在容器上部署应用程序。
安装Docker
在CentOS上安装Docker之前,需要更新CentOS软件包。要更新软件包,请使用以下命令-
# yum -y update
样本输出应如下所示–
Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: ftp.iitm.ac.in * elrepo: mirrors.ircam.fr * epel: mirror01.idc.hinet.net * extras: ftp.iitm.ac.in * updates: ftp.iitm.ac.in Resolving Dependencies --> Running transaction check ---> Package autocorr-en.noarch 1:4.3.7.2-5.el7 will be updated ---> Package autocorr-en.noarch 1:4.3.7.2-5.el7_2.1 will be an update ---> Package avahi.x86_64 0:0.6.31-15.el7 will be updated ---> Package avahi.x86_64 0:0.6.31-15.el7_2.1 will be an update ---> Package avahi-autoipd.x86_64 0:0.6.31-15.el7 will be updated ---> Package avahi-autoipd.x86_64 0:0.6.31-15.el7_2.1 will be an update ............
要安装Docker,请使用以下命令–
# yum -y install docker docker-registry
样本输出应如下所示–
Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: ftp.iitm.ac.in * elrepo: mirrors.ircam.fr * epel: epel.mirror.net.in * extras: ftp.iitm.ac.in * updates: ftp.iitm.ac.in Resolving Dependencies --> Running transaction check ---> Package docker.x86_64 0:1.8.2-10.el7.centos will be installed --> Processing Dependency: docker-selinux >= 1.8.2-10.el7.centos for package: docker-1.8.2-10.el7.centos.x86_64 ---> Package docker-registry.x86_64 0:0.9.1-7.el7 will be installed --> Processing Dependency: python-sqlalchemy >= 0.9.8-1 for package: docker-registry-0.9.1-7.el7.x86_64 --> Processing Dependency: python-backports-lzma >= 0.0.2-8 for package: docker-registry-0.9.1-7.el7.x86_64 --> Processing Dependency: python-requests for package: docker-registry-0.9.1-7.el7.x86_64 --> Processing Dependency: python-gunicorn for package: docker-registry-0.9.1-7.el7.x86_64 --> Processing Dependency: python-gevent for package: docker-registry-0.9.1-7.el7.x86_64 --> Processing Dependency: python-flask for package: docker-registry-0.9.1-7.el7.x86_64 --> Processing Dependency: python-blinker for package: docker-registry-0.9.1-7.el7.x86_64 --> Processing Dependency: m2crypto for package: docker-registry-0.9.1-7.el7.x86_64 --> Processing Dependency: PyYAML for package: docker-registry-0.9.1-7.el7.x86_64 .......
启动Docker
要在启动时启动Docker,请使用以下命令–
# systemctl enable docker.service
样本输出应如下所示–
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
要启动Docker,请使用以下命令–
# systemctl start docker.service
要查找docker的状态,请使用以下命令–
# systemctl status docker.service
样本输出应如下所示–
docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2016-02-29 16:01:24 IST; 1min 18s ago Docs: http://docs.docker.comMain PID: 27398 (docker) CGroup: /system.slice/docker.service └─27398 /usr/bin/docker daemon --selinux-enabled Feb 29 16:00:56 linux docker[27398]: time="2016-02-29T16:00:56.139817103+05...e" Feb 29 16:01:22 linux docker[27398]: time="2016-02-29T16:01:22.314033208+05...e" Feb 29 16:01:22 linux docker[27398]: time="2016-02-29T16:01:22.314422184+05...e" Feb 29 16:01:22 linux docker[27398]: time="2016-02-29T16:01:22.401448064+05...1" Feb 29 16:01:22 linux docker[27398]: time="2016-02-29T16:01:22.647321427+05...e" Feb 29 16:01:24 linux docker[27398]: time="2016-02-29T16:01:24.713353670+05...." Feb 29 16:01:24 linux docker[27398]: time="2016-02-29T16:01:24.716886255+05...." Feb 29 16:01:24 linux docker[27398]: time="2016-02-29T16:01:24.716900165+05...n" Feb 29 16:01:24 linux docker[27398]: time="2016-02-29T16:01:24.716913621+05...os Feb 29 16:01:24 linux systemd[1]: Started Docker Application Container Engine. Hint: Some lines were ellipsized, use -l to show in full. .........
下载适用于CentOS的Docker容器
要下载Docker容器,请使用以下命令–
# docker pull centos
样本输出应如下所示–
Using default tag: latest Trying to pull repository docker.io/library/centos ... latest: Pulling from library/centos 47d44cb6f252: Pull complete f5079557f135: Pull complete 42c2aa730369: Pull complete 0e0217391d41: Pull complete library/centos:latest: The image you are pulling has been verified. Important: image verification is a tech preview feature and should not be relied on to provide security. Digest: sha256:1272ae53bac7bf054dd209a0b4a8629bcc39526c2a767427c7639b630a224a9e Status: Downloaded newer image for docker.io/centos:latest .................
运行Docker容器
要运行docker,它需要一个带有bashshell的基本CentOS容器。要运行Docker,请使用以下命令–
# docker run -i -t centos /bin/bash
上面的命令将用户输入到centOSdocker容器内的bashshell中。要退出Docker,请使用Ctrl+p或Ctrl+q 快捷键。通过搜索可以找到许多已经包含在Docker容器中的社区。
例如,要搜索CentOS社区,请使用以下命令–
# docker search centos
样本输出应如下所示–
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED docker.io docker.io/centos The official build of CentOS. 1965 [OK] docker.io docker.io/jdeathe/centos-ssh CentOS-6 6.7 x86_64 / CentOS-7 7.2.1511 x8... 15 [OK] docker.io docker.io/million12/centos-supervisor Base CentOS-7 with supervisord launcher, h... 9 [OK] docker.io docker.io/blalor/centos Bare-bones base CentOS 6.5 image 8 [OK] docker.io docker.io/nimmis/java-centos This is docker images of CentOS 7 with dif... 7 [OK] docker.io docker.io/torusware/speedus-centos Always updated official CentOS docker imag... 7 [OK] docker.io docker.io/centos/mariadb55-centos7 3 [OK] docker.io docker.io/nathonfowlie/centos-jre Latest CentOS image with the JRE pre-insta... 3 [OK] docker.io docker.io/nickistre/centos-lamp LAMP on centos setup 3 [OK] docker.io docker.io/consol/sakuli-centos-xfce Sakuli end-2-end testing and monitoring co... 2 [OK] docker.io docker.io/darksheer/centos Base Centos Image -- Updated hourly 1 [OK] docker.io docker.io/layerworx/centos CentOS container with etcd, etcdctl, confd... 1 [OK] docker.io docker.io/lighthopper/orientdb-centos A Dockerfile for creating an OrientDB imag... 1 [OK] docker.io docker.io/softvisio/centos Centos 1 [OK] docker.io docker.io/yajo/centos-epel CentOS with EPEL and fully updated 1 [OK] docker.io docker.io/blacklabelops/centos CentOS Base Image! Built and Updates Daily! 0 [OK] docker.io docker.io/dmglab/centos CentOS with some extras - This is for the ... 0 [OK] docker.io docker.io/ericuni/centos centos dev 0 [OK] docker.io docker.io/grayzone/centos auto build for centos. 0 [OK] docker.io docker.io/insaneworks/centos CentOS 6.5 x86_64 + @update 0 [OK] docker.io docker.io/januswel/centos yum update-ed CentOS image 0 [OK] docker.io docker.io/jsmigel/centos-epel Docker base image of CentOS w/ EPEL installed 0 [OK] docker.io docker.io/lighthopper/openjdk-centos A Dockerfile for creating an OpenJDK image... 0 [OK] docker.io docker.io/timhughes/centos Centos with systemd installed and running 0 [OK] docker.io docker.io/ustclug/centos USTC centos 0 [OK]
恭喜你!现在,您知道“如何在CentOS7上安装Docker”。在下一篇Linux文章中,我们将学习有关这些命令类型的更多信息。继续阅读!