ubuntu18.04安装docker,最全教程
Ubuntu 安装 Docker CE
ubuntu安装教程>警告:切勿在没有配置 Docker APT 源的情况下直接使⽤ apt 命令安装 Docker.
### 准备⼯作
#### 系统要求
* Bionic 18.04 (LTS)
* Xenial 16.04 (LTS)
Docker CE 可以安装在 64 位的 x86 平台或 ARM 平台上。Ubuntu 发⾏版中,LTS(Long-Term-Support)长期⽀持版本,会获得 5年的升级维护⽀持,这样的版本会更稳定,因此在⽣产环境中推荐使⽤ LTS 版本。
#### 卸载旧版本
旧版本的 Docker 称为 `docker` 或者 `docker-engine`,使⽤以下命令卸载旧版本:
```bash
$ sudo apt-get remove docker \
docker-engine \
docker.io
```
提醒(1)上⾯的bash是告诉你这些语句输⼊在控制台中
(2)直接从sudo到结尾的o复制全部,然后在控制台中右键,粘帖
### 使⽤ APT 安装
```bash
$ sudo apt-get update
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
```
提醒: 操作同上所⽰,直接复制,粘帖即可
鉴于国内⽹络问题,强烈建议使⽤国内源,官⽅源请在注释中查看。
为了确认所下载软件包的合法性,需要添加软件源的 `GPG` 密钥。
```bash
然后,我们需要向 `source.list` 中添加 Docker 软件源
```bash
提醒:操作直接复制,粘粘
>以上命令会添加稳定版本的 Docker CE APT 镜像源,如果需要测试或每⽇构建版本的 Docker CE 请将 stable 改为 test 或者 nightly。
#### 安装 Docker CE
更新 apt 软件包缓存,并安装 `docker-ce`:
```bash
$ sudo apt-get update
$ sudo apt-get install docker-ce
```
### 使⽤脚本⾃动安装
在测试或开发环境中 Docker 官⽅为了简化安装流程,提供了⼀套便捷的安装脚本,Ubuntu 系统上可以使⽤这套脚本安装:
```bash
$ curl -fsSL get.docker -o get-docker.sh
$ sudo sh get-docker.sh --mirror Aliyun
```
执⾏这个命令后,脚本就会⾃动的将⼀切准备⼯作做好,并且把 Docker CE 的 Edge 版本安装在系统中。
### 启动 Docker CE
```bash
$ sudo systemctl enable docker
$ sudo systemctl start docker
```
### 建⽴ docker ⽤户组
建⽴ `docker` 组:
```bash
$ sudo groupadd docker
```
将当前⽤户加⼊ `docker` 组:
```bash
$ sudo usermod -aG docker $USER
```
退出当前终端并重新登录,进⾏如下测试。
### 测试 Docker 是否安装正确
```bash
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
d1725b59e92d: Pull complete
Digest: sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788 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
若能正常输出以上信息,则说明安装成功。恭喜你哦
亲测可⽤。
发布评论