ubuntu20.04 安装docker,docker-compose
版本Ubuntu Focal 20.04 (LTS)一.Docker安装1.如果存在旧版本卸载旧版本旧版本的 Docker 称为docker或者docker-engine使用以下命令卸载旧版本sudo apt-get remove docker \ docker-engine \ docker.io2.使用 APT 安装由于apt源使用 HTTPS 以确保软件下载过程中不被篡改。因此我们首先需要添加使用 HTTPS 传输的软件包以及 CA 证书。sudo apt-get update sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg \ lsb-release3.为了确认所下载软件包的合法性需要添加软件源的GPG密钥鉴于国内网络问题这里我们使用阿里云的GPG密钥:curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg4.我们需要向sources.list中添加 Docker 软件源echo \ deb [archamd64 signed-by/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \ $(lsb_release -cs) stable | sudo tee /etc/apt/sources.list.d/docker.list /dev/null5.安装 Docker更新 apt 软件包缓存并安装docker-cesudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io6.启动 Dockersudo systemctl enable docker sudo systemctl start docker7.建立 docker 用户组默认情况下docker命令会使用 Unix socket 与 Docker 引擎通讯。而只有root用户和docker组的用户才可以访问 Docker 引擎的 Unix socket。出于安全考虑一般 Linux 系统上不会直接使用root用户。因此更好地做法是将需要使用docker的用户加入docker用户组建立docker组sudo groupadd docker将当前用户加入docker组usermod -aG docker $USER退出当前终端并重新登录进行如下测试8.测试 Docker 是否安装正确rootzph-IdeaCentre-GeekPro-14IOB:/home/zph# docker version Client: Docker Engine - Community Version: 20.10.12 API version: 1.41 Go version: go1.16.12 Git commit: e91ed57 Built: Mon Dec 13 11:45:33 2021 OS/Arch: linux/amd64 Context: default Experimental: true Server: Docker Engine - Community Engine: Version: 20.10.12 API version: 1.41 (minimum version 1.12) Go version: go1.16.12 Git commit: 459d0df Built: Mon Dec 13 11:43:42 2021 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.4.13 GitCommit: 9cc61520f4cd876b86e77edfeb88fbcd536d1f9d runc: Version: 1.0.3 GitCommit: v1.0.3-0-gf46b6ba docker-init: Version: 0.19.0 GitCommit: de40ad0$ docker run --rm hello-world Unable to find image hello-world:latest locally latest: Pulling from library/hello-world b8dfde127a29: Pull complete Digest: sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24 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://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/说明docker安装成功二.Docker-Compose 安装PIP 安装方式1.先安装pipapt install python3-pip2.安装docker-composesudo pip install -U docker-compose可以看到类似如下输出说明安装成功:Collecting docker-compose Downloading docker_compose-1.29.2-py2.py3-none-any.whl (114 kB) ... Successfully installed attrs-21.4.0 distro-1.7.0 docker-5.0.3 docker-compose-1.29.2 dockerpty-0.4.1 docopt-0.6.2 jsonschema-3.2.0 pyrsistent-0.18.1 python-dotenv-0.19.2 texttable-1.6.4 websocket-client-0.59.0bash 补全命令curl -L https://raw.githubusercontent.com/docker/compose/1.27.4/contrib/completion/bash/docker-compose /etc/bash_completion.d/docker-compose3.卸载sudo pip uninstall docker-composedownload the version of Docker Compos安装方式1.curl下载docker compose#安装1.20版本 Docker Compose sudo curl -L https://github.com/docker/compose/releases/download/1.20.1/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose #安装最新版 Docker Compose sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose2.对二进制文件应用可执行权限sudo chmod x /usr/local/bin/docker-compose3.测试是否安装成功docker-compose --version出现以下说明安装成功docker-compose version 1.20.1, build 5d8c71b命令的变化:从 Docker Compose v2 开始它已从一个独立的docker-compose命令转变为一个 Docker CLI 的插件形式即docker compose中间是空格而不是连字符旧命令 (v1):docker-compose up新命令 (v2):docker compose up因此安装完成后推荐使用docker compose来执行相关操作