准备
安装docker引擎需要Centos 7或者 8版本,系统必须启用centos-extras存储库。这个存储库在默认情况下是启用的,但是如果您已经禁用了它,则需要重新启用它,建议使用overlay2存储驱动,执行如下命令卸载老版本docker引擎,/var/lib/docker/下存储了老的镜像、挂载卷、容器等文件如果不需要建议删除
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
安装方式一共三种:
- 仓库方式安装
- 安装包方式安装
- 脚本安装
采用仓库安装
安装工具
$ sudo yum install -y yum-utils
配置仓库源
$ sudo yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
安装引擎
查看指定版本
$ yum list docker-ce --showduplicates | sort -r
docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
最新版本安装
$ sudo yum install docker-ce docker-ce-cli containerd.io
基于版本安装
$ sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io
启动服务
sudo systemctl start docker
验证安装
使用docker 运行hello-world镜像
banbohub@banbohub .~ $ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:cc15c5b292d8525effc0f89cb299f1804f3a725c8d05e158653a563f15e4f685
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/
采用安装包
如果无法使用 仓库 进行安装,可以采用下载安装包(.rpm)的形式进行安装
下载安装包
根据CentOS版本在https://download.docker.com/linux/centos/ 选择相应的docker 引擎版本下载
安装引擎
$ sudo yum install /path/to/package.rpm
启动服务
sudo systemctl start docker
验证安装
使用docker 运行hello-world镜像
banbohub@banbohub .~ $ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:cc15c5b292d8525effc0f89cb299f1804f3a725c8d05e158653a563f15e4f685
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/
更新镜像
如果要升级Docker引擎,请下载更新的软件包文件,然后重复安装过程,使用yum -y upgrade代替yum -y install,并指向新文件。
脚本安装
Docker 官方为了简化安装流程,提供了一套安装脚本,但是不建议将便利脚本用于生产环境。该脚本的源代码是开源的,可以在GitHub上的docker安装存储库中找到。
$ curl -fsSL https://get.docker.com -o get-docker.sh $ sh ./get-docker.sh
省略sudo
创建 docker 用户组
sudo groupadd docker
将用户添加到 docker 组
sudo usermod -aG docker {your_username}
本文暂时没有评论,来添加一个吧(●'◡'●)