[docker] 一、入门
作者:解琛
时间:2020 年 12 月 8 日
【docker】查看docker容器或镜像的详细信息命令,查看docker中正在运行的容器的挂载位置
Docker查看本地所有的镜像命令(docker images)
Install Docker Engine on Ubuntu
一、基本指令
指令 | 说明 |
---|---|
docker ps | 查看正在运行中的容器列表,-a:列出所有; |
docker images | 查看本地所有镜像,-q:查看所有镜像的 id; |
docker inspect 容器或镜像ID | 查看容器的详细信息; |
docker-compose stop | 关闭容器; |
docker rm data_redmine_1 | 删除容器; |
systemctl daemon-reload | 重启 docker; |
systemctl restart docker | 重启 docker; |
二、常规操作
2.1 重启 docker
systemctl daemon-reload
systemctl restart docker
2.2 切换国内源
sudo vim /etc/docker/daemon.json
内容如下。
{
"registry-mirrors" : [
"http://ovfftd6p.mirror.aliyuncs.com",
"http://registry.docker-cn.com",
"http://docker.mirrors.ustc.edu.cn",
"http://hub-mirror.c.163.com"
],
"insecure-registries" : [
"registry.docker-cn.com",
"docker.mirrors.ustc.edu.cn"
],
"debug" : true,
"experimental" : true
}
2.3 安装 docker
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
2.4 安装微信
sudo apt install docker.io
sudo systemctl enable --now docker
sudo service docker start
docker pull bestwu/wechat
# 记录下这个数值
getent group audio | cut -d: -f3
接下来要做的事情就是创建一个 yml 配置文件用来每次启动 wechat。
vim docker-wechat.yaml
version: '2'
services:
wechat:
image: bestwu/wechat
container_name: wechat
devices:
- /dev/snd
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix
- $HOME/WeChatFiles:/WeChatFiles
environment:
- DISPLAY=unix$DISPLAY
- QT_IM_MODULE=fcitx
- XMODIFIERS=@im=fcitx
- GTK_IM_MODULE=fcitx
- AUDIO_GID=29 # 可选 默认63(fedora) 主机audio gid 解决声音设备访问权限问题
- GID=1000 # 可选 默认1000 主机当前用户 gid 解决挂载目录访问权限问题
- UID=1000 # 可选 默认1000 主机当前用户 uid 解决挂载目录访问权限问题
使用 docker-compose 启动容器。
docker-compose -f start.yaml up --build -d
三、问题
3.1 Failed to start docker.service: Unit docker.service is masked.
Docker安装完启动时提示Failed to start docker.service: Unit docker.service is masked.
systemctl unmask docker.service
systemctl unmask docker.socket
systemctl start docker.service
出现如下报错。
xiechen@xiechen-Ubuntu:~$ systemctl status docker.service
● docker.service - LSB: Create lightweight, portable, self-sufficient containers.
Loaded: loaded (/etc/init.d/docker; generated)
Active: failed (Result: exit-code) since Mon 2020-12-07 16:29:00 CST; 9s ago
Docs: man:systemd-sysv-generator(8)
Process: 3212 ExecStart=/etc/init.d/docker start (code=exited, status=1/FAILURE)
12月 07 16:29:00 xiechen-Ubuntu systemd[1]: Starting LSB: Create lightweight, portable, self-sufficient containers....
12月 07 16:29:00 xiechen-Ubuntu docker[3212]: * /usr/bin/dockerd not present or not executable
12月 07 16:29:00 xiechen-Ubuntu systemd[1]: docker.service: Control process exited, code=exited status=1
12月 07 16:29:00 xiechen-Ubuntu systemd[1]: docker.service: Failed with result 'exit-code'.
12月 07 16:29:00 xiechen-Ubuntu systemd[1]: Failed to start LSB: Create lightweight, portable, self-sufficient containers..
直接重新安装一下。
sudo apt install docker.io
sudo systemctl start docker
sudo systemctl enable docker
docker container ls --all