1. docker run 不使用缓存

  1. docker build --no-cache -t u12_core -f u12_core .

2. 从 host 拷贝文件到 Docker 容器里面

  1. docker cp foo.txt mycontainer:/foo.txt
  2. docker cp mycontainer:/foo.txt foo.txt

3. Docker 访问宿主机所在网络的其他机器

  1. docker run --net host image

4. 带环境变量运行容器

  1. docker run -e MYVAR1 --env MYVAR2=foo --env-file ./env.list ubuntu bash

5. Docker 启动时报错:iptables:No chain/target/match by the name

重启可以解决

6. centos 7 Docker容器启动报WARNING: IPv4 forwarding is disabled. Networking will not work

  1. # vi /usr/lib/sysctl.d/00-system.conf

添加如下代码:

  1. net.ipv4.ip_forward=1

7. 配置 Docker Daemon Http Proxy

  1. [root@liqiang.io]# mkdir -p /etc/systemd/system/docker.service.d
  2. [root@liqiang.io]# cat /etc/systemd/system/docker.service.d/http-proxy.conf
  3. [Service]
  4. Environment="HTTP_PROXY=http://192.168.1.1:8118/"
  5. Environment="HTTPS_PROXY=http://192.168.1.1:8118/"
  6. [root@liqiang.io]# systemctl daemon-reload
  7. [root@liqiang.io]# systemctl restart docker

8. 清理 docker

9. 不支持 overlay 存储引擎

在构建 Image 的时候报错:

  1. [root@liqiang.io]# docker build -t xxxx:xxx .
  2. ... ...
  3. => ERROR [2/6] RUN mkdir /code &&apt-get update &&apt-get -y install freetds-dev &&apt-get -y install unixodbc-dev 0.1s
  4. ------
  5. > [2/6] RUN mkdir /code &&apt-get update &&apt-get -y install freetds-dev &&apt-get -y install unixodbc-dev:
  6. ------
  7. failed to solve with frontend dockerfile.v0: failed to build LLB: executor failed running [/bin/sh -c mkdir /code &&apt-get update &&apt-get -y install freetds-dev &&apt-get -y install unixodbc-dev]: error creating overlay mount to /mnt/win-disk/overlay/criu9p4195qcmlve53c6iiqsm/merged: invalid argument
  8. make: *** [docker] Error 1

解决方式:修改存储引擎:

  1. [root@liqiang.io]# echo "fix wrong driver"
  2. [root@liqiang.io]# echo '{ "storage-driver": "devicemapper" }' | sudo tee /etc/docker/daemon.json
  3. [root@liqiang.io]# systemctl restart docker.service
  4. [root@liqiang.io]# echo "fix aliyun buggy selinux"
  5. [root@liqiang.io]# sed -i 's/SELINUXTYPE=mcs/SELINUXTYPE=targeted/' /etc/selinux/config