参考书籍:
《Docker - 从入门到实践(v1.2.0)》 - 书栈网 · BookStack
- 安装docker
curl -fsSL get.docker.com -o get-docker.sh
sudo sh get-docker.sh --mirror Aliyun
- 配置docker用户,镜像加速
sudo groupadd docker
sudo usermod -aG docker $USER
# 镜像加速
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://registry.docker-cn.com", "https://hub-mirror.c.163.com", "https://g5ps9afu.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
网易云加速器 https://hub-mirror.c.163.com
百度云加速器 https://mirror.baidubce.com
- 拉取镜像
docker pull ubuntu:18.04
- 编写Dockerfile
FROM ubuntu:18.04
RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse" > /etc/apt/sources.list \
&& echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse" >> /etc/apt/sources.list \
&& echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse" >> /etc/apt/sources.list \
&& echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse" >> /etc/apt/sources.list \
&& apt-get update \
&& apt-get install ttf-wqy-zenhei fonts-wqy-microhei -y \
&& apt-get install libreoffice -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
#############################################################
FROM centos:7
RUN sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \
-i.bak /etc/yum.repos.d/CentOS-*.repo \
&& yum makecache \
&& yum install libreoffice google-noto-sans-simplified-chinese-fonts -y \
&& yum clean all
- 创建镜像
docker build -t office .
- 创建容器,进入docker
docker run -it --rm office
- 导出镜像
docker save office | xz > office-last.tar.xz
或者
docker save office | gzip > office-last.tar.gz
- 导入镜像
docker load -i office-last.tar.xz
或者
docker load -i office-last.tar.gz
- docker 无法补全
yum install -y bash-completion
source /usr/share/bash-completion/completions/docker
source /usr/share/bash-completion/bash_completion
WSL无法启动centos6容器
-
在
%UserProfile%
目录下创建.wslconfig
文件,填入以下内容[wsl2] kernelCommandLine = vsyscall=emulate