“模板:Docker”的版本间的差异
来自ARM Wiki
Tangdapeng(讨论 | 贡献) (→安装特定版本) |
Tangdapeng(讨论 | 贡献) |
||
(未显示同一用户的5个中间版本) | |||
第5行: | 第5行: | ||
sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common | sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | ==== | + | ==== Debian ==== |
*添加Docker的官方GPG密钥: | *添加Docker的官方GPG密钥: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
第18行: | 第18行: | ||
sub rsa4096 2017-02-22 [S] | sub rsa4096 2017-02-22 [S] | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | * | + | *添加Docker源,[arch=arm64]中的参数根据系统架构决定 |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | sudo add-apt-repository "deb [arch= | + | sudo add-apt-repository "deb [arch=arm64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" |
+ | </syntaxhighlight> | ||
+ | ==== Ubuntu ==== | ||
+ | *添加Docker的官方GPG密钥: | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | ||
+ | sudo apt-key fingerprint 0EBFCD88 | ||
+ | </syntaxhighlight> | ||
+ | *添加Docker源,[arch=arm64]中的参数根据系统架构决定 | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | sudo add-apt-repository "deb [arch=arm64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
− | |||
===安装Docker=== | ===安装Docker=== | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
sudo apt update | sudo apt update | ||
− | sudo apt | + | sudo apt install docker-ce docker-ce-cli containerd.io |
</syntaxhighlight> | </syntaxhighlight> | ||
====安装特定版本==== | ====安装特定版本==== | ||
第42行: | 第50行: | ||
*按如下命令安装(<VERSION_STRING>替换成对应的版本号) | *按如下命令安装(<VERSION_STRING>替换成对应的版本号) | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | sudo apt | + | sudo apt install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io |
</syntaxhighlight> | </syntaxhighlight> | ||
示例: | 示例: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | sudo apt | + | sudo apt install docker-ce=5:19.03.8~3-0~debian-stretch docker-ce-cli=5:19.03.8~3-0~debian-stretch containerd.io |
</syntaxhighlight> | </syntaxhighlight> | ||
第55行: | 第63行: | ||
*没有本地镜像的情况下会自动pull下来,完成后会进入容器 | *没有本地镜像的情况下会自动pull下来,完成后会进入容器 | ||
[[File:Docker-demo.jpg|500px|Docker-demo]]<br /> | [[File:Docker-demo.jpg|500px|Docker-demo]]<br /> | ||
+ | |||
+ | ===常用命令=== | ||
+ | *查看docker版本 | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | docker version | ||
+ | </syntaxhighlight> | ||
+ | *查看当前运行容器 | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | docker ps | ||
+ | </syntaxhighlight> | ||
+ | *查看所有容器 | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | docker ps -a | ||
+ | </syntaxhighlight> | ||
+ | *启动一个容器 | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | docker run -it ubuntu /bin/bash | ||
+ | </syntaxhighlight> | ||
+ | *后台运行一个容器 | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | docker run -itd --name ubuntu-test ubuntu /bin/bash | ||
+ | </syntaxhighlight> | ||
+ | *停止容器 | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | docker stop ubuntu-test | ||
+ | </syntaxhighlight> | ||
+ | *重启容器 | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | docker restart ubuntu-test | ||
+ | </syntaxhighlight> | ||
+ | *删除容器 | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | docker rm ubuntu-test | ||
+ | </syntaxhighlight> | ||
+ | *查看本地镜像 | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | docker images | ||
+ | </syntaxhighlight> | ||
+ | *移除镜像 | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | docker rmi centos:7 | ||
+ | </syntaxhighlight> | ||
+ | *连接容器 | ||
+ | <syntaxhighlight lang="bash"> | ||
+ | docker exec -it ubuntu-test /bin/bash | ||
+ | </syntaxhighlight> |
2020年5月15日 (五) 18:50的最新版本
配置Ubuntu\Debian软件库
- 更新apt软件包索引并安装软件包
sudo apt update
sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
Debian
- 添加Docker的官方GPG密钥:
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
- 执行完以上命令会有如下提示
pub rsa4096 2017-02-22 [SCEA]
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
uid [ unknown] Docker Release (CE deb) <docker@docker.com>
sub rsa4096 2017-02-22 [S]
- 添加Docker源,[arch=arm64]中的参数根据系统架构决定
sudo add-apt-repository "deb [arch=arm64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
Ubuntu
- 添加Docker的官方GPG密钥:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
- 添加Docker源,[arch=arm64]中的参数根据系统架构决定
sudo add-apt-repository "deb [arch=arm64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
安装Docker
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
安装特定版本
- 首先查找当前提供的可用版本
apt-cache madison docker-ce
- 如下是部分打印信息,第二列为版本信息
docker-ce | 5:19.03.8~3-0~debian-stretch | https://download.docker.com/linux/debian stretch/stable arm64 Packages
...
- 按如下命令安装(<VERSION_STRING>替换成对应的版本号)
sudo apt install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
示例:
sudo apt install docker-ce=5:19.03.8~3-0~debian-stretch docker-ce-cli=5:19.03.8~3-0~debian-stretch containerd.io
运行容器
docker run -it ubuntu bash
- 没有本地镜像的情况下会自动pull下来,完成后会进入容器
常用命令
- 查看docker版本
docker version
- 查看当前运行容器
docker ps
- 查看所有容器
docker ps -a
- 启动一个容器
docker run -it ubuntu /bin/bash
- 后台运行一个容器
docker run -itd --name ubuntu-test ubuntu /bin/bash
- 停止容器
docker stop ubuntu-test
- 重启容器
docker restart ubuntu-test
- 删除容器
docker rm ubuntu-test
- 查看本地镜像
docker images
- 移除镜像
docker rmi centos:7
- 连接容器
docker exec -it ubuntu-test /bin/bash