hengdin

导航

 

1,安装包的下载

进入 /opt 路径下下载安装包,并解压缩

cd /opt
sudo wget https://download.docker.com/linux/static/stable/x86_64/docker-24.0.7.tgz

2,解压安装包,并将解压后的文件夹内的东西全部放到 usr/local 下

sudo tar -xzvf docker-24.0.7.tgz
# 将解压后的文件夹 放到 usr/local 下
mv docker /usr/local/

3,将docker 文件夹下所有文件软连接到/usr/bin目录下,/user/bin是环境变量目录,在路径下都可以运行docker命令

ls -l docker

ln -s /usr/local/docker/containerd /usr/bin/containerd
ln -s /usr/local/docker/containerd-shim /usr/bin/containerd-shim
ln -s /usr/local/docker/containerd-shim-runc-v2 /usr/bin/containerd-shim-runc-v2
ln -s /usr/local/docker/ctr /usr/bin/ctr
ln -s /usr/local/docker/docker /usr/bin/docker
ln -s /usr/local/docker/dockerd /usr/bin/dockerd
ln -s /usr/local/docker/docker-init /usr/bin/docker-init
ln -s /usr/local/docker/docker-proxy /usr/bin/docker-proxy
ln -s /usr/local/docker/runc /usr/bin/runc

4,创建编辑docker.service

vim /etc/systemd/system/docker.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/bin/dockerd

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

5. 配置镜像加速器

mkdir -p /etc/docker/
vi /etc/docker/daemon.json

内容如下:

{
"registry-mirrors": ["https://alzgoonw.mirror.aliyuncs.com"]
}

5. 赋执行权限

chmod +x /etc/systemd/system/docker.service

systemctl daemon-reload

6. 启动docker并设置开机自启

如果启动docker启动不成功有可能是daemon.json加速器里的内容可能是空格引起的,用tab按键进行重新编排,重新重启即可解决

systemctl enable docker.service

7. 启动docker

systemctl start docker

8. 验证是否安装成功

  • 方式一:
sudo docker version 
Client:
 Version:           20.10.9
 API version:       1.41
 Go version:        go1.16.8
 Git commit:        c2ea9bc
 Built:             Mon Oct  4 16:03:22 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.9
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.8
  Git commit:       79ea9d3
  Built:            Mon Oct  4 16:07:30 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.4.11
  GitCommit:        5b46e404f6b9f661a205e28d59c982d3634148f8
 runc:
  Version:          1.0.2
  GitCommit:        v1.0.2-0-g52b36a2d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

  • 方式二:
docker run hello-world
出现以下信息说明启动成功了
Hello from Docker!
This message shows that your installation appears to be working correctly.

9. 解决docker每次都需要输入sudo的权限问题

# 添加docker用户组
sudo groupadd docker
# 将当前用户添加到docker用户组中
sudo gpasswd -a $USER docker
# 更新用户组
newgrp docker
# 重启docker
sudo service docker restart

10. docker的常用命令

查看docker状态:systemctl status docker
启动docker:systemctl start docker
停止docker:systemctl stop docker
拉取镜像:docker pull 名称
查看镜像:docker images
删除镜像:docker rmi 镜像id
查看正在启动的容器:docker ps
启动容器:docker start 容器名称
查看容器信息:docker inspect mongo
进入容器:docker exec -it 容器名称 /bin/bash
查看docker网络:docker network ls
当前使用docker镜像的容器(以monggodb为例):docker container ls
查看所有容器:docker ps -a
当前正在使用的所有容器:docker container ls -all
停止容器:docker stop 名称
删除容器(容器需要停止运行再删除):docker container rm 名称
删除所有容器:docker rm $(docker ps -a -q)
查看容器IP地址:docker inspect 321a999f2ecc | grep IPAddress

posted on 2022-08-03 16:11  hengdin  阅读(794)  评论(0编辑  收藏  举报