Centos7 docker installation and use _ graphic tutorial

Note: This article is also written with reference to articles on the Internet, thanks to the relevant authors for their contributions.

operating system

64位CentOS Linux release 7.2.1511 (Core)

Configured IP: 192.168.1.160

Modify yum source

The purpose is to improve the download speed of docker.

 

1. Back up your original image file so that it can be restored after an error.

[root@localhost ~]#

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

 

2. Download the new CentOS-Base.repo to /etc/yum.repos.d/

[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

 

3. Run yum makecache to generate the cache

[root@localhost ~]# yum clean all

[root@localhost ~]# yum makecache

Install Docker

[root@localhost ~]# yum -y install docker-io

It will take a few minutes to install. If the internet is fast, it will take tens of seconds.

start Docker

[root@localhost ~]# systemctl start docker

An error will be reported:

Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.

Follow the prompts to execute:

[root@localhost ~]# systemctl status docker.service

There will be prompt information as follows:

● docker.service - Docker Application Container Engine

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

   Active: failed (Result: exit-code) since 三 2018-05-02 23:34:46 CST; 52s ago

     Docs: http://docs.docker.com

  Process: 14416 ExecStart=/usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-path=/usr/libexec/docker/docker-proxy-current --seccomp-profile=/etc/docker/seccomp.json $OPTIONS $DOCKER_STORAGE_OPTIONS $DOCKER_NETWORK_OPTIONS $ADD_REGISTRY $BLOCK_REGISTRY $INSECURE_REGISTRY $REGISTRIES (code=exited, status=1/FAILURE)

 Main PID: 14416 (code=exited, status=1/FAILURE)

 

5月 02 23:34:45 localhost.localdomain systemd[1]: Starting Docker Application Container Engine...

5月 02 23:34:45 localhost.localdomain dockerd-current[14416]: time="2018-05-02T23:34:45.527821208+08:00" level=warning msg="could not change group /var/run/...t found"

5月 02 23:34:45 localhost.localdomain dockerd-current[14416]: time="2018-05-02T23:34:45.532650572+08:00" level=info msg="libcontainerd: new containerd proce...: 14421"

5月 02 23:34:46 localhost.localdomain dockerd-current[14416]: time="2018-05-02T23:34:46.539484373+08:00" level=warning msg="overlay2: the backing xfs filesystem is ...

5月 02 23:34:46 localhost.localdomain dockerd-current[14416]: Error starting daemon: SELinux is not supported with the overlay2 graph driver on this kernel....d=false)

5月 02 23:34:46 localhost.localdomain systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE

5月 02 23:34:46 localhost.localdomain systemd[1]: Failed to start Docker Application Container Engine.

5月 02 23:34:46 localhost.localdomain systemd[1]: Unit docker.service entered failed state.

5月 02 23:34:46 localhost.localdomain systemd[1]: docker.service failed.

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

 

The red part tells us that SELinux in the linux kernel does not support overlay2 graph driver, there are two solutions, either start a new kernel, or disable selinux in docker and set --selinux-enabled=false. We take the second way.

[root@localhost ~]# vi /etc/sysconfig/docker

Then set --selinux-enabled to false, save and exit.

As shown below:

Restart

[root@localhost ~]# systemctl start docker

View version number

[root@localhost ~]# docker -v

Docker version 1.13.1, build 774336d/1.13.1

So far docker starts successfully

Modify the Docker image

Because foreign docker images are too slow to access, we need to modify them to Alibaba Cloud's docker images. In this way, the speed of pulling from domestic mirrors will be faster.

1. Open the Alibaba Cloud docker warehouse address https://dev.aliyun.com/search.html

2. You can log in with your Taobao account. After logging in, click on your own management center.

3. Click "Mirror Accelerator" in the menu bar on the left side of the management center, the right panel will have your acceleration address, and there are detailed setting steps below the panel.

As shown below:

[root@localhost ~]# vi /etc/docker/daemon.json

Copy the following characters in

"registry-mirrors": ["https://njrds9qc.mirror.aliyuncs.com"]

 

Save and exit.

 

refresh daemon

[root@localhost ~]# systemctl daemon-reload

restart docker

[root@localhost ~]# systemctl restart docker

pull image

Take hello-world as an example

[root@localhost ~]# docker pull hello-world

Indicates successful pull

run image

[root@localhost ~]# docker run hello-world

run successfully.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325325978&siteId=291194637