Ubuntu 安装 Docker
- 系统环境
本文基于 Ubuntu 18.04 (LTS) 安装,与 Ubuntu 16.04 (LTS) 的安装过程一致。
- 移除旧版本的Docker
如果之前安装过其他版本的Docker,首先需要卸载这些Docker,使用如下命令:
sudo apt remove docker docker-engine docker.io
- 安装依赖的软件包
sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
- 添加软件源
由于国内使用 Docker 的源速度比较慢,在这里使用中科大镜像源安装。
sudo add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
- 安装 Docker CE
sudo apt update
sudo apt install docker-ce
- 建立 docker 用户组
默认 docker 只能由 root 用户和 docker 用户组的用户使用,即只能切换到 root 用户或者用 sudo 提权使用,为了方便使用,我们将自己的用户添加到 docker 用户组。
sudo usermod -aG docker $USER
- 测试安装
退出上一步使用的终端,而后运行一下命令:
docker run hello-world
如果输出以下信息,说明安装成功。
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world ca4f61b1923c: Pull complete Digest: sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c 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://cloud.docker.com/
For more examples and ideas, visit: https://docs.docker.com/engine/userguide/