apt install apt-transport-https ca-certificates curl software-properties-common # 由于apt源使用 HTTPS 以确保软件下载过程中不被篡改。因此,我们首先需要添加使用HTTPS 传输的软件包以及 CA 证书。 curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add - # 为了确认所下载软件包的合法性,需要添加软件源的GPG密钥。也可以添加官方密钥,如下 # curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - add-apt-repository "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable" # 向source.list中添加 Docker 软件源 apt update apt install docker-ce # 安装docker # 在ubuntu19.10版本中,没有找到docker-ce,更新源时还会报错。可以安装docker.io,另外查到方法可尝试 # curl https://get.docker.com | bash # sudo apt install docker.io groupadd docker usermod -aG docker test # 将当前用户加入docker组 # 默认情况下,docker命令会使用 Unix socket 与 Docker 引擎通讯。而只有root用户和组的用户才可以访问 # Docker 引擎的 Unix socket。出于安全考虑,一般 Linux 系统上不会直接使用root用户。因此,更好地做法是 # 将需要使用docker的用户加入docker用户组。 newgrp docker # 不需要使用sudo,但一定要更新用户组,如果不执行此步,还是会报错:"docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/create: dial unix /var/run/docker.sock: connect: permission denied. " # 原因就是上面说的,docker进程使用Unix Socket而不是TCP端口。而默认情况下,Unix socket属于root用户,需要root权限才能访问。 vim /etc/docker/daemon.json { "registry-mirrors": ["https://7ozw7lxv.mirror.aliyuncs.com"] } # 设置docker加速器,地址是从阿里云的容器镜像服务器得到的 systemctl daemon-reload systemctl start docker docker run hello-world # 测试docker安装是否成功。如果安装成功,会输入下列内容 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/