本教程参考:https://docs.docker.com/engine/installation/linux/docker-ce/centos/#install-using-the-repository
卸载旧版
没有安装过 docker 的可以略过。
$ sudo yum remove docker docker-common docker-selinux docker-engine
安装 Docker CE
预备条件
$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
安装
$ sudo yum install docker-ce
如果安装失败,可能yum源缺少,可尝试更换aliyun源。
查看版本
$ docker version
启动 Docker
$ sudo systemctl start docker
关闭 Docker
$ sudo systemctl stop docker
开机启动(可选)
$ sudo systemctl enable docker
更换仓库镜像
为了加速镜像拉取,以中科大源为例:http://mirrors.ustc.edu.cn/help/dockerhub.html?highlight=docker
更新/etc/docker/daemon.json
为:
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/"]
}
推荐使用 aliyun 的镜像加速器,具体使用会在后续文章中介绍。
Hello world
使用命令行的工具来检索名字为
tutorial
的镜像$ docker search tutorial
使用docker命令来下载镜像
$ docker pull learn/tutorial
查看已下载的镜像
$ docker images
在 docker 容器中运行 hello world!
docker run
命令有两个参数,一个是镜像名,一个是要在镜像中运行的命令。$ docker run learn/tutorial echo "hello word"