官方安装指南:https://docs.docker.com/engine/install/ubuntu/
DOCKER包下载:https://download.docker.com/linux/static/stable/x86_64/
注: 官方安装与其他软件一样是在服务器中安装了docker软件源文件,如果觉得比较麻烦可以,手动下载好文件,放到服务器指定位置去,update即可
1. 提前下载好docker包
wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.14.tgz
2. 解压文件
# 解压的过程中,熟悉一下docker的结构文件
root@python:~# tar xvf docker-20.10.14.tgz
docker/
docker/runc
docker/docker-proxy
docker/containerd-shim
docker/docker
docker/ctr
docker/docker-init
docker/dockerd
docker/containerd
docker/containerd-shim-runc-v2
3. 将解压的文件放入PATH变量能够找到的地方,这样就不用自己手动指定启动路径,也方便下一步做service服务;
root@python:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
root@python:~# ls /usr/local/sbin
root@python:~# ls
docker docker-20.10.14.tgz snap
root@python:~# mv docker/* /usr/local/sbin/
4. 测试是否能启动
root@python:~# docker version
Client:
Version: 20.10.14
API version: 1.41
Go version: go1.16.15
Git commit: a224086
Built: Thu Mar 24 01:45:09 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
5. 配置service,以便systemd管理
root@python:~# vim /usr/lib/systemd/sytem/docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
ExecStart=/usr/local/sbin/dockerd # 注意此处 $PATH
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
LimitNPROC=infinity
TimeoutStartSec=0
Delegate=yes
KillMode=process
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
root@python:~# systemctl daemon-reload
root@python:~# systemctl start docker
# 验证进程是否真的启动,而不是service骗人
root@python:~# ps aux|grep docker
root 81742 0.2 2.6 1348328 53800 ? Ssl 21:31 0:00 /usr/local/sbin/dockerd
root 81764 0.3 1.5 1255536 30812 ? Ssl 21:31 0:00 containerd --config /var/run/docker/containerd/containerd.toml --log-level info
root 81909 0.0 0.0 6432 720 pts/2 S+ 21:32 0:00 grep --color=auto docker
6. 尝试运行一个测试镜像容器
root@python:~# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete
Digest: sha256:10d7d58d5ebd2a652f4d93fdd86da8f265f5318c6a73cc5b6a9798ff6d2b2e67
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 run 是运行一次就退出的,所以要 docker ps -a 查看
root@python:~# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c5d6c331b8ab hello-world "/hello" 52 seconds ago Exited (0) 52 seconds ago dazzling_rosalind