ubuntn20.04安装docker和deocker-compose

发布于:2022-11-05 ⋅ 阅读:(367) ⋅ 点赞:(0)

一:进行一个更新

sudo apt-get update

如果没有换源,需要进行换源操作

1. Ubuntu系统的软件源配置⽂件为 /etc/apt/sources.list 。

2. 我们先使⽤ cp(copy file) 命令备份该⽂件。

        sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

3. 使⽤熟悉的编辑器编辑 sources.list ⽂件

        sudo gedit /etc/apt/sources.list

4.若提⽰gedit不存在,则执⾏以下命令再重新执⾏上⾯的命令

        sudo apt install gedit

5.在打开的 sources.list 的最上⽅输⼊下⾯的内容,下⾯的配置内容来⾃清华和阿⾥云镜像站

# 清华镜像

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse # 预发布软件源,不建议启用 # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

# 阿里云镜像

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

6. 最后打开终端输⼊更新命令

        sudo apt update

        sudo apt upgrade

二,docker环境部署

1. 打开终端

2. ⾸先,我们需要更新⼀下应⽤包的索引,因为我们要导⼊新的HTTPS应⽤库(repository),所以在此之前 我们需要安装⼀下所需的依赖项:

        sudo apt-get update

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

 

3. 使⽤以下curl命令导⼊应⽤库的 GPG 密钥:

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

 4. 有了密钥后,我们就可以把APT应⽤库加载⼊我们的系统:

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

 出现这个再按继续完成安装即可

5.如果出现:sudo: add-apt-repository:找不到命令:

        sudo apt-get install software-properties-common

 5. 安装最新版本的Docker,下⾯的Commands是⽤于安装最新版本的Docker

        sudo apt-get update

        sudo apt install docker-ce docker-ce-cli containerd.io

 6. 启动docker

        sudo systemctl start docker

7. 查看docker是否正确安装

        sudo systemctl status docker

能看到active (running) 就是正常运⾏的       

 也可以查看进程

        ps -ef | grep docker

 

三,docker-compse的部署

1. 使⽤curl将Compose⽂件下载到/usr/local/bin⽬录中

sudo curl -L "https://get.daocloud.io/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

下载其他版本,就把版本号改一下就行了

 下载过程中,可能会被对方重设:

   然后多进行几次就🆗了

2. 下载完成后,将可执⾏权限应⽤于⽂件:

        sudo chmod +x /usr/local/bin/docker-compose

 3. 验证安装是否成功

        docker-compose -v

 显示出版本就是可以的

到这里就安装完成了。

本文含有隐藏内容,请 开通VIP 后查看