跳转至

Docker Tips#

Docker#

  1. Remove all exited containers

    docker rm `docker ps -aq`
    
  2. Update restart policy

    docker update --restart=always <container>
    
  3. Before deployment, ensure that Docker's configuration file /etc/docker/daemon.json is ready, including mirror site, log rotation and many other useful settings.

    {
        "data-root": "/docker",
        "registry-mirrors": [ "https://docker.mirrors.ustc.edu.cn/" ],
        "bip": "10.200.0.1/24",
        "default-address-pools": [
            {"base":"10.201.0.0/16","size":24},
            {"base":"10.202.0.0/16","size":24}
        ],
        "log-driver": "json-file",
        "log-opts": {
            "max-size": "5g",
            "max-file": "3"
        }
    }
    

Dockerfile#

Init Alpine Container#

# Add a mirror site
RUN sed -i 's@dl-cdn.alpinelinux.org@mirrors.aliyun.com@g' /etc/apk/repositories

# Change TimeZone
RUN apk update \
    && apk add --no-cache tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && echo "Asia/Shanghai" > /etc/timezone \
    && apk del tzdata

# Change the pip mirror
RUN pip3 config set global.index-url https://mirrors.aliyun.com/simple
RUN pip3 install --upgrade pip3