Docker-安装
Docker-Install
Docker 只能安装在 64 位机器上。
Docker 从 1.13 版本之后采用时间线的方式作为版本号,分为社区版 CE 和企业版 EE。
社区版是免费提供给个人开发者和小型团体使用的,企业版会提供额外的收费服务,比如经过官方测试认证过的基础设施、容器、插件等。
Docker 分为 CE 和 EE 两大版本。CE 即社区版(免费,支持周期 7 个月),EE 即企业版,强调安全,付费使用,支持周期 24 个月。
Docker CE 分为 stable test 和 nightly 三个更新频道。每六个月发布一个 stable 版本 (18.09, 19.03, 19.09…)。
CentOS7 安装 Docker CE
Get Docker Engine - Community for CentOS
https://docs.docker.com/install/linux/docker-ce/centos/
CentOS 安装 Docker CE
https://yeasy.gitbooks.io/docker_practice/install/centos.html
Docker 入门教程
http://www.ruanyifeng.com/blog/2018/02/docker-tutorial.html
前提条件:
1 安装 Docker Engine - Community 需要 CentOS 7 版本及以上,老版本不支持。
2 需要开启 centos-extras yum repo,默认是开启的。
安装 docker repo
1 安装 yum 仓库管理工具 yum-utils, 以及 device-mapper-persistent-data, lvm2
$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
2 安装 docker repo
$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
安装完可以在 /etc/yum.repos.d/
中看到 docker-ce.repo
文件docker-ce.repo
中默认只有 docker-ce-stable
是开启的,即只开启稳定版的repo
yum 安装最新版 Docker
sudo yum install docker-ce docker-ce-cli containerd.io
我安装的版本信息
已安装:
containerd.io.x86_64 0:1.2.10-3.2.el7
docker-ce.x86_64 3:19.03.5-3.el7
docker-ce-cli.x86_64 1:19.03.5-3.el7
作为依赖被安装:
container-selinux.noarch 2:2.107-3.el7
启动 Docker 并验证
启动dockersudo systemctl start docker
设置开机启动sudo systemctl enable docker
验证sudo docker run hello-world
注意必须加sudo,启动 docker 需要 root 权限
此命令将从 dokcerhub 下载一个 hello-world 镜像并启动一个容器
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:4fe721ccc2e8dc7362278a29dc660d833570ec2682f4e4194f4ee23e415e1064
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用户组
默认情况下,docker 命令会使用 Unix socket 与 Docker 引擎通讯。
而只有 root 用户和 docker 组的用户才可以访问 Docker 引擎的 Unix socket。
出于安全考虑,一般 Linux 系统上不会直接使用 root 用户。
因此,更好地做法是将需要使用 docker 的用户加入 docker 用户组。
1 sudo groupadd docker
建立 docker 组
2 sudo usermod -aG docker $USER
将当前用户加入 docker 组
3 docker run hello-world
退出 linux 重新登录,不加 sudo 执行 docker,成功说明当前用户加入docker用户组没问题。
重启 Docker
sudo systemctl restart docker
容器会全部停止,之后需要重启容器
CentOS7 Docker 19.03.5 升级到 26.1.4
升级前
检查当前安装的 docker 版本:
$ yum list installed|grep docker
containerd.io.x86_64 1.2.10-3.2.el7 @docker-ce-stable
docker-ce.x86_64 3:19.03.5-3.el7 @docker-ce-stable
docker-ce-cli.x86_64 1:19.03.5-3.el7 @docker-ce-stable
检查当前运行中的 docker 容器:
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6ec7145c4ebe blog "java --add-opens ja…" 12 days ago Up 12 days blog
84b24ea9c2e1 nginx:alpine "nginx -g 'daemon of…" 2 months ago Up 2 months nginx
780a99514961 prom/prometheus "/bin/prometheus --c…" 21 months ago Up 21 months prometheus
494d650978b1 prom/node-exporter "/bin/node_exporter" 21 months ago Up 21 months node-exporter
b99e30d1e09f grafana/grafana "/run.sh" 21 months ago Up 21 months grafana
65842e714996 elasticsearch:8.8.2-ik "/bin/tini -- /usr/l…" 21 months ago Up 21 months es
f33daa8d3e09 gogs/gogs "/app/gogs/docker/st…" 2 years ago Up 2 years gogs
升级
1、停止 docker 服务 sudo systemctl stop docker
2、卸载旧版 dockersudo yum remove -y docker-ce docker-ce-cli containerd.io
3、安装新版 docker
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 -y docker-ce docker-ce-cli containerd.io
已安装:
docker-ce.x86_64 3:26.1.4-1.el7 docker-ce-cli.x86_64 1:26.1.4-1.el7
containerd.io.x86_64 0:1.6.28-3.2.el7
4、启动及添加开机启动
# 启动
sudo systemctl start docker
# 添加开机启动
sudo systemctl enable docker
# 验证
sudo docker run hello-world
看到下面信息即可:
Hello from Docker!
This message shows that your installation appears to be working correctly.
查看 docker 版本
$ docker -v
Docker version 26.1.4, build 5650f9b
升级后
docker ps 无结果,容器都停止了
按升级前的记录,依次启动各个 docker 容器
实测:
之前 es8 启动后在容器内用 elasticsearch-setup-passwords 命令行工具交互式配置的用户密码还在
之前 grafana 启动后在界面配置的 admin 密码也还在
Mac 安装 Docker CE
Install Docker Desktop on Mac
https://docs.docker.com/docker-for-mac/install/
macOS 安装 Docker Desktop CE
https://yeasy.gitbooks.io/docker_practice/install/mac.html
Docker Desktop for Mac 要求系统最低为 2010 年以后的 Mac 机型,准确说是带 Intel MMU 虚拟化的, macOS 10.13 及以上版本, 最低 4GB 内存。
如果不满足已上要求,可以使用 Docker Toolbox 安装 Docker 来代替 Docker Desktop, Docker Toolbox 使用 Oracle VirtualBox 虚拟机而不是 HyperKit 虚拟机。
Homebrew 安装 Docker Desktop for Mac
Homebrew 的 Cask 已经支持 Docker Desktop for Mac, 因此可以很方便的使用 Homebrew Cask 来进行安装:brew install --cask docker
查看 docker 版本 docker --version
$ docker --version
Docker version 19.03.5, build 633a0ea
启动一个 nginx 验证docker run -d -p 80:80 --name nginx --rm nginx
docker run -d -p 80:80 --name nginx --rm nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
000eee12ec04: Pull complete
eb22865337de: Pull complete
bee5d581ef8b: Pull complete
Digest: sha256:50cf965a6e08ec5784009d0fccb380fc479826b6e0e65684d9879170a9df8566
Status: Downloaded newer image for nginx:latest
76986f1e2fffac5174f5cfa23a0988f891762bfc73904aad142d1c96c9dff75e
会自动从 docker hub 上下载最新版 nginx 镜像并启动
服务运行后,可以访问 http://localhost,如果看到了 “Welcome to nginx!”,就说明 Docker Desktop for Mac 安装成功了。
nvidia-docker
NVIDIA / nvidia-docker
https://github.com/NVIDIA/nvidia-docker
nvidia-docker 相关组件
nvidia-docker2
nvidia-container-runtime
nvidia-container-toolkit
libnvidia-container
之间的关系
What’s the difference between the lastest nvidia-docker and nvidia container runtime? #1268
https://github.com/NVIDIA/nvidia-docker/issues/1268
下一篇 Docker-Compose
页面信息
location:
protocol
: host
: hostname
: origin
: pathname
: href
: document:
referrer
: navigator:
platform
: userAgent
: