Docker 常见问题


1、镜像下载慢,如何提高下载速度?

  1. touch /etc/docker/daemon.json
  2. cat >> /etc/docker/daemon.json <<EOF
  3. {
  4. "insecure-registries": ["0.0.0.0/0"],
  5. "registry-mirrors": ["https://7bezldxe.mirror.aliyuncs.com"]
  6. }
  7. EOF
  8. systemctl daemon-reload && systemctl restart docker
  1. PS:0.0.0.0/0 表示信任所有非https地址的镜像仓库,对于内网测试,这样配置很方便。对于线上生产环境,
  2. 为了安全请不要这样配置

2、如何配置Docker后端存储驱动?

以overlay为例

  1. touch /etc/docker/daemon.json
  2. cat >> /etc/docker/daemon.json <<EOF
  3. {
  4. "storage-driver": "overlay"
  5. }
  6. EOF
  7. systemctl daemon-reload && systemctl restart docker

3、docker info 出现 WARNING

  1. WARNING: No swap limit support
  2. WARNING: No kernel memory limit support
  3. WARNING: No oom kill disable support

编辑/etc/default/grub 文件,并设置:GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"

接着

SUSE

  1. grub2-mkconfig -o /boot/grub2/grub.cfg

Cetos

  1. Update grub

Ubuntu

  1. update-grub

4、我怎么通过rancher让docker里的程序代理上网呢?

启动容器的时候添加:

  1. -e http_proxy= -e https_proxy=

proxy

5、Docker Error: Unable to remove filesystem

Some container-based utilities, such as Google cAdvisor, mount Docker system directories, such as /var/lib/docker/, into a container. For instance, the documentation for cadvisor instructs you to run the cadvisor container as follows:

  1. $ sudo docker run \
  2. --volume=/:/rootfs:ro \
  3. --volume=/var/run:/var/run:rw \
  4. --volume=/sys:/sys:ro \
  5. --volume=/var/lib/docker/:/var/lib/docker:ro \
  6. --publish=8080:8080 \
  7. --detach=true \
  8. --name=cadvisor \
  9. google/cadvisor:latest

When you bind-mount /var/lib/docker/, this effectively mounts all resources of all other running containers as filesystems within the container which mounts /var/lib/docker/. When you attempt to remove any of these containers, the removal attempt may fail with an error like the following:

  1. Error: Unable to remove filesystem for
  2. 74bef250361c7817bee19349c93139621b272bc8f654ae112dd4eb9652af9515:
  3. remove /var/lib/docker/containers/74bef250361c7817bee19349c93139621b272bc8f654ae112dd4eb9652af9515/shm:
  4. Device or resource busy

The problem occurs if the container which bind-mounts /var/lib/docker/ uses statfsor fstatfs on filesystem handles within /var/lib/docker/ and does not close them.

Typically, we would advise against bind-mounting /var/lib/docker in this way. However, cAdvisor requires this bind-mount for core functionality.

If you are unsure which process is causing the path mentioned in the error to be busy and preventing it from being removed, you can use the lsof command to find its process. For instance, for the error above:

  1. sudo lsof /var/lib/docker/containers/74bef250361c7817bee19349c93139621b272bc8f65