如何在CentOS7当中进行Docker安装

2018-08-02  本文已影响0人  雨夜狂奔的蜗牛

安装要求


[root@localhost ~]# uname -a

Linux localhost.localdomain 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

[root@localhost ~]#

通过yum的方式安装


[root@localhost ~]# yum update -y

将以下文件拷贝到/etc/yum.repos.d/目录下, 并保存为docker.repo


[dockerrepo]

name=Docker Repository

baseurl=https://yum.dockerproject.org/repo/main/centos/7

enable=1

gpgcheck=1

gpgkey=https://yum.dockerproject.org/gpg


[root@localhost yum.repos.d]# yum install -y docker-engine

docker-engine安装完成之后docker并不会自动启动, 所以需要手动启动docker


查看docker-engine安装完成之后docker服务的状态

[root@localhost yum.repos.d]# 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: https://docs.docker.com

[root@localhost yum.repos.d]#

添加开机自启动并启动docker服务


[root@localhost yum.repos.d]# systemctl enable docker

Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

[root@localhost yum.repos.d]#

[root@localhost yum.repos.d]# systemctl start docker

[root@localhost yum.repos.d]#



查看docker运行状态


[root@localhost yum.repos.d]# systemctl status docker

● docker.service - Docker Application Container Engine

   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)

   Active: active (running) since Thu 2018-08-02 10:59:36 EDT; 12s ago

     Docs: https://docs.docker.com

 Main PID: 2457 (dockerd)

    Tasks: 16

   Memory: 13.5M

   CGroup: /system.slice/docker.service

           ├─2457 /usr/bin/dockerd

           └─2460 docker-containerd -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/containerd --shim docker-containerd-shim --runtime doc...



Aug 02 10:59:34 localhost.localdomain systemd[1]: Starting Docker Application Container Engine...

Aug 02 10:59:35 localhost.localdomain dockerd[2457]: time="2018-08-02T10:59:34.993895086-04:00" level=info msg="libcontainerd: new containerd process, pid: 2460"

Aug 02 10:59:36 localhost.localdomain dockerd[2457]: time="2018-08-02T10:59:36.057360579-04:00" level=info msg="Graph migration to content-addressability took 0.00 seconds"

Aug 02 10:59:36 localhost.localdomain dockerd[2457]: time="2018-08-02T10:59:36.058359003-04:00" level=info msg="Loading containers: start."

Aug 02 10:59:36 localhost.localdomain dockerd[2457]: time="2018-08-02T10:59:36.208752435-04:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to s...rred IP address"

Aug 02 10:59:36 localhost.localdomain dockerd[2457]: time="2018-08-02T10:59:36.322492112-04:00" level=info msg="Loading containers: done."

Aug 02 10:59:36 localhost.localdomain dockerd[2457]: time="2018-08-02T10:59:36.329675081-04:00" level=info msg="Daemon has completed initialization"

Aug 02 10:59:36 localhost.localdomain dockerd[2457]: time="2018-08-02T10:59:36.329699951-04:00" level=info msg="Docker daemon" commit=89658be graphdriver=overlay version=17.05.0-ce

Aug 02 10:59:36 localhost.localdomain dockerd[2457]: time="2018-08-02T10:59:36.335503624-04:00" level=info msg="API listen on /var/run/docker.sock"

Aug 02 10:59:36 localhost.localdomain systemd[1]: Started Docker Application Container Engine.

Hint: Some lines were ellipsized, use -l to show in full.

[root@localhost yum.repos.d]#

查看docker的本地配置信息


[root@localhost yum.repos.d]# docker info

Containers: 0

 Running: 0

 Paused: 0

 Stopped: 0

Images: 0

Server Version: 17.05.0-ce

Storage Driver: overlay

 Backing Filesystem: xfs

 Supports d_type: true

Logging Driver: json-file

Cgroup Driver: cgroupfs

Plugins:

 Volume: local

 Network: bridge host macvlan null overlay

Swarm: inactive

Runtimes: runc

Default Runtime: runc

Init Binary: docker-init

containerd version: 9048e5e50717ea4497b757314bad98ea3763c145

runc version: 9c2d8d184e5da67c95d601382adf14862e4f2228

init version: 949e6fa

Security Options:

 seccomp

  Profile: default

Kernel Version: 3.10.0-693.el7.x86_64

Operating System: CentOS Linux 7 (Core)

OSType: linux

Architecture: x86_64

CPUs: 1

Total Memory: 3.702GiB

Name: localhost.localdomain

ID: WDSH:UZED:35RO:5R5W:J7KN:QOLZ:ZKG5:Z7RN:ZZRD:PDCQ:2YHX:VEE5

Docker Root Dir: /var/lib/docker

Debug Mode (client): false

Debug Mode (server): false

Registry: https://index.docker.io/v1/

Experimental: false

Insecure Registries:

 127.0.0.0/8

Live Restore Enabled: false



[root@localhost yum.repos.d]#

查看版本


[root@localhost yum.repos.d]# docker -v

Docker version 17.05.0-ce, build 89658be

[root@localhost yum.repos.d]#

运行hello world


[root@localhost yum.repos.d]# docker run hello-world

Unable to find image 'hello-world:latest' locally

latest: Pulling from library/hello-world

9db2ca6ccae0: Pull complete

Digest: sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc

Status: Downloaded newer image for hello-world:latest



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/engine/userguide/



[root@localhost yum.repos.d]#

上一篇 下一篇

猜你喜欢

热点阅读