💕本文严重依赖(参考,非暴力复制)于 docker官方文档:
https://docs.docker.com/install

教程环境

系统环境

ProductName: Mac OS XProductVersion: 10.14.2

BuildVersion: 18C54

虚拟机环境

默认centos7 64

[root@redis01 ~]# uname -r 3.10.0-957.el7.x86_64 [root@redis01 ~]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) [root@redis01 ~]#

运行权限

本文运行用户为ROOT,如果是普通用户,需要在运行命令前加上sudo,还可以创建docker用户组,并您的用户创建到将docker组中,这样方便管理.
可以参考资料:https://docs.docker.com/install/linux/linux-postinstall/

介绍

安装

yum安装

便捷脚本安装

要求

存储库安装

配置加速器

Ubuntu 16.04+、Debian 8+、CentOS 7

对于使用 systemd 的系统,请在 /etc/docker/daemon.json 中写入如下内容(如果文件不存在请新建该文件)

  1. {
  2. "registry-mirrors": [
  3. "https://dockerhub.azk8s.cn",
  4. "https://reg-mirror.qiniu.com"
  5. ]
  6. }

注意,一定要保证该文件符合 json 规范,否则 Docker 将不能启动。

之后重新启动服务。

$ sudo systemctl daemon-reload
$ sudo systemctl restart docker

注意:如果您之前查看旧教程,修改了 docker.service 文件内容,请去掉您添加的内容(--registry-mirror=https://dockerhub.azk8s.cn)。

安装依赖

卸载docker

卸载Docker CE
卸载Docker包:

$ sudo yum remove docker-ce
主机上的图像,容器,卷或自定义配置文件不会自动删除。要删除所有图像,容器和卷:

$ sudo rm -rf /var/lib/docker
您必须手动删除任何已编辑的配置文件。

启动docker

[root@redis01 ~]# systemctl start docker
# 检测docker启动状态
[root@redis01 ~]# systemctl status docker
● docker.service - Docker Application Container Engine
  Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
  Active: active (running) since Mon 2019-01-21 09:34:17 CST; 3s ago

查看启动状态和版本

[root@redis01 ~]# docker version
Client:
 Version:           18.09.1
 API version:       1.39
 Go version:        go1.10.6
 Git commit:        4c52b90
 Built:             Wed Jan  9 19:35:01 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.1
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.6
  Git commit:       4c52b90
  Built:            Wed Jan  9 19:06:30 2019
  OS/Arch:          linux/amd64
  Experimental:     false

本文就不将docker设为开机自启动了,没用~~~(至少现在是)
设置可以参考资料:https://docs.docker.com/install/linux/linux-postinstall/

测试docker运行

运行hello-world测试

[root@redis01 ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
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/get-started/

该 run 命令会下载镜像,并在容器中运行,容器运行中,会打印hello 的信息,然后容器退出.

[root@redis01 ~]#