分类 docker 下的文章

安装命令

sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo systemctl enable docker

设置registry-mirrors

vim /etc/docker/daemon.json,添加以下内容:

{
    "registry-mirrors": [
        "https://xxx.mirror.xxx.com"
    ]
}

重启服务

sudo systemctl daemon-reload
sudo systemctl restart docker

cat /dev/null > /etc/apt/sources.list

Debian 11 修改sources.list

cat <<EOT >> /etc/apt/sources.list
deb http://mirrors.ustc.edu.cn/debian/ bullseye main contrib non-free
deb-src http://mirrors.ustc.edu.cn/debian/ bullseye main contrib non-free
  
deb http://mirrors.ustc.edu.cn/debian/ bullseye-updates main contrib non-free
deb-src http://mirrors.ustc.edu.cn/debian/ bullseye-updates main contrib non-free
  
deb http://mirrors.ustc.edu.cn/debian/ bullseye-backports main contrib non-free
deb-src http://mirrors.ustc.edu.cn/debian/ bullseye-backports main contrib non-free
  
deb http://mirrors.ustc.edu.cn/debian-security/ bullseye-security main contrib non-free
deb-src http://mirrors.ustc.edu.cn/debian-security/ bullseye-security main contrib non-free
EOT

Debian 12 修改sources.list

cat <<EOT >> /etc/apt/sources.list
deb https://mirrors.aliyun.com/debian bookworm main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian bookworm main non-free non-free-firmware contrib

deb https://mirrors.aliyun.com/debian bookworm-updates main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian bookworm-updates main non-free non-free-firmware contrib

deb https://mirrors.aliyun.com/debian bookworm-proposed-updates main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian bookworm-proposed-updates main non-free non-free-firmware contrib

deb https://mirrors.aliyun.com/debian bookworm-backports main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian bookworm-backports main non-free non-free-firmware contrib

deb https://mirrors.aliyun.com/debian bookworm-backports-sloppy main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian bookworm-backports-sloppy main non-free non-free-firmware contrib

deb https://mirrors.aliyun.com/debian-security bookworm-security main non-free non-free-firmware contrib
deb-src https://mirrors.aliyun.com/debian-security bookworm-security main non-free non-free-firmware contrib
EOT

修改时区

1)sudo dpkg-reconfigure tzdata
2)timedatectl set-timezone Asia/Shanghai
3)echo Asia/Shanghai > /etc/timezone && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

安装常用工具

apt update
apt install -y procps telnet inetutils-ping net-tools vim wget
apt clean

Ubuntu修改时区

FROM ubuntu:latest
 
ENV TZ=Asia/Shanghai
 
RUN apt-get update && apt-get install -y tzdata
RUN echo ${TZ} > /etc/timezone && ln -sf /usr/share/zoneinfo/${TZ} /etc/localtime && dpkg-reconfigure -f noninteractive tzdata

修改repositories

sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

修改时区

apk add tzdata
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo Asia/Shanghai  > /etc/timezone
apk del tzdata

示例

FROM test.com/base/openjdk:8-jdk-alpine

ENV WORKSPACE=/app TZ=Asia/Shanghai

CMD mkdir ${WORKSPACE}
WORKDIR ${WORKSPACE}

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
    apk --update add --no-cache ttf-dejavu fontconfig tzdata tini curl bash wget busybox-extras bind-tools tcpdump net-tools && \
    cp /usr/share/zoneinfo/${TZ} /etc/localtime && \
    echo ${TZ} > /etc/timezone && \
    rm -rf /var/cache/apk/*

COPY app.jar app.jar

EXPOSE 8080

CMD /sbin/tini -- java -Djava.security.egd=file:/dev/./urandom ${SW_AGENT_OPTS} ${JAVA_OPTS} -jar /app/app.jar ${SPRING_OPTS}

删除镜像

docker rmi $(docker images | grep -E 'harbor.xxx.com/(qa|dev|prod)/' | awk -v OFS=":" '{print $1,$2}')

删除k8s中Evicted状态的pod

kubectl get po -A | grep 'Evicted' | awk 'NR>0 {print "kubectl delete po -n " $1,$2}' | bash

查看docker space

# overlay2无thin pool,devicemapper有thin pool。
docker info | grep Space

查看镜像和容器的空间

docker system df -v 或 docker system df -v | grep GB

虚机:

  • 添加中文

    yum install kde-l10n-Chinese -y

  • 转化语言环境和字符集

    localedef -c -f UTF-8 -i zh_CN zh_CN.utf8

  • 添加定义到系统环境变量

    vi /etc/profile export LC_ALL=zh_CN.utf8

  • 执行生效

    source /etc/profile

Dockerfile

ENV LC_ALL=zh_CN.UTF-8
RUN yum install kde-l10n-Chinese -y && localedef -c -f UTF-8 -i zh_CN zh_CN.utf8