安装docker

docker官方提供了傻瓜式安装脚本,为你做好所有工作,免去了手动安装的繁琐。
本文实测系统环境:debian11
执行以下命令

curl -fsSL https://get.docker.com | bash -s docker

可在此命令后附带--mirror参数设置镜像源,以提高国内服务器下载docker的速度

若登录linux的用户不是root,则需要docker的用户加入 docker 用户组。参考以下命令。

sudo groupadd docker # 建立docker用户组
sudo usermod -aG docker $USER #将当前用户加入 docker 组

done

重新登录ssh终端,可执行以下命令测试是否正确安装docker
docker run hello-world
正确安装的输出信息如下:

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
d1725b59e92d: Pull complete
Digest: xxxxxxxxxxxxxxxx
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-compose

执行以下命令

curl -L https://github.com/docker/compose/releases/download/v2.4.1/docker-compose-linux-`uname -m` > ./docker-compose

注释:

  • uname -m用于获取本机架构
  • 注意将/2.4.1/换成所需的版本号,可前往docker-compose的仓库查看详情

记得授予权限
chmod +x ./docker-compose
删除没用的文件
mv ./docker-compose /usr/local/bin/docker-compose