安装Docker环境

工作要用,就学下呗

安装Docker

OS: Linux tmp 5.3.0-28-generic #30~18.04.1-Ubuntu

检查是否安装了旧版本,如果有的话先卸载:

1
$ sudo apt-get remove docker docker-engine docker.io containerd runc

更新软件包:

1
$ sudo apt update

安装相应的依赖:

1
$ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

添加Docker官方的GPG密钥:

1
2
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo apt-key fingerprint 0EBFCD88

添加存储库:

1
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

安装最新版本的Docker:

1
2
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io

建立docker用户组,将需要使用docker的用户加入docker组并更新:

1
2
3
$ sudo groupadd docker
$ sudo usermod -aG docker $USER
$ systemctl restart docker

退出当前终端并重新登录,进行测试:

1
2
3
4
5
6
7
8
9
$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Already exists
Digest: sha256:9572f7cdcee8591948c2963463447a53466950b3fc15a247fcad1917ca215a2f
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
......

说明已经安装成功,遇到如下报错的话,重启即可:

1
Got permission denied while trying to connect to the Docker daemon socket at unix...

安装Docker Compose

1
2
3
sudo curl -L "https://github.com/docker/compose/releases/download/1.22.0/docker-compose-$(uname -s)-$(uname -m)"  -o /usr/local/bin/docker-compose
sudo mv /usr/local/bin/docker-compose /usr/bin/docker-compose
sudo chmod +x /usr/bin/docker-compose

Docker Hub配置USTC源

为了加速拉取,采用USTC镜像,新建/etc/docker/daemon.json文件,写入:

1
2
3
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/"]
}

重新启动Docker:

1
sudo systemctl restart docker

通过docker info查看是否配置成功,在输出中可以看到下面的部分:

1
2
3
4
5
$ docker info
......
Registry Mirrors:
https://docker.mirrors.ustc.edu.cn/
......

排错

1、通过yml文件拉取镜像时,提示如下错误:

1
ERROR: An HTTP request took too long to complete. Retry with --verbose to obtain debug information. If you encounter this issue regularly because of slow network conditions, consider setting COMPOSE_HTTP_TIMEOUT to a higher value (current value: 60).

通过如下错误可解决:

1
COMPOSE_HTTP_TIMEOUT=200 docker-compose --compatibility up

2、如果yml文件中版本不对,导致拉取错误latest not found: manifest unknown: manifest unknown,此时需要去Docker Hub中搜索相应的信息,查看想要拉取的tag是什么,再做相应的修改。

参考

1、https://docs.docker.com/install/linux/docker-ce/ubuntu/
2、https://docs.docker.com/compose/install/
3、https://stackoverflow.com/questions/36685980/docker-is-installed-but-docker-compose-is-not-why
4、https://mirrors.ustc.edu.cn/help/dockerhub.html
5、https://stackoverflow.com/a/36502755

0%