docker学习笔记
标题Ubuntu安装docker
参考:ubuntu22.04使用阿里云Docker镜像源安装Docker(https://blog.csdn.net/qq_26328861/article/details/136205861)
-
安装依赖包
sudo apt install apt-transport-https ca-certificates curl gnupg lsb-release
-
添加阿里云Docker镜像源GPG秘钥
sudo curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
-
添加阿里云镜像源
sudo echo "deb [arch=amd64 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/null
-
安装Docker
sudo apt install docker-ce docker-ce-cli containerd.io
-
启动Docker服务
sudo systemctl start docker
-
查看Docker是否启动成功
sudo systemctl status docker
-
查看Docker的版本号,能打印则说明安装成功
sudo docker -v
-
运行第一个镜像,hello-world
sudo docker run hello-world
出现下面的报错,说明无法访问docker hub网站,需要配置国内的镜像,参考下一节。
Using default tag: latest
Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
配置docker使用国内的镜像
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": [
"https://docker.1panel.live",
"https://docker.m.daocloud.io",
"https://docker.cloudlayer.icu"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo docker run hello-world
出现下面的打印则表示运行成功
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
e6590344b1a5: Pull complete
Digest: sha256:bfbb0cc14f13f9ed1ae86abc2b9f11181dc50d779807ed3a3c5e55a6936dbdd5
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 Hub国内无法访问方法汇总(https://www.cnblogs.com/ppqppl/articles/18499797)
docker常用命令
docker ps #查看正在运行的镜像的状态
docker stop <容器ID> #停止某个镜像,容器ID可以从docker ps命令中获取