没有安装过 docker 的 ubuntu 安装 docker的步骤:

$ sudo apt-get update

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

如果选择官方的源:

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

如果选择阿里的源:

sudo curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add -
sudo apt-key fingerprint 0EBFCD88

添加官方仓库:

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

添加阿里仓库:

sudo add-apt-repository \
   "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
apt-cache madison docker-ce

从上面输出的版本中找到你需要的版本:

sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

如果这里报错,可以尝试这个命令,我用这个命令进行安装就没有问题:

sudo apt-get -y install docker-ce=[VERSION]
sudo docker run hello-world
sudo gpasswd -a 用户名 docker
sudo service docker restart
newgrp - docker

安装 docker-compose,先去 https://github.com/docker/compose/releases 找到你需要的版本,然后替换下面的 1.24.1 这个版本号,我用的是 1.27.3 :

sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose --version

参考: https://docs.docker.com/engine/install/ubuntu/ https://www.cnblogs.com/walker-lin/p/11214127.html https://www.runoob.com/docker/docker-compose.html https://blog.csdn.net/liqi_q/article/details/83030737 https://www.cnblogs.com/grow1016/p/11533645.html

标签: docker

添加新评论