安装、卸载Docker
及安装软件实例 设置仓库源 更新仓库,安装仓库源的HTTPS
支持。 1 2 3 4 5 sudo apt install \ ca-certificates \ curl \ gnupg \ lsb-release
增加Docker
官方GPG密钥
: 1 curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
添加Docker
仓库安装源 1 2 3 echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
安装Docker Engine
安装最新版本的Docker Engine
和containerd
,或者执行下一步安装特定版本 1 2 sudo apt install docker-ce docker-ce-cli containerd.io
要安装特定版本的Docker Engine
,请在repo
中列出可用的版本,然后选择并安装: 列出repo
中可用的版本 1 2 3 4 5 6 7 8 apt-cache madison docker-ce docker-ce | 5:20.10.12~3-0~debian-bullseye | https://download.docker.com/linux/debian bullseye/stable amd64 Packages docker-ce | 5:20.10.11~3-0~debian-bullseye | https://download.docker.com/linux/debian bullseye/stable amd64 Packages docker-ce | 5:20.10.10~3-0~debian-bullseye | https://download.docker.com/linux/debian bullseye/stable amd64 Packages docker-ce | 5:20.10.9~3-0~debian-bullseye | https://download.docker.com/linux/debian bullseye/stable amd64 Packages docker-ce | 5:20.10.8~3-0~debian-bullseye | https://download.docker.com/linux/debian bullseye/stable amd64 Packages docker-ce | 5:20.10.7~3-0~debian-bullseye | https://download.docker.com/linux/debian bullseye/stable amd64 Packages docker-ce | 5:20.10.6~3-0~debian-bullseye | https://download.docker.com/linux/debian bullseye/stable amd64 Packages
例如,使用第二列中的版本字符串安装特定的版本 1 2 sudo apt-get install docker-ce=5:20.10.12~3-0~debian-bullseye docker-ce-cli=5:20.10.12~3-0~debian-bullseye containerd.io
验证安装 1 2 3 4 5 6 7 8 9 10 11 sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 2db29710123e: Pull complete Digest: sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. ......
卸载Docker
引擎 卸载Docker Engine
、CLI
和Containerd
包 1 sudo apt purge docker-ce docker-ce-cli containerd.io
删除主机上的所有镜像、容器和卷 主机上的映像、容器、卷或自定义配置文件不会自动删除删除所有镜像、容器和卷1 2 sudo rm -rf /var/lib/docker sudo rm -rf /var/lib/containerd
必须手动删除已编辑的配置文件。
docker
安装软件实例—安装微信docker
换源编辑daemon.json
(不存在就新建)1 sudo vim /etc/docker/daemon.json
填写以下内容:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 { "registry-mirrors" : [ "http://ovfftd6p.mirror.aliyuncs.com" , "http://registry.docker-cn.com" , "http://docker.mirrors.ustc.edu.cn" , "http://hub-mirror.c.163.com" ] , "data-root" : "/home/你自己用户名/docker-home" , "insecure-registries" : [ "registry.docker-cn.com" , "docker.mirrors.ustc.edu.cn" ] , "debug" : true , "experimental" : true }
重新加载并查看docker
信息 依次输入以下命令:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 sudo systemctl daemon-reload sudo systemctl restart docker sudo docker info Client: Context: default Debug Mode: false Plugins: app: Docker App (Docker Inc., v0.9.1-beta3) buildx: Docker Buildx (Docker Inc., v0.7.1-docker) scan: Docker Scan (Docker Inc., v0.12.0) Server: Containers: 1 Running: 0 Paused: 0 Stopped: 1 Images: 1 Server Version: 20.10.12 Storage Driver: overlay2 Backing Filesystem: extfs Supports d_type: true Native Overlay Diff: true userxattr: false Logging Driver: json-file Cgroup Driver: systemd Cgroup Version: 2 Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc ...... runc version: v1.0.2-0-g52b36a2 init version: de40ad0 Security Options: apparmor seccomp Profile: default cgroupns Kernel Version: 5.10.0-9-amd64 Operating System: Debian GNU/Linux 11 (bullseye) OSType: linux Architecture: x86_64 CPUs: 2 Total Memory: 3.743GiB ...... Docker Root Dir: /home/你自己用户名/docker-home Debug Mode: true File Descriptors: 24 Goroutines: 34 System Time: 2021-12-18T12:12:11.920214294+08:00 EventsListeners: 0 Registry: https://index.docker.io/v1/ Labels: Experimental: true Insecure Registries: docker.mirrors.ustc.edu.cn registry.docker-cn.com 127.0.0.0/8 Registry Mirrors: http://ovfftd6p.mirror.aliyuncs.com/ http://registry.docker-cn.com/ http://docker.mirrors.ustc.edu.cn/ http://hub-mirror.c.163.com/ Live Restore Enabled: false
拉取微信镜像 1 2 3 4 5 6 7 8 9 10 11 12 13 14 sudo docker pull bestwu/wechat Using default tag: latest latest: Pulling from bestwu/wechat f21eee950c89: Pull complete 11ce96be0dbe: Pull complete 213b37605fda: Pull complete fb5f4607d644: Pull complete 996bef3d98a0: Pull complete 6181aef875e7: Pull complete 892cf94c8e7a: Pull complete Digest: sha256:f0a3b04aae119ed2d7bb9e6f1f8e5a3cf39a435b028fd9ddd733680fd5639693 Status: Downloaded newer image for bestwu/wechat:latest docker.io/bestwu/wechat:latest
创建运行脚本wechat.sh
输入以下内容:1 2 3 4 5 6 7 8 9 10 11 sudo docker run -d --name wechat --device /dev/snd --ipc="host" \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -v $HOME /WeChatFiles:/WeChatFiles \ -e DISPLAY=unix$DISPLAY \ -e XMODIFIERS=@im=fcitx \ -e QT_IM_MODULE=fcitx \ -e GTK_IM_MODULE=fcitx \ -e AUDIO_GID=`getent group audio | cut -d: -f3` \ -e GID=`id -g` \ -e UID=`id -u` \ bestwu/wechat
使用脚本:
查看容器内容 1 2 3 4 5 sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 091e415c8872 bestwu/wechat "/entrypoint.sh" 13 minutes ago Up 13 minutes wechat 4eadb762084f hello-world "/hello" 2 hours ago Exited (0) 2 hours ago priceless_goodall
打开&关闭微信 1 2 3 4 sudo docker start wechat sudo docker stop wechat
删除微信容器 1 2 docker stop $(docker ps -a -q) sudo docker rm -f wechat
删除镜像和容器 1 2 3 4 5 6 7 8 9 10 11 12 sudo docker rmi <镜像id > sudo docker rmi -f hello-world Untagged: hello-world:latest Untagged: hello-world@sha256:2498fce14358aa50ead0cc6c19990fc6ff866ce72aeb5546e1d59caac3d0d60f Deleted: sha256:feb5d9fea6a5e9606aa995e879d862b825965ba48de054caab5ef356dc6b3412 sudo docker rm 4eadb762084f
安装、卸载docker-compose
及安装软件实例 安装docker-compose
1 2 3 4 5 6 7 8 9 10 sudo curl -L "https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-$(uname -s) -$(uname -m) " -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose docker-compose -v Docker Compose version v2.2.2 sudo rm /usr/local/bin/docker-compose
若提示XXX commend not found
,则建立软链接或者将/user/local/bin
加入到环境变量(推荐)1 2 3 4 5 sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose vim ~/.bashrc export PATH=/usr/local/bin:$PATH
安装实例—安装TIM-QQ
输入以下内容:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 version: '2' services: qq: image: bestwu/qq:office container_name: qq ipc: host devices: - /dev/snd #声音 volumes: - /tmp/.X11-unix:/tmp/.X11-unix - /home/yk/TencentFiles:/TencentFiles #使用自己的用户路径 environment: - DISPLAY=unix$DISPLAY - XMODIFIERS=@im=fcitx # 中文输入,这里根据系统输入法类型自行输入,默认是IBus - QT_IM_MODULE=fcitx - GTK_IM_MODULE=fcitx - AUDIO_GID=29 # 可选 默认63(fedora) 主机audio gid 解决声音设备访问权限问题 - GID=$GID # 可选 默认1000 主机当前用户 gid 解决挂载目录访问权限问题 - UID=$UID # 可选 默认1000 主机当前用户 uid 解决挂载目录访问权限问题
运行:
具体介绍参考:开源项目 docker-qq
更换Docker
数据挂载目录 默认安装docker
将会使用/var/lib/docker
作为数据存放目录,可以新增额外的数据盘,以减少对根分区(/
)或者动态数据存储分区(/var
)的空间占用。1 2 3 4 5 6 mkdir -p ~/Dates/dockersudo cp -r /var/lib/docker/* ~/Dates/docker ln -s /home/你自己用户名/docker_dates/ /var/lib/docker
参考资料: 1、在Debian上安装 2、Docker安装微信 3、【简记】修改Docker数据目录位置,包含镜像位置