快速导航
- 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构建时替换为国内源
- centos安装docker使用aliyun源
Docker-Compose
重新创建
1docker-compose up --force-recreate --build -d api0
更新镜像
1docker-compose pull memos
2docker-compose up -d --remove-orphans memos
ubuntu安装docker
基本安装方式在官方文档里有写,无奈使用官方镜像源速度太慢,改为使用国内镜像
1curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
2apt-key fingerprint 0EBFCD88
3add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
1apt-get install docker-ce docker-ce-cli containerd.io
docker删除硬盘残留的文件
使用 docker rmi ... 或者 docker image rm ... 并不能将镜像完全删除,还会一直占用硬盘空间
1docker system prune
1docker volume prune
该命令不会删除已存在镜像(不管是否正在运行)
(硬盘一下子多个好几个G, 心情不错)
docker构建时禁用缓存
dockerfile 中有多个 RUN 或者 ADD .. 命令时, 每个 RUN 都会创建一个 image, 下一个 image 会以上一个为基础(缓存)继续构建,
可以使用 docker images -a 看到很多 <none> 的 image
不过作为一名有洁癖的coder, 这种情况不能忍
1docker build --no-cache -t hello .
docker配置国内源
1{
2 "registry-mirrors": [
3 "https://mirror.ccs.tencentyun.com",
4 "http://registry.docker-cn.com",
5 "http://docker.mirrors.ustc.edu.cn",
6 "http://hub-mirror.c.163.com"
7 ],
8 "debug": true,
9 "experimental": false,
10 "insecure-registries": [
11 "registry.docker-cn.com",
12 "docker.mirrors.ustc.edu.cn",
13 "test-cdn-chengdu-office5:5000",
14 "registry.k8s.cloud"
15 ]
16}
docker权限
1nginx:
2 cap_add:
3 - NET_ADMIN
4 - SYS_PTRACE
常见问题FAQ
centos安装docker使用aliyun源
https://docs.docker.com/install/linux/docker-ce/centos/
1yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
docker无法pull镜像
-
现象 ping docker.io 不通 curl https://docker.io
1docker pull myregistry.local:5000/testing/test-image或者配置默认的docker仓库 https://www.jianshu.com/p/1a4025c5f186
ubuntu
1vi /etc/default/docker1DOCKER_OPTS="$DOCKER_OPTS --registry-mirror=https://xxxxx.mirror.aliyuncs.com"然后重启docker
docker挂载磁盘后文件不可写
https://stackoverflow.com/questions/35760760/writable-folder-permissions-in-docker
1chmod a+rwx -R dir/
pip安装docker-compose时无法安装subprocess32
1ERROR: 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安装方式为
1yum -y install epel-release
2yum install python-pip
3# or yum install python2-pip
error storing credentials - err: exit status 1
1root@ubuntu:~/kunpeng# docker login registry.k8s.cloud
2Username: jsl
3Password:
4Error 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 环境变量
1ENV LANG "C.UTF-8"
docker内部apt update时At least one invalid signature was encountered
1W: GPG error: http://archive.ubuntu.com/ubuntu bionic InRelease: At least one invalid signature was encountered.
2E: The repository 'http://archive.ubuntu.com/ubuntu bionic InRelease' is not signed.
3W: GPG error: http://archive.ubuntu.com/ubuntu bionic-updates InRelease: At least one invalid signature was encountered.
4E: The repository 'http://archive.ubuntu.com/ubuntu bionic-updates InRelease' is not signed.
这是因为docker所需磁盘空间不足,mac下可通过ui调整docker磁盘大小,或者使用清理docker镜像
1docker image prune
2docker container prune
docker info显示Backing Filesystem 为 <unknown>
1Client:
2 Debug Mode: false
3
4Server:
5 Containers: 64
6 Running: 59
7 Paused: 0
8 Stopped: 5
9 Images: 39
10 Server Version: 19.03.8
11 Storage Driver: overlay2
12 Backing Filesystem: <unknown>
13 Supports d_type: true
14 ...
需要升级docker版本
1yum list docker-ce --showduplicates | sort -r
2yum 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
1[root@k8s-node-07 ~]# docker inspect registry.k8s.cloud/jsl-oms-client:dev4
2[]
3Error response from daemon: readlink /var/lib/docker/overlay2/l: invalid argument
Docker构建时替换为国内源
-
alpine
1sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories -
debian
1sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list
知识共享署名-非商业性使用-相同方式共享4.0国际许可协议