Table of Contents
- Docker-Compose
- ubuntu安装docker
- docker删除硬盘残留的文件
- docker构建时禁用缓存
- docker配置国内源
- docker权限
- 常见问题FAQ
- centos安装docker使用aliyun源
- docker无法pull镜像
- docker挂载磁盘后文件不可写
- pip安装docker-compose时无法安装subprocess32
- error storing credentials - err: exit status 1
- UnicodeEncodeError: 'ascii' codec can't encode character 'u4eac' in position 14: ordinal not in range(128)
- docker内部apt update时At least one invalid signature was encountered
- docker info显示Backing Filesystem 为 <unknown>
- Error response from daemon: readlink /var/lib/docker/overlay2/l: invalid argument
- Docker构建时替换为国内源
Docker-Compose
重新创建
docker-compose up --force-recreate --build -d api0
更新镜像
docker-compose pull memos docker-compose up -d --remove-orphans memos
ubuntu安装docker
基本安装方式在官方文档里有写,无奈使用官方镜像源速度太慢,改为使用国内镜像
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - apt-key fingerprint 0EBFCD88 add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
apt-get install docker-ce docker-ce-cli containerd.io
docker删除硬盘残留的文件
使用 docker rmi ...
或者 docker image rm ...
并不能将镜像完全删除,还会一直占用硬盘空间
docker system prune
docker volume prune
该命令不会删除已存在镜像(不管是否正在运行)
(硬盘一下子多个好几个G, 心情不错)
docker构建时禁用缓存
dockerfile 中有多个 RUN 或者 ADD .. 命令时, 每个 RUN 都会创建一个 image, 下一个 image 会以上一个为基础(缓存)继续构建,
可以使用 docker images -a
看到很多 <none> 的 image
不过作为一名有洁癖的coder, 这种情况不能忍
docker build --no-cache -t hello .
docker配置国内源
{ "registry-mirrors": [ "https://mirror.ccs.tencentyun.com", "http://registry.docker-cn.com", "http://docker.mirrors.ustc.edu.cn", "http://hub-mirror.c.163.com" ], "debug": true, "experimental": false, "insecure-registries": [ "registry.docker-cn.com", "docker.mirrors.ustc.edu.cn", "test-cdn-chengdu-office5:5000", "registry.k8s.cloud" ] }
docker权限
nginx: cap_add: - NET_ADMIN - SYS_PTRACE
常见问题FAQ
centos安装docker使用aliyun源
https://docs.docker.com/install/linux/docker-ce/centos/
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
docker无法pull镜像
-
现象 ping docker.io 不通 curl https://docker.io
docker pull myregistry.local:5000/testing/test-image
或者配置默认的docker仓库 https://www.jianshu.com/p/1a4025c5f186
ubuntu
vi /etc/default/docker
DOCKER_OPTS="$DOCKER_OPTS --registry-mirror=https://xxxxx.mirror.aliyuncs.com"
然后重启docker
docker挂载磁盘后文件不可写
https://stackoverflow.com/questions/35760760/writable-folder-permissions-in-docker
chmod a+rwx -R dir/
pip安装docker-compose时无法安装subprocess32
ERROR: Command errored out with exit status 1: /usr/bin/python2 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-oX9c4h/subprocess32/setup.py'"'"'; __file__='"'"'/tmp/pip-install-oX9c4h/subprocess32/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-bccCWb/install-record.txt --single-version-externally-managed --compile --user --prefix= Check the logs for full command output.
一般情况下是由于docker-compose不支持python2导致的,需要在机器上安装python3 centos可直接使用yum安装docker-compose, python3作为依赖会自动安装
注: pip安装方式为
yum -y install epel-release yum install python-pip # or yum install python2-pip
error storing credentials - err: exit status 1
root@ubuntu:~/kunpeng# docker login registry.k8s.cloud Username: jsl Password: Error saving credentials: error storing credentials - err: exit status 1, out: `Cannot autolaunch D-Bus without X11 $DISPLAY`
UnicodeEncodeError: 'ascii' codec can't encode character 'u4eac' in position 14: ordinal not in range(128)
docker 内部使用python是编码问题, 需要设置 LANG
环境变量
ENV LANG "C.UTF-8"
docker内部apt update时At least one invalid signature was encountered
W: GPG error: http://archive.ubuntu.com/ubuntu bionic InRelease: At least one invalid signature was encountered. E: The repository 'http://archive.ubuntu.com/ubuntu bionic InRelease' is not signed. W: GPG error: http://archive.ubuntu.com/ubuntu bionic-updates InRelease: At least one invalid signature was encountered. E: The repository 'http://archive.ubuntu.com/ubuntu bionic-updates InRelease' is not signed.
这是因为docker所需磁盘空间不足,mac下可通过ui调整docker磁盘大小,或者使用清理docker镜像
docker image prune docker container prune
docker info显示Backing Filesystem 为 <unknown>
Client: Debug Mode: false Server: Containers: 64 Running: 59 Paused: 0 Stopped: 5 Images: 39 Server Version: 19.03.8 Storage Driver: overlay2 Backing Filesystem: <unknown> Supports d_type: true ...
需要升级docker版本
yum list docker-ce --showduplicates | sort -r yum install docker-ce-19.03.9-3.el7 docker-ce-cli-19.03.9-3.el7
Error response from daemon: readlink /var/lib/docker/overlay2/l: invalid argument
[root@k8s-node-07 ~]# docker inspect registry.k8s.cloud/jsl-oms-client:dev4 [] Error response from daemon: readlink /var/lib/docker/overlay2/l: invalid argument
Docker构建时替换为国内源
-
alpine
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
-
debian
sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list