Debian12 安装Docker
安装Docker
先更新系统
apt update
安装Docker
apt -y install docker.io
测试是否安装成功,以下三个命令随便一个都可以。
docker -v docker --version docker version
输出:
Docker version 20.10.24+dfsg1, build 297e128
更改DOCKER HUB源
修改/etc/docker/daemon.json文件,没有的话nano会自动创建一个
nano /etc/docker/daemon.json
输入以下内容:
{
"registry-mirrors": [
"https://registry.hub.docker.com",
"http://hub-mirror.c.163.com",
"https://mirror.baidubce.com",
"https://docker.mirrors.sjtug.sjtu.edu.cn",
"https://docker.nju.edu.cn"
]
}
CTRL+O,回车键保存,CTRL+X推出nano
加载daemon.json文件更新配置,重启Docker
systemctl daemon-reload systemctl restart docker
查看镜像源地址修改情况,检查最后几行Registry Mirrors是不是刚刚修改的地址
docker info
运行一个镜像测试一下
docker run hello-world
docker run hello-world 是一个 Docker 命令,用于运行一个名为 hello-world 的 Docker 容器。这个命令首先会在本地查找 hello-world 镜像,如果没有找到,Docker 会自动从 Docker Hub 上下载这个镜像,然后运行这个镜像。
如果你运行了 docker run hello-world 命令,你应该会看到一些欢迎信息,通常是一条打印出 "Hello from Docker!" 的消息。
输出如下。
root@debian:/etc/docker# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:d211f485f2dd1dee407a80973c8f129f00d54604d2c90732e8e320e5038a0348
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/
OK,Docker安装成功了。
安装docker-compose
虽然现在用不到,以后会用到。
apt install docker-compose -y
测试docker-compose是否安装成功,以下三个命令随便一个都可以。
docker-compose -v docker-compose --version docker-compose version
输出以下差不多的内容表示安装成功。
docker-compose version 1.29.2, build unknown
Compose 是用于定义和运行多容器 Docker 应用程序的工具。通过 Compose,您可以使用 YML 文件来配置应用程序需要的所有服务。然后,使用一个命令,就可以从 YML 文件配置中创建并启动所有服务。