├── .gitignore ├── LICENSE ├── README.md ├── dockerfiles ├── alpine │ └── Dockerfile ├── code │ ├── Dockerfile │ ├── README.md │ └── docker-entrypoint.sh ├── edrawmax │ ├── Dockerfile │ ├── docker-entrypoint.sh │ └── run.sh ├── gitlab │ └── docker-compose.yml ├── gosu │ ├── Dockerfile │ ├── README.md │ └── docker-entrypoint.sh ├── jenkins-gitlab │ └── docker-compose.yml ├── jenkins │ └── docker-compose.yml ├── miniconda │ └── Dockerfile ├── nginx │ └── docker-compose.yml ├── qq │ ├── Dockerfile │ ├── README.md │ ├── deepin.com.qq.im.desktop │ ├── docker-entrypoint.sh │ ├── hicolor │ │ ├── 16x16 │ │ │ └── apps │ │ │ │ └── deepin.com.qq.im.svg │ │ ├── 24x24 │ │ │ └── apps │ │ │ │ └── deepin.com.qq.im.svg │ │ ├── 32x32 │ │ │ └── apps │ │ │ │ └── deepin.com.qq.im.svg │ │ ├── 48x48 │ │ │ └── apps │ │ │ │ └── deepin.com.qq.im.svg │ │ └── 64x64 │ │ │ └── apps │ │ │ └── deepin.com.qq.im.svg │ └── qq.sh ├── sshd │ ├── Dockerfile │ └── README.md ├── system_mirror │ ├── Dockerfile │ ├── Dockerfile.en_US │ └── sources.list ├── thunder │ ├── Dockerfile │ ├── README.md │ ├── deepin.com.thunderspeed.desktop │ ├── docker-entrypoint.sh │ ├── hicolor │ │ ├── 16x16 │ │ │ └── apps │ │ │ │ └── deepin.com.thunderspeed.svg │ │ ├── 24x24 │ │ │ └── apps │ │ │ │ └── deepin.com.thunderspeed.svg │ │ ├── 32x32 │ │ │ └── apps │ │ │ │ └── deepin.com.thunderspeed.svg │ │ ├── 48x48 │ │ │ └── apps │ │ │ │ └── deepin.com.thunderspeed.svg │ │ └── 64x64 │ │ │ └── apps │ │ │ └── deepin.com.thunderspeed.svg │ └── thunder.sh ├── tim │ ├── Dockerfile │ ├── README.md │ ├── deepin.com.qq.office.desktop │ ├── docker-entrypoint.sh │ ├── hicolor │ │ ├── 16x16 │ │ │ └── apps │ │ │ │ └── deepin.com.qq.office.svg │ │ ├── 24x24 │ │ │ └── apps │ │ │ │ └── deepin.com.qq.office.svg │ │ ├── 32x32 │ │ │ └── apps │ │ │ │ └── deepin.com.qq.office.svg │ │ ├── 48x48 │ │ │ └── apps │ │ │ │ └── deepin.com.qq.office.svg │ │ └── 64x64 │ │ │ └── apps │ │ │ └── deepin.com.qq.office.svg │ └── tim.sh ├── ubuntu │ ├── Dockerfile │ ├── docker-compose.yml │ └── sources.list ├── wechat │ ├── Dockerfile │ ├── README.md │ ├── deepin.com.wechat.desktop │ ├── docker-entrypoint.sh │ ├── hicolor │ │ ├── 16x16 │ │ │ └── apps │ │ │ │ └── deepin.com.wechat.svg │ │ ├── 24x24 │ │ │ └── apps │ │ │ │ └── deepin.com.wechat.svg │ │ ├── 32x32 │ │ │ └── apps │ │ │ │ └── deepin.com.wechat.svg │ │ ├── 48x48 │ │ │ └── apps │ │ │ │ └── deepin.com.wechat.svg │ │ └── 64x64 │ │ │ └── apps │ │ │ └── deepin.com.wechat.svg │ └── wechat.sh └── wps │ ├── Dockerfile │ ├── README.md │ ├── desktop.zip │ ├── docker-entrypoint.sh │ ├── et.sh │ ├── pdf.sh │ ├── wpp.sh │ ├── wps.sh │ └── wps_symbol_fonts.zip ├── docs ├── Travis-CI.md ├── docker │ ├── advanced │ │ ├── [Docker][SSH]远程登录Ubuntu.md │ │ ├── [Ubuntu]nvidia-docker安装.md │ │ ├── [alpine]源配置.md │ │ ├── [docker search]搜索镜像.md │ │ ├── [译]Docker开发最佳实践.md │ │ ├── imgs │ │ │ ├── diff_dev_prod.png │ │ │ ├── docker-nvidia.png │ │ │ ├── go-format.png │ │ │ └── match_rule.png │ │ ├── 编写.dockerignore.md │ │ └── 镜像迁移.md │ ├── basic │ │ ├── Docker启动设置.md │ │ ├── [Aliyun]镜像加速.md │ │ ├── [Docker]DNS设置.md │ │ ├── [Docker][Ubuntu 18.04]中文环境配置.md │ │ ├── [docker commit]保存容器为镜像.md │ │ ├── [译]docker概述.md │ │ ├── docker-hub使用.md │ │ ├── docker定位.md │ │ ├── hello-world.md │ │ ├── imgs │ │ │ ├── Container@2x.png │ │ │ ├── VM@2x.png │ │ │ ├── architecture.svg │ │ │ ├── commit-options.png │ │ │ ├── engine-components-flow.png │ │ │ └── laurel-docker-containers.png │ │ ├── 可选设置.md │ │ ├── 安装.md │ │ └── 镜像和容器.md │ ├── compose │ │ ├── Compose安装.md │ │ ├── Compose文件格式 - Service设置.md │ │ ├── Compose文件格式 - 存储设置.md │ │ ├── Compose文件格式概述.md │ │ ├── Compose版本依赖.md │ │ ├── [译]Docker Compose概述.md │ │ ├── imgs │ │ │ └── compose-docker.png │ │ ├── 使用Docker Compose构建镜像.md │ │ └── 使用docker-compose还是docker run.md │ ├── dockerfile │ │ ├── ADD和COPY.md │ │ ├── ARG.md │ │ ├── CMD.md │ │ ├── Dockerfile编写.md │ │ ├── ENTRYPOINT.md │ │ ├── ENV.md │ │ ├── EXPOSE.md │ │ ├── FROM.md │ │ ├── LABEL.md │ │ ├── RUN.md │ │ ├── SHELL.md │ │ ├── WORKDIR.md │ │ ├── [译]Dockerfile编写最佳实践.md │ │ ├── imgs │ │ │ └── cmd-entrypoint.png │ │ └── 多阶段构建.md │ ├── faq.rst │ ├── faq │ │ ├── docker build运行apt-get update失败.md │ │ ├── service启动docker失效.md │ │ ├── 安装g++出错.md │ │ └── 安装git出错.md │ ├── gui │ │ ├── [Docker]GUI最佳实践.md │ │ ├── [Docker][Ubuntu 18.04]deepin-wine制作.md │ │ ├── [Docker][Ubuntu]Edraw安装.md │ │ ├── [Docker][Ubuntu]Libreoffice运行.md │ │ ├── [Docker][Ubuntu]WPS运行.md │ │ ├── [Docker][Ubuntu]vscode运行.md │ │ ├── [Docker][deepin-wine]QQ运行.md │ │ ├── [Docker][deepin-wine]TIM运行.md │ │ ├── [Docker][deepin-wine]微信运行.md │ │ ├── [Docker][deepin-wine]迅雷运行.md │ │ └── imgs │ │ │ ├── edrawmax.png │ │ │ ├── libreoffice.png │ │ │ ├── qq-begin.png │ │ │ ├── qq-starter.png │ │ │ ├── thunder.png │ │ │ ├── tim.png │ │ │ ├── wechat-starter.png │ │ │ ├── wps-a.png │ │ │ ├── wps-china-restart.png │ │ │ ├── wps-china.png │ │ │ ├── wps-lack.png │ │ │ ├── wps-starter.png │ │ │ ├── wps.png │ │ │ └── wps2.png │ └── storage │ │ ├── [docker volume]创建和管理卷.md │ │ ├── [gosu]绑定挂载最佳实践.md │ │ ├── [volume][bind mount]bind propagation设置.md │ │ ├── [volume][bind mount]标识符-v和--mount解析.md │ │ ├── [译]在Docker中管理数据.md │ │ ├── imgs │ │ ├── propagation-options.png │ │ ├── types-of-mounts-bind.png │ │ ├── types-of-mounts-volume.png │ │ ├── types-of-mounts.png │ │ └── volumes-shared-storage.svg │ │ ├── 使用卷管理数据.md │ │ └── 绑定挂载.md ├── index.md └── jenkins.md ├── mkdocs.yml └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | 3 | node_modules/ 4 | 5 | docs/build/ 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 本仓库不再维护,更新的内容前往:[ZJDoc/Deploy](https://github.com/ZJDoc/Deploy) 2 | 3 | # Containerization-Automation 4 | 5 | [![Documentation Status](https://readthedocs.org/projects/containerization-automation/badge/?version=latest)](https://containerization-automation.readthedocs.io/zh_CN/latest/?badge=latest) [![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme) [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org) [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/) 6 | 7 | > 容器化与自动化 8 | 9 | 学习、使用容器以及自动化工具。当前有: 10 | 11 | 1. [Jenkins](https://containerization-automation.readthedocs.io/zh_CN/latest/jenkins/) 12 | 2. [Docker](https://containerization-automation.readthedocs.io/zh_CN/latest/docker/basic/[%E8%AF%91]docker%E6%A6%82%E8%BF%B0/) 13 | 14 | ## 内容列表 15 | 16 | - [本仓库不再维护,更新的内容前往:ZJDoc/Deploy](#本仓库不再维护更新的内容前往zjdocdeploy) 17 | - [Containerization-Automation](#containerization-automation) 18 | - [内容列表](#内容列表) 19 | - [背景](#背景) 20 | - [安装](#安装) 21 | - [文档工具安装](#文档工具安装) 22 | - [用法](#用法) 23 | - [主要维护人员](#主要维护人员) 24 | - [参与贡献方式](#参与贡献方式) 25 | - [许可证](#许可证) 26 | 27 | ## 背景 28 | 29 | 容器以及自动化工具的出现极大的加快了软件的生产步骤,同时能够有效解决复杂的依赖环境。看了`Docker`和`CI`工具的介绍,好好利用起来能得到一个很棒的开发环境,赶紧动起来!!! 30 | 31 | ## 安装 32 | 33 | ### 文档工具安装 34 | 35 | ``` 36 | $ pip install -r requirements.txt 37 | ``` 38 | 39 | ## 用法 40 | 41 | 有两种文档使用方式 42 | 43 | 1. 在线浏览文档:[Containers and Automation](https://containerization-automation.readthedocs.io/zh_CN/latest/?badge=latest) 44 | 45 | 2. 本地浏览文档,实现如下: 46 | 47 | ``` 48 | $ git clone https://github.com/zjZSTU/Containerization-Automation.git 49 | $ cd Containerization-Automation 50 | $ mkdocs serve 51 | ``` 52 | 启动本地服务器后即可登录浏览器`localhost:8000` 53 | 54 | ## 主要维护人员 55 | 56 | * zhujian - *Initial work* - [zjZSTU](https://github.com/zjZSTU) 57 | 58 | ## 参与贡献方式 59 | 60 | 欢迎任何人的参与!打开[issue](https://github.com/zjZSTU/Container-Automation/issues)或提交合并请求 61 | 62 | 注意: 63 | 64 | * `GIT`提交,请遵守[Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0-beta.4/)规范 65 | * 语义版本化,请遵守[Semantic Versioning 2.0.0](https://semver.org)规范 66 | * `README`编写,请遵守[standard-readme](https://github.com/RichardLitt/standard-readme)规范 67 | 68 | ## 许可证 69 | 70 | [Apache License 2.0](LICENSE) © 2019 zjZSTU 71 | -------------------------------------------------------------------------------- /dockerfiles/alpine/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:latest 2 | LABEL maintainer "zhujian " 3 | 4 | RUN set -eux && sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories 5 | -------------------------------------------------------------------------------- /dockerfiles/code/Dockerfile: -------------------------------------------------------------------------------- 1 | 2 | FROM zjzstu/ubuntu:18.04 3 | LABEL maintainer "zhujian " 4 | 5 | WORKDIR /app 6 | 7 | RUN set -eux && \ 8 | apt-get update && \ 9 | apt-get install -y libnotify4 libnss3 libxkbfile1 libsecret-1-0 libgtk-3-0 libxss1 libx11-xcb1 libasound2 ttf-wqy-microhei python3-pip curl wget gosu && \ 10 | # verify that the binary works 11 | gosu nobody true && \ 12 | # 下载安装包 13 | wget https://vscode.cdn.azure.cn/stable/b37e54c98e1a74ba89e03073e5a3761284e3ffb0/code_1.38.1-1568209190_amd64.deb && \ 14 | # 新建用户user,并修改安装包属主/属组 15 | useradd -s /bin/bash -m user && \ 16 | chown -R user:user /app && \ 17 | chmod a+x *.deb && \ 18 | dpkg -i code_1.38.1-1568209190_amd64.deb && \ 19 | apt-get install -f -y && \ 20 | # 删除 21 | rm code*.deb && \ 22 | apt-get autoclean -y && apt-get clean -y && \ 23 | find /var/lib/apt/lists -type f -delete && \ 24 | find /var/cache -type f -delete && \ 25 | find /var/log -type f -delete && \ 26 | find /usr/share/doc -type f -delete && \ 27 | find /usr/share/man -type f -delete 28 | 29 | COPY docker-entrypoint.sh ./ 30 | RUN chmod a+x docker-entrypoint.sh && \ 31 | chown user:user docker-entrypoint.sh 32 | ENTRYPOINT ["/app/docker-entrypoint.sh"] 33 | -------------------------------------------------------------------------------- /dockerfiles/code/README.md: -------------------------------------------------------------------------------- 1 | 2 | 参考:[[Docker][Ubuntu]vscode运行](https://container-automation.readthedocs.io/zh_CN/latest/docker/gui/[Docker][Ubuntu]vscode%E8%BF%90%E8%A1%8C.html) -------------------------------------------------------------------------------- /dockerfiles/code/docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$(id -u)" -eq '0' ] 4 | then 5 | USER_ID=${LOCAL_USER_ID:-9001} 6 | usermod -u ${USER_ID} -g ${USER_ID} -a -G root user > /dev/null 2>&1 7 | 8 | export HOME=/home/user 9 | exec gosu user "$0" "$@" # > /dev/null 2>&1 10 | fi 11 | 12 | exec $@ > /dev/null 2>&1 13 | -------------------------------------------------------------------------------- /dockerfiles/edrawmax/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM zjzstu/ubuntu:18.04 2 | LABEL maintainer "zhujian " 3 | 4 | WORKDIR /app 5 | RUN set -eux && \ 6 | apt-get update && \ 7 | apt-get install -y wget gosu && \ 8 | gosu nobody true && \ 9 | apt-get install -y libglib2.0-dev libgl1 libnvidia-gl-435 libxcb-render-util0 libdbus-1-3 libxrender1 libfontconfig1 libxi6 && \ 10 | wget https://www.edrawsoft.cn/2download/edrawmax-9-amd64-cn.deb && \ 11 | useradd -s /bin/bash -m user && \ 12 | chown -R user:user /app && \ 13 | dpkg -i *.deb && \ 14 | rm -f *.deb && \ 15 | apt-get autoclean -y && apt-get clean -y && \ 16 | find /var/lib/apt/lists -type f -delete && \ 17 | find /var/cache -type f -delete && \ 18 | find /var/log -type f -delete && \ 19 | find /usr/share/doc -type f -delete && \ 20 | find /usr/share/man -type f -delete 21 | 22 | COPY docker-entrypoint.sh ./ 23 | RUN chmod a+x docker-entrypoint.sh && \ 24 | chown user:user docker-entrypoint.sh 25 | ENTRYPOINT ["/app/docker-entrypoint.sh"] -------------------------------------------------------------------------------- /dockerfiles/edrawmax/docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$(id -u)" -eq '0' ] 4 | then 5 | USER_ID=${LOCAL_USER_ID:-9001} 6 | 7 | chown -R ${USER_ID} /app 8 | usermod -u ${USER_ID} user 9 | usermod -a -G root user 10 | 11 | export HOME=/home/user 12 | exec gosu user "$0" "$@" 13 | fi 14 | 15 | exec "$@" -------------------------------------------------------------------------------- /dockerfiles/edrawmax/run.sh: -------------------------------------------------------------------------------- 1 | docker run \ 2 | --rm -it \ 3 | -v /tmp/.X11-unix:/tmp/.X11-unix \ 4 | -e DISPLAY=unix$DISPLAY \ 5 | --privileged \ 6 | -e XMODIFIERS="@im=fcitx" \ 7 | -e QT_IM_MODULE="fcitx" \ 8 | -e GTK_IM_MODULE="fcitx" \ 9 | -e GID=`id -g` \ 10 | -e UID=`id -u` \ 11 | --name edrawmax \ 12 | --gpus all \ 13 | -d \ 14 | zjzstu/edrawmax:latest \ 15 | edrawmax -------------------------------------------------------------------------------- /dockerfiles/gitlab/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | services: 3 | gitlab: 4 | labels: 5 | AUTHOR: "zhujian " 6 | container_name: gitlab 7 | image: gitlab/gitlab-ce:latest 8 | volumes: 9 | - "/srv/gitlab/config:/etc/gitlab" 10 | - "/srv/gitlab/logs:/var/log/gitlab" 11 | - "/srv/gitlab/data:/var/opt/gitlab" 12 | ports: 13 | - "7010:7010" 14 | - "7020:22" 15 | restart: always 16 | tty: true 17 | stdin_open: true -------------------------------------------------------------------------------- /dockerfiles/gosu/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM zjzstu/ubuntu:18.04 2 | LABEL maintainer "zhujian " 3 | 4 | WORKDIR /app 5 | RUN set -eux && \ 6 | apt-get update && \ 7 | apt-get install -y gosu && \ 8 | rm -rf /var/lib/apt/lists/* && \ 9 | # verify that the binary works 10 | gosu nobody true && \ 11 | useradd -s /bin/bash -m user 12 | 13 | COPY docker-entrypoint.sh . 14 | RUN chmod a+x docker-entrypoint.sh 15 | 16 | ENTRYPOINT ["/app/docker-entrypoint.sh"] 17 | -------------------------------------------------------------------------------- /dockerfiles/gosu/README.md: -------------------------------------------------------------------------------- 1 | 2 | 参考:[] -------------------------------------------------------------------------------- /dockerfiles/gosu/docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$(id -u)" -eq '0' ] 4 | then 5 | USER_ID=${LOCAL_USER_ID:-9001} 6 | 7 | usermod -u ${USER_ID} -g ${USER_ID} user > /dev/null 2>&1 8 | chown -R `id -u user`:`id -u user` /app > /dev/null 2>&1 9 | 10 | export HOME=/home/user 11 | exec gosu user "$0" "$@" 12 | fi 13 | 14 | exec "$@" -------------------------------------------------------------------------------- /dockerfiles/jenkins-gitlab/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | services: 3 | jenkins: 4 | labels: 5 | AUTHOR: "zhujian " 6 | container_name: jenkins 7 | image: jenkins/jenkins 8 | volumes: 9 | - "jenkins_home:/var/jenkins_home" 10 | ports: 11 | - "7070:8080" 12 | - "50000:50000" 13 | restart: always 14 | tty: true 15 | stdin_open: true 16 | gitlab: 17 | labels: 18 | AUTHOR: "zhujian " 19 | container_name: gitlab 20 | image: gitlab/gitlab-ce:latest 21 | volumes: 22 | - "/srv/gitlab/config:/etc/gitlab" 23 | - "/srv/gitlab/logs:/var/log/gitlab" 24 | - "/srv/gitlab/data:/var/opt/gitlab" 25 | ports: 26 | - "7010:7010" 27 | - "7020:22" 28 | restart: always 29 | tty: true 30 | stdin_open: true 31 | volumes: 32 | jenkins_home: 33 | external: true -------------------------------------------------------------------------------- /dockerfiles/jenkins/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | services: 3 | jenkins: 4 | labels: 5 | AUTHOR: "zhujian " 6 | container_name: jenkins 7 | image: jenkins/jenkins 8 | volumes: 9 | - "jenkins_home:/var/jenkins_home" 10 | ports: 11 | - "7070:8080" 12 | - "50000:50000" 13 | restart: always 14 | tty: true 15 | stdin_open: true 16 | volumes: 17 | jenkins_home: 18 | external: true -------------------------------------------------------------------------------- /dockerfiles/miniconda/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM zjzstu/ubuntu:18.04 2 | LABEL maintainer "zhujian " 3 | 4 | ENV PATH /opt/conda/bin:$PATH 5 | 6 | RUN set -eux && \ 7 | apt-get update --fix-missing && \ 8 | apt-get install -y wget bzip2 ca-certificates curl git gosu && \ 9 | apt-get clean && \ 10 | rm -rf /var/lib/apt/lists/* 11 | 12 | # 指定用户名 13 | ENV USER zj 14 | RUN set -eux && \ 15 | useradd -s /bin/bash -m ${USER} 16 | 17 | USER ${USER} 18 | 19 | RUN set -eux && \ 20 | echo ~ && \ 21 | wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py38_4.8.2-Linux-x86_64.sh -O ~/miniconda.sh && \ 22 | /bin/bash ~/miniconda.sh -b -p ~/conda && \ 23 | rm ~/miniconda.sh && \ 24 | ~/conda/bin/conda clean -tipsy && \ 25 | echo ". /home/${USER}/conda/etc/profile.d/conda.sh" >> ~/.bashrc && \ 26 | echo "conda activate base" >> ~/.bashrc 27 | 28 | USER root 29 | 30 | ENV TINI_VERSION v0.16.1 31 | ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/bin/tini 32 | RUN chmod +x /usr/bin/tini 33 | 34 | ENTRYPOINT [ "/usr/bin/tini", "--" ] 35 | CMD [ "/bin/bash" ] -------------------------------------------------------------------------------- /dockerfiles/nginx/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | nginx: 4 | container_name: nginx 5 | image: nginx 6 | ports: 7 | - "80:80" 8 | volumes: 9 | - "~/nginx/www:/opt/www" 10 | - "~/nginx/logs:/var/log/nginx" 11 | - "~/nginx/conf.d:/etc/nginx/conf.d" 12 | - "~/nginx/nginx.conf:/etc/nginx/nginx.conf" 13 | restart: always 14 | -------------------------------------------------------------------------------- /dockerfiles/qq/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM zjzstu/deepin-wine:latest 2 | LABEL maintainer "zhujian " 3 | 4 | WORKDIR /app 5 | RUN set -eux && \ 6 | apt-get update && \ 7 | apt-get install -y wget ttf-wqy-microhei gosu dbus && \ 8 | gosu nobody true && \ 9 | wget https://mirrors.aliyun.com/deepin/pool/non-free/d/deepin.com.qq.im/deepin.com.qq.im_9.1.8deepin0_i386.deb && \ 10 | useradd -s /bin/bash -m user && \ 11 | chown -R user:user /app && \ 12 | dpkg -i *.deb && \ 13 | rm -f *.deb && \ 14 | apt-get autoclean -y && apt-get clean -y && \ 15 | find /var/lib/apt/lists -type f -delete && \ 16 | find /var/cache -type f -delete && \ 17 | find /var/log -type f -delete && \ 18 | find /usr/share/doc -type f -delete && \ 19 | find /usr/share/man -type f -delete 20 | 21 | COPY docker-entrypoint.sh ./ 22 | RUN chmod a+x docker-entrypoint.sh && \ 23 | chown user:user docker-entrypoint.sh 24 | ENTRYPOINT ["/app/docker-entrypoint.sh"] -------------------------------------------------------------------------------- /dockerfiles/qq/README.md: -------------------------------------------------------------------------------- 1 | 2 | 参考:[[Docker][deepin-wine]QQ运行](https://container-automation.readthedocs.io/zh_CN/latest/docker/gui/[Docker][deepin-wine]QQ运行.html) -------------------------------------------------------------------------------- /dockerfiles/qq/deepin.com.qq.im.desktop: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env xdg-open 2 | 3 | [Desktop Entry] 4 | Encoding=UTF-8 5 | Type=Application 6 | X-Created-By=Deepin WINE Team 7 | Categories=chat; 8 | Icon=deepin.com.qq.im 9 | Exec=/usr/local/bin/qq 10 | Name=QQ 11 | Name[zh_CN]=QQ 12 | Comment=Tencent QQ Client on Deepin Wine 13 | StartupWMClass=QQ.exe 14 | MimeType= 15 | -------------------------------------------------------------------------------- /dockerfiles/qq/docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$(id -u)" -eq '0' ] 4 | then 5 | UID=${UID:-9001} 6 | GID=${GID:-9001} 7 | AUDIO_GID=${AUDIO_GID:-9002} 8 | VIDEO_GID=${VIDEO_GID:-9003} 9 | 10 | usermod -u ${UID} -g ${GID} -a -G root,${AUDIO_GID},${VIDEO_GID} user > /dev/null 2>&1 11 | 12 | source dbus start > /dev/null 2>&1 13 | export HOME=/home/user 14 | chown -R ${UID}:${GID} ${HOME} > /dev/null 2>&1 15 | exec gosu user "$0" "$@" 16 | fi 17 | 18 | APP="QQ" 19 | APP_NAME="QQ.exe" 20 | 21 | /opt/deepinwine/apps/Deepin-${APP}/run.sh > /dev/null 2>&1 22 | sleep 30s 23 | 24 | while test -n "`pidof ${APP_NAME}`" 25 | do 26 | sleep 1s 27 | done 28 | exit "$?" -------------------------------------------------------------------------------- /dockerfiles/qq/qq.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | APP="QQ" 4 | CONTAINER="qq" 5 | 6 | IMAGE="zjzstu/${CONTAINER}:latest" 7 | HOST_STORAGE="${HOME}/deepin-wine/Tencent Files" 8 | CONTAINER_STORAGE="/home/user/Tencent Files" 9 | 10 | HOST_CONFIGURE="${HOME}/.deepinwine/Deepin-${APP}" 11 | CONTAINER_CONFIGURE="/home/user/.deepinwine/Deepin-${APP}" 12 | 13 | APP_COMMAND="/opt/deepinwine/apps/Deepin-${APP}/run.sh" 14 | 15 | function startup() 16 | { 17 | docker run \ 18 | --device=/dev/snd:/dev/snd \ 19 | --device=/dev/video0:/dev/video0 \ 20 | --privileged \ 21 | -v /tmp/.X11-unix:/tmp/.X11-unix \ 22 | --privileged \ 23 | -e DISPLAY=unix${DISPLAY} \ 24 | -e AUDIO_GID=`getent group audio | cut -d: -f3` \ 25 | -e VIDEO_GID=`getent group video | cut -d: -f3` \ 26 | -e GID=`id -g` \ 27 | -e UID=`id -u` \ 28 | -e XMODIFIERS="@im=fcitx" \ 29 | -e QT_IM_MODULE="fcitx" \ 30 | -e GTK_IM_MODULE="fcitx" \ 31 | -v "${HOST_STORAGE}":"${CONTAINER_STORAGE}" \ 32 | -v "${HOST_CONFIGURE}":"${CONTAINER_CONFIGURE}" \ 33 | --name ${CONTAINER} \ 34 | -d ${IMAGE} > /dev/null 2>&1 35 | } 36 | 37 | function run() 38 | { 39 | xhost + > /dev/null 2>&1 40 | 41 | START=$(docker ps -q --filter="name=${CONTAINER}") 42 | STOP=$(docker ps -aq --filter="name=${CONTAINER}") 43 | 44 | if [ -n "${START}" ] 45 | then 46 | docker exec -d -u user $START ${APP_COMMAND} > /dev/null 2>&1 47 | elif [ -n "${STOP}" ] 48 | then 49 | docker restart ${STOP} > /dev/null 2>&1 50 | else 51 | startup 52 | fi 53 | } 54 | 55 | function main() 56 | { 57 | run 58 | exit "$?" 59 | } 60 | 61 | main -------------------------------------------------------------------------------- /dockerfiles/sshd/Dockerfile: -------------------------------------------------------------------------------- 1 | # $ docker build -t zjzstu/ssh . 2 | # $ docker run -d -P --name test_sshd zjzstu/ssh:latest 3 | FROM zjzstu/ubuntu:18.04 4 | LABEL maintainer "zhujian " 5 | 6 | RUN apt-get update && apt-get install -y openssh-server 7 | RUN mkdir /var/run/sshd && \ 8 | echo 'root:zhujian' | chpasswd && \ 9 | sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \ 10 | sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd 11 | # SSH login fix. Otherwise user is kicked off after login 12 | 13 | EXPOSE 22 14 | CMD ["/usr/sbin/sshd", "-D"] -------------------------------------------------------------------------------- /dockerfiles/sshd/README.md: -------------------------------------------------------------------------------- 1 | 2 | 参考:[[Docker][SSH]远程登录Ubuntu](https://container-automation.readthedocs.io/zh_CN/latest/docker/advanced/%5BDocker%5D%5BSSH%5D远程登录Ubuntu.html) -------------------------------------------------------------------------------- /dockerfiles/system_mirror/Dockerfile: -------------------------------------------------------------------------------- 1 | # $ docker build -t zjzstu/ubuntu:18.04 -t zjzstu/ubuntu:latest . 2 | # $ docker run -it --rm zjzstu/ubuntu bash 3 | 4 | FROM ubuntu:18.04 5 | LABEL maintainer "zhujian " 6 | 7 | COPY sources.list . 8 | ENV DEBIAN_FRONTEND=noninteractive 9 | RUN mv sources.list /etc/apt/sources.list && \ 10 | apt-get update && \ 11 | apt-get install -y locales tzdata && \ 12 | locale-gen zh_CN.UTF-8 && \ 13 | update-locale LANG=zh_CN.UTF-8 LANGUAGE=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 && \ 14 | ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ 15 | dpkg-reconfigure --frontend noninteractive tzdata && \ 16 | find /var/lib/apt/lists -type f -delete && \ 17 | find /var/cache -type f -delete 18 | 19 | ENV LANG=zh_CN.UTF-8 LANGUAGE=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 -------------------------------------------------------------------------------- /dockerfiles/system_mirror/Dockerfile.en_US: -------------------------------------------------------------------------------- 1 | # $ docker build -t zjzstu/ubuntu:18.04 -t zjzstu/ubuntu:latest . 2 | # $ docker run -it --rm zjzstu/ubuntu bash 3 | 4 | FROM ubuntu:18.04 5 | LABEL maintainer "zhujian " 6 | 7 | COPY sources.list . 8 | ENV DEBIAN_FRONTEND=noninteractive 9 | RUN mv sources.list /etc/apt/sources.list && \ 10 | apt-get update && \ 11 | apt-get install -y locales tzdata && \ 12 | locale-gen en_US.UTF-8 && \ 13 | update-locale LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LC_ALL=en_US.UTF-8 && \ 14 | ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ 15 | dpkg-reconfigure --frontend noninteractive tzdata && \ 16 | find /var/lib/apt/lists -type f -delete && \ 17 | find /var/cache -type f -delete 18 | 19 | ENV LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LC_ALL=en_US.UTF-8 -------------------------------------------------------------------------------- /dockerfiles/system_mirror/sources.list: -------------------------------------------------------------------------------- 1 | deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse 2 | deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse 3 | 4 | deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse 5 | deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse 6 | 7 | deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse 8 | deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse 9 | 10 | deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse 11 | deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse 12 | 13 | deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse 14 | deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse -------------------------------------------------------------------------------- /dockerfiles/thunder/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM zjzstu/deepin-wine:latest 2 | LABEL maintainer "zhujian " 3 | 4 | WORKDIR /app 5 | RUN set -eux && \ 6 | apt-get update && \ 7 | apt-get install -y wget ttf-wqy-microhei gosu dbus && \ 8 | gosu nobody true && \ 9 | wget https://mirrors.aliyun.com/deepin/pool/non-free/d/deepin.com.thunderspeed/deepin.com.thunderspeed_7.10.35.366deepin18_i386.deb && \ 10 | useradd -s /bin/bash -m user && \ 11 | chown -R user:user /app && \ 12 | dpkg -i *.deb && \ 13 | rm -f *.deb && \ 14 | apt-get autoclean -y && apt-get clean -y && \ 15 | find /var/lib/apt/lists -type f -delete && \ 16 | find /var/cache -type f -delete && \ 17 | find /var/log -type f -delete && \ 18 | find /usr/share/doc -type f -delete && \ 19 | find /usr/share/man -type f -delete 20 | 21 | COPY docker-entrypoint.sh ./ 22 | RUN chmod a+x docker-entrypoint.sh && \ 23 | chown user:user docker-entrypoint.sh 24 | ENTRYPOINT ["/app/docker-entrypoint.sh"] -------------------------------------------------------------------------------- /dockerfiles/thunder/README.md: -------------------------------------------------------------------------------- 1 | 2 | 参考:[[Docker][deepin-wine]迅雷运行](https://container-automation.readthedocs.io/zh_CN/latest/docker/gui/[Docker][deepin-wine]迅雷运行.html) -------------------------------------------------------------------------------- /dockerfiles/thunder/deepin.com.thunderspeed.desktop: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env xdg-open 2 | 3 | [Desktop Entry] 4 | Encoding=UTF-8 5 | Type=Application 6 | X-Created-By=Deepin WINE Team 7 | Categories=internet; 8 | Icon=deepin.com.thunderspeed 9 | Exec=/usr/local/bin/thunder 10 | Name=Thunder Speed 11 | Name[zh_CN]=迅雷极速版 12 | Comment=Thunder Speed Client on Deepin Wine 13 | StartupWMClass=Thunder.exe 14 | MimeType= 15 | -------------------------------------------------------------------------------- /dockerfiles/thunder/docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$(id -u)" -eq '0' ] 4 | then 5 | UID=${UID:-9001} 6 | GID=${GID:-9001} 7 | AUDIO_GID=${AUDIO_GID:-9002} 8 | VIDEO_GID=${VIDEO_GID:-9003} 9 | 10 | usermod -u ${UID} -g ${GID} -a -G root,${AUDIO_GID},${VIDEO_GID} user > /dev/null 2>&1 11 | 12 | source dbus start > /dev/null 2>&1 13 | export HOME=/home/user 14 | chown -R ${UID}:${GID} ${HOME} > /dev/null 2>&1 15 | exec gosu user "$0" "$@" 16 | fi 17 | 18 | APP="ThunderSpeed" 19 | APP_NAME="Thunder.exe" 20 | 21 | /opt/deepinwine/apps/Deepin-${APP}/run.sh > /dev/null 2>&1 22 | sleep 30s 23 | 24 | while test -n "`pidof ${APP_NAME}`" 25 | do 26 | sleep 1s 27 | done 28 | exit "$?" -------------------------------------------------------------------------------- /dockerfiles/thunder/hicolor/16x16/apps/deepin.com.thunderspeed.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 迅雷极速版 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /dockerfiles/thunder/hicolor/24x24/apps/deepin.com.thunderspeed.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 迅雷极速版 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /dockerfiles/thunder/hicolor/32x32/apps/deepin.com.thunderspeed.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 迅雷极速版 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /dockerfiles/thunder/hicolor/48x48/apps/deepin.com.thunderspeed.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 迅雷极速版 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /dockerfiles/thunder/hicolor/64x64/apps/deepin.com.thunderspeed.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 迅雷极速版 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /dockerfiles/thunder/thunder.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | APP="ThunderSpeed" 4 | CONTAINER="thunder" 5 | 6 | IMAGE="zjzstu/${CONTAINER}:latest" 7 | HOST_STORAGE="${HOME}/deepin-wine/${APP} Files" 8 | CONTAINER_STORAGE="/home/user/${APP} Files" 9 | 10 | HOST_CONFIGURE="${HOME}/.deepinwine/Deepin-${APP}" 11 | CONTAINER_CONFIGURE="/home/user/.deepinwine/Deepin-${APP}" 12 | 13 | APP_COMMAND="/opt/deepinwine/apps/Deepin-${APP}/run.sh" 14 | 15 | function startup() 16 | { 17 | docker run \ 18 | --device=/dev/snd:/dev/snd \ 19 | --device=/dev/video0:/dev/video0 \ 20 | --privileged \ 21 | -v /tmp/.X11-unix:/tmp/.X11-unix \ 22 | -e DISPLAY=unix${DISPLAY} \ 23 | -e AUDIO_GID=`getent group audio | cut -d: -f3` \ 24 | -e VIDEO_GID=`getent group video | cut -d: -f3` \ 25 | -e GID=`id -g` \ 26 | -e UID=`id -u` \ 27 | -e XMODIFIERS="@im=fcitx" \ 28 | -e QT_IM_MODULE="fcitx" \ 29 | -e GTK_IM_MODULE="fcitx" \ 30 | -v "${HOST_STORAGE}":"${CONTAINER_STORAGE}" \ 31 | -v "${HOST_CONFIGURE}":"${CONTAINER_CONFIGURE}" \ 32 | --name ${CONTAINER} \ 33 | -d ${IMAGE} > /dev/null 2>&1 34 | } 35 | 36 | function run() 37 | { 38 | xhost + > /dev/null 2>&1 39 | 40 | START=$(docker ps -q --filter="name=${CONTAINER}") 41 | STOP=$(docker ps -aq --filter="name=${CONTAINER}") 42 | 43 | if [ -n "${START}" ] 44 | then 45 | docker exec -d -u user $START ${APP_COMMAND} > /dev/null 2>&1 46 | elif [ -n "${STOP}" ] 47 | then 48 | docker restart ${STOP} > /dev/null 2>&1 49 | else 50 | startup 51 | fi 52 | } 53 | 54 | function main() 55 | { 56 | run 57 | exit "$?" 58 | } 59 | 60 | main -------------------------------------------------------------------------------- /dockerfiles/tim/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM zjzstu/deepin-wine:latest 2 | LABEL maintainer "zhujian " 3 | 4 | WORKDIR /app 5 | RUN set -eux && \ 6 | apt-get update && \ 7 | apt-get install -y wget ttf-wqy-microhei gosu dbus && \ 8 | gosu nobody true && \ 9 | wget https://mirrors.aliyun.com/deepin/pool/non-free/d/deepin.com.qq.office/deepin.com.qq.office_2.0.0deepin4_i386.deb && \ 10 | useradd -s /bin/bash -m user && \ 11 | chown -R user:user /app && \ 12 | dpkg -i *.deb && \ 13 | rm -f *.deb && \ 14 | apt-get autoclean -y && apt-get clean -y && \ 15 | find /var/lib/apt/lists -type f -delete && \ 16 | find /var/cache -type f -delete && \ 17 | find /var/log -type f -delete && \ 18 | find /usr/share/doc -type f -delete && \ 19 | find /usr/share/man -type f -delete 20 | 21 | COPY docker-entrypoint.sh ./ 22 | RUN chmod a+x docker-entrypoint.sh && \ 23 | chown user:user docker-entrypoint.sh 24 | ENTRYPOINT ["/app/docker-entrypoint.sh"] -------------------------------------------------------------------------------- /dockerfiles/tim/README.md: -------------------------------------------------------------------------------- 1 | 2 | 参考:[[Docker][deepin-wine]QQ运行](https://container-automation.readthedocs.io/zh_CN/latest/docker/gui/[Docker][deepin-wine]QQ运行.html) -------------------------------------------------------------------------------- /dockerfiles/tim/deepin.com.qq.office.desktop: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env xdg-open 2 | 3 | [Desktop Entry] 4 | Encoding=UTF-8 5 | Type=Application 6 | X-Created-By=Deepin WINE Team 7 | Categories=chat; 8 | Icon=deepin.com.qq.office 9 | Exec=/usr/local/bin/tim 10 | Name=TIM 11 | Name[zh_CN]=TIM 12 | Comment=Tencent TIM Client on Deepin Wine 13 | StartupWMClass=TIM.exe 14 | MimeType= 15 | -------------------------------------------------------------------------------- /dockerfiles/tim/docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$(id -u)" -eq '0' ] 4 | then 5 | UID=${UID:-9001} 6 | GID=${GID:-9001} 7 | AUDIO_GID=${AUDIO_GID:-9002} 8 | VIDEO_GID=${VIDEO_GID:-9003} 9 | 10 | usermod -u ${UID} -g ${GID} -a -G root,${AUDIO_GID},${VIDEO_GID} user > /dev/null 2>&1 11 | 12 | source dbus start > /dev/null 2>&1 13 | export HOME=/home/user 14 | chown -R ${UID}:${GID} ${HOME} > /dev/null 2>&1 15 | exec gosu user "$0" "$@" 16 | fi 17 | 18 | APP="TIM" 19 | APP_NAME="TIM.exe" 20 | 21 | /opt/deepinwine/apps/Deepin-${APP}/run.sh > /dev/null 2>&1 22 | sleep 30s 23 | 24 | while test -n "`pidof ${APP_NAME}`" 25 | do 26 | sleep 1s 27 | done 28 | exit "$?" -------------------------------------------------------------------------------- /dockerfiles/tim/hicolor/16x16/apps/deepin.com.qq.office.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | tim 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /dockerfiles/tim/hicolor/24x24/apps/deepin.com.qq.office.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | tim 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /dockerfiles/tim/hicolor/32x32/apps/deepin.com.qq.office.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | tim 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /dockerfiles/tim/hicolor/48x48/apps/deepin.com.qq.office.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | tim 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /dockerfiles/tim/hicolor/64x64/apps/deepin.com.qq.office.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | tim 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /dockerfiles/tim/tim.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | APP="TIM" 4 | CONTAINER="tim" 5 | 6 | IMAGE="zjzstu/${CONTAINER}:latest" 7 | HOST_STORAGE="${HOME}/deepin-wine/Tencent Files" 8 | CONTAINER_STORAGE="/home/user/Tencent Files" 9 | 10 | HOST_CONFIGURE="${HOME}/.deepinwine/Deepin-${APP}" 11 | CONTAINER_CONFIGURE="/home/user/.deepinwine/Deepin-${APP}" 12 | 13 | APP_COMMAND="/opt/deepinwine/apps/Deepin-${APP}/run.sh" 14 | 15 | function startup() 16 | { 17 | docker run \ 18 | --device=/dev/snd:/dev/snd \ 19 | --device=/dev/video0:/dev/video0 \ 20 | --privileged \ 21 | -v /tmp/.X11-unix:/tmp/.X11-unix \ 22 | --privileged \ 23 | -e DISPLAY=unix${DISPLAY} \ 24 | -e AUDIO_GID=`getent group audio | cut -d: -f3` \ 25 | -e VIDEO_GID=`getent group video | cut -d: -f3` \ 26 | -e GID=`id -g` \ 27 | -e UID=`id -u` \ 28 | -e XMODIFIERS="@im=fcitx" \ 29 | -e QT_IM_MODULE="fcitx" \ 30 | -e GTK_IM_MODULE="fcitx" \ 31 | -v "${HOST_STORAGE}":"${CONTAINER_STORAGE}" \ 32 | -v "${HOST_CONFIGURE}":"${CONTAINER_CONFIGURE}" \ 33 | --name ${CONTAINER} \ 34 | -d ${IMAGE} > /dev/null 2>&1 35 | } 36 | 37 | function run() 38 | { 39 | xhost + > /dev/null 2>&1 40 | 41 | START=$(docker ps -q --filter="name=${CONTAINER}") 42 | STOP=$(docker ps -aq --filter="name=${CONTAINER}") 43 | 44 | if [ -n "${START}" ] 45 | then 46 | docker exec -d -u user $START ${APP_COMMAND} > /dev/null 2>&1 47 | elif [ -n "${STOP}" ] 48 | then 49 | docker restart ${STOP} > /dev/null 2>&1 50 | else 51 | startup 52 | fi 53 | } 54 | 55 | function main() 56 | { 57 | run 58 | exit "$?" 59 | } 60 | 61 | main -------------------------------------------------------------------------------- /dockerfiles/ubuntu/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:18.04 2 | LABEL maintainer "zhujian " 3 | 4 | COPY sources.list . 5 | ENV DEBIAN_FRONTEND=noninteractive 6 | RUN set -eux && \ 7 | rm /etc/apt/sources.list && \ 8 | mv sources.list /etc/apt/sources.list && \ 9 | apt-get update && \ 10 | apt-get install -y locales tzdata xfonts-wqy && \ 11 | locale-gen zh_CN.UTF-8 && \ 12 | update-locale LANG=zh_CN.UTF-8 LANGUAGE=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 && \ 13 | ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ 14 | dpkg-reconfigure --frontend noninteractive tzdata && \ 15 | find /var/lib/apt/lists -type f -delete && \ 16 | find /var/cache -type f -delete 17 | 18 | ENV LANG=zh_CN.UTF-8 LANGUAGE=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 19 | -------------------------------------------------------------------------------- /dockerfiles/ubuntu/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.7" 2 | services: 3 | ubuntu: 4 | labels: 5 | AUTHOR: "zhujian " 6 | container_name: ubuntu 7 | image: 'zjzstu/ubuntu:latest' 8 | build: . 9 | environment: 10 | - XMODIFIERS="@im=fcitx" 11 | - QT_IM_MODULE="fcitx" 12 | - GTK_IM_MODULE="fcitx" 13 | tty: true 14 | stdin_open: true -------------------------------------------------------------------------------- /dockerfiles/ubuntu/sources.list: -------------------------------------------------------------------------------- 1 | deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse 2 | deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse 3 | 4 | deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse 5 | deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse 6 | 7 | deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse 8 | deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse 9 | 10 | deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse 11 | deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse 12 | 13 | deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse 14 | deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse 15 | -------------------------------------------------------------------------------- /dockerfiles/wechat/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM zjzstu/deepin-wine:latest 2 | LABEL maintainer "zhujian " 3 | 4 | WORKDIR /app 5 | RUN set -eux && \ 6 | apt-get update && \ 7 | apt-get install -y wget ttf-wqy-microhei gosu dbus && \ 8 | gosu nobody true && \ 9 | wget https://mirrors.aliyun.com/deepin/pool/non-free/d/deepin.com.wechat/deepin.com.wechat_2.6.8.65deepin0_i386.deb && \ 10 | useradd -s /bin/bash -m user && \ 11 | chown -R user:user /app && \ 12 | dpkg -i *.deb && \ 13 | rm -f *.deb && \ 14 | apt-get autoclean -y && apt-get clean -y && \ 15 | find /var/lib/apt/lists -type f -delete && \ 16 | find /var/cache -type f -delete && \ 17 | find /var/log -type f -delete && \ 18 | find /usr/share/doc -type f -delete && \ 19 | find /usr/share/man -type f -delete 20 | 21 | COPY docker-entrypoint.sh ./ 22 | RUN chmod a+x docker-entrypoint.sh && \ 23 | chown user:user docker-entrypoint.sh 24 | ENTRYPOINT ["/app/docker-entrypoint.sh"] -------------------------------------------------------------------------------- /dockerfiles/wechat/README.md: -------------------------------------------------------------------------------- 1 | 2 | 参考:[[Docker][deepin-wine]微信运行](https://container-automation.readthedocs.io/zh_CN/latest/docker/gui/[Docker][deepin-wine]微信运行.html) -------------------------------------------------------------------------------- /dockerfiles/wechat/deepin.com.wechat.desktop: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env xdg-open 2 | 3 | [Desktop Entry] 4 | Encoding=UTF-8 5 | Type=Application 6 | X-Created-By=Deepin WINE Team 7 | Categories=chat; 8 | Icon=deepin.com.wechat 9 | Exec=/usr/local/bin/wechat 10 | Name=WeChat 11 | Name[zh_CN]=微信 12 | Comment=Tencent WeChat Client on Deepin Wine 13 | StartupWMClass=WeChat.exe 14 | MimeType= 15 | -------------------------------------------------------------------------------- /dockerfiles/wechat/docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$(id -u)" -eq '0' ] 4 | then 5 | UID=${UID:-9001} 6 | GID=${GID:-9001} 7 | AUDIO_GID=${AUDIO_GID:-9002} 8 | VIDEO_GID=${VIDEO_GID:-9003} 9 | 10 | usermod -u ${UID} -g ${GID} -a -G root,${AUDIO_GID},${VIDEO_GID} user > /dev/null 2>&1 11 | 12 | source dbus start > /dev/null 2>&1 13 | export HOME=/home/user 14 | chown -R ${UID}:${GID} ${HOME} > /dev/null 2>&1 15 | exec gosu user "$0" "$@" 16 | fi 17 | 18 | APP="WeChat" 19 | APP_NAME="WeChat.exe" 20 | 21 | /opt/deepinwine/apps/Deepin-${APP}/run.sh > /dev/null 2>&1 22 | sleep 30s 23 | 24 | while test -n "`pidof ${APP_NAME}`" 25 | do 26 | sleep 1s 27 | done 28 | exit "$?" -------------------------------------------------------------------------------- /dockerfiles/wechat/hicolor/16x16/apps/deepin.com.wechat.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 微信 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /dockerfiles/wechat/hicolor/24x24/apps/deepin.com.wechat.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 微信 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /dockerfiles/wechat/hicolor/32x32/apps/deepin.com.wechat.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 微信 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /dockerfiles/wechat/hicolor/48x48/apps/deepin.com.wechat.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 微信 5 | Created with Sketch. 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /dockerfiles/wechat/wechat.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | APP="WeChat" 4 | CONTAINER="wechat" 5 | 6 | IMAGE="zjzstu/${CONTAINER}:latest" 7 | HOST_STORAGE="${HOME}/deepin-wine/${APP} Files" 8 | CONTAINER_STORAGE="/home/user/${APP} Files" 9 | 10 | HOST_CONFIGURE="${HOME}/.deepinwine/Deepin-${APP}" 11 | CONTAINER_CONFIGURE="/home/user/.deepinwine/Deepin-${APP}" 12 | 13 | APP_COMMAND="/opt/deepinwine/apps/Deepin-${APP}/run.sh" 14 | 15 | function startup() 16 | { 17 | docker run \ 18 | --device=/dev/snd:/dev/snd \ 19 | --device=/dev/video0:/dev/video0 \ 20 | --privileged \ 21 | -v /tmp/.X11-unix:/tmp/.X11-unix \ 22 | -e DISPLAY=unix${DISPLAY} \ 23 | -e AUDIO_GID=`getent group audio | cut -d: -f3` \ 24 | -e VIDEO_GID=`getent group video | cut -d: -f3` \ 25 | -e GID=`id -g` \ 26 | -e UID=`id -u` \ 27 | -e XMODIFIERS="@im=fcitx" \ 28 | -e QT_IM_MODULE="fcitx" \ 29 | -e GTK_IM_MODULE="fcitx" \ 30 | -v "${HOST_STORAGE}":"${CONTAINER_STORAGE}" \ 31 | -v "${HOST_CONFIGURE}":"${CONTAINER_CONFIGURE}" \ 32 | --name ${CONTAINER} \ 33 | -d ${IMAGE} > /dev/null 2>&1 34 | } 35 | 36 | function run() 37 | { 38 | xhost + > /dev/null 2>&1 39 | 40 | START=$(docker ps -q --filter="name=${CONTAINER}") 41 | STOP=$(docker ps -aq --filter="name=${CONTAINER}") 42 | 43 | if [ -n "${START}" ] 44 | then 45 | docker exec -d -u user $START ${APP_COMMAND} > /dev/null 2>&1 46 | elif [ -n "${STOP}" ] 47 | then 48 | docker restart ${STOP} > /dev/null 2>&1 49 | else 50 | startup 51 | fi 52 | } 53 | 54 | function main() 55 | { 56 | run 57 | exit "$?" 58 | } 59 | 60 | main 61 | -------------------------------------------------------------------------------- /dockerfiles/wps/Dockerfile: -------------------------------------------------------------------------------- 1 | 2 | FROM zjzstu/ubuntu:latest 3 | LABEL maintainer "zhujian " 4 | 5 | WORKDIR /app 6 | COPY wps_symbol_fonts.zip ./ 7 | 8 | RUN set -eux && \ 9 | # 安装wps依赖,安装额外工具xdg-utils/unzip/wget/gosu 10 | apt-get update && \ 11 | apt-get install -y libfreetype6 libcups2 libglib2.0-0 libglu1-mesa libsm6 libxrender1 libfontconfig1 libxext6 libxcb1 libgtk2.0-0 libcanberra-gtk-module xdg-utils unzip wget gosu && \ 12 | # verify that the binary works 13 | gosu nobody true && \ 14 | # 下载安装包 15 | wget http://kdl.cc.ksosoft.com/wps-community/download/8865/wps-office_11.1.0.8865_amd64.deb && \ 16 | wget http://kdl.cc.ksosoft.com/wps-community/download/fonts/wps-office-fonts_1.0_all.deb && \ 17 | # 新建用户user,并修改安装包属主/属组 18 | useradd -s /bin/bash -m user && \ 19 | chown user:user wps*.deb && \ 20 | # 安装wps及中文字体 21 | unzip wps_symbol_fonts.zip -d /usr/share/fonts/ && \ 22 | chmod 755 /usr/share/fonts/*.ttf && \ 23 | chmod 755 /usr/share/fonts/*.TTF && \ 24 | dpkg -i wps-office_11.1.0.8865_amd64.deb && \ 25 | dpkg -i wps-office-fonts_1.0_all.deb && \ 26 | # 删除 27 | rm *.deb wps_symbol_fonts.zip && \ 28 | apt-get remove -y --purge wget unzip && \ 29 | apt-get autoclean -y && apt-get clean -y && \ 30 | find /var/lib/apt/lists -type f -delete && \ 31 | find /var/cache -type f -delete && \ 32 | find /var/log -type f -delete && \ 33 | find /usr/share/doc -type f -delete && \ 34 | find /usr/share/man -type f -delete 35 | 36 | COPY docker-entrypoint.sh ./ 37 | # 赋予docker-entrypoint.sh可执行权限 38 | RUN chmod a+x docker-entrypoint.sh 39 | 40 | ENTRYPOINT ["/app/docker-entrypoint.sh"] -------------------------------------------------------------------------------- /dockerfiles/wps/README.md: -------------------------------------------------------------------------------- 1 | 2 | 参考:[[Docker][Ubuntu]WPS运行](https://container-automation.readthedocs.io/zh_CN/latest/docker/gui/[Docker][Ubuntu]WPS运行.html) -------------------------------------------------------------------------------- /dockerfiles/wps/desktop.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Document-Collection/Containerization-Automation/1c26d368b07a390523ec1d8ab65f0b208bb16cf2/dockerfiles/wps/desktop.zip -------------------------------------------------------------------------------- /dockerfiles/wps/docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$(id -u)" -eq '0' ] 4 | then 5 | USER_ID=${LOCAL_USER_ID:-9001} 6 | 7 | chown -R ${USER_ID} /app 8 | usermod -u ${USER_ID} user 9 | usermod -a -G root user 10 | 11 | export HOME=/home/user 12 | exec gosu user "$0" "$@" 13 | fi 14 | 15 | exec "$@" -------------------------------------------------------------------------------- /dockerfiles/wps/et.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | FINALNAME= 4 | BASENAME="/home/user/Documents" 5 | 6 | COMMAND="et" 7 | COMMAND_NAME="et" 8 | IMAGE_NAME="zjzstu/wps:latest" 9 | 10 | # 替换主机文件路径为容器路径 11 | function parse_arg() 12 | { 13 | FILE_DIR=$1 14 | 15 | if [ ! -f ${FILE_DIR} ] 16 | then 17 | echo "file not existed!" 18 | exit 1 19 | fi 20 | 21 | if [[ ${FILE_DIR} == ./* ]] 22 | then 23 | FINALNAME=${PWD}${FILE_DIR#.} 24 | elif [[ ${FILE_DIR} == ../* ]] 25 | then 26 | FINALNAME=`dirname ${PWD}`${FILE_DIR#..} 27 | elif [[ ${FILE_DIR} == ${HOME}* ]] 28 | then 29 | FINALNAME=${FILE_DIR} 30 | else 31 | FINALNAME=${PWD}/${FILE_DIR} 32 | fi 33 | 34 | FINALNAME=${BASENAME}${FINALNAME#${HOME}} 35 | } 36 | 37 | # 启动wps镜像 38 | function startup() 39 | { 40 | docker run -d \ 41 | -v /tmp/.X11-unix:/tmp/.X11-unix \ 42 | -e DISPLAY=unix${DISPLAY} \ 43 | -e LOCAL_USER_ID=`id -u ${USER}` \ 44 | -e XMODIFIERS="@im=fcitx" \ 45 | -e QT_IM_MODULE="fcitx" \ 46 | -e GTK_IM_MODULE="fcitx" \ 47 | -v ${HOME}:${BASENAME} \ 48 | --name ${COMMAND_NAME} \ 49 | ${IMAGE_NAME} \ 50 | ${COMMAND} ${FINALNAME} > /dev/null 2>&1 51 | } 52 | 53 | function run() 54 | { 55 | xhost + > /dev/null 2>&1 56 | 57 | START=$(docker ps -q --filter="name=${COMMAND_NAME}") 58 | STOP=$(docker ps -aq --filter="name=${COMMAND_NAME}") 59 | 60 | if [ -n "${START}" ] 61 | then 62 | docker exec -u user $START ${COMMAND} $FINALNAME > /dev/null 2>&1 63 | elif [ -n "${STOP}" ] 64 | then 65 | if [ -z ${FINALNAME} ] 66 | then 67 | docker restart ${STOP} > /dev/null 2>&1 68 | else 69 | docker container rm ${STOP} > /dev/null 2>&1 70 | startup 71 | fi 72 | else 73 | startup 74 | fi 75 | } 76 | 77 | function main() 78 | { 79 | NUM=$# 80 | if [ $NUM -eq 1 ] 81 | then 82 | parse_arg "$@" 83 | fi 84 | 85 | run "$@" 86 | exit 0 87 | } 88 | 89 | main "$@" -------------------------------------------------------------------------------- /dockerfiles/wps/pdf.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | FINALNAME= 4 | BASENAME="/home/user/Documents" 5 | 6 | COMMAND="wpspdf" 7 | COMMAND_NAME="pdf" 8 | IMAGE_NAME="zjzstu/wps:latest" 9 | 10 | # 替换主机文件路径为容器路径 11 | function parse_arg() 12 | { 13 | FILE_DIR=$1 14 | 15 | if [[ ${FILE_DIR} == ./* ]] 16 | then 17 | FINALNAME=${PWD}${FILE_DIR#.} 18 | elif [[ ${FILE_DIR} == ../* ]] 19 | then 20 | FINALNAME=`dirname ${PWD}`${FILE_DIR#..} 21 | elif [[ ${FILE_DIR} == ${HOME}* ]] 22 | then 23 | FINALNAME=${FILE_DIR} 24 | else 25 | FINALNAME=${PWD}/${FILE_DIR} 26 | fi 27 | 28 | FINALNAME=${BASENAME}${FINALNAME#${HOME}} 29 | } 30 | 31 | # 启动wps镜像 32 | function startup() 33 | { 34 | docker run -d \ 35 | -v /tmp/.X11-unix:/tmp/.X11-unix \ 36 | -e DISPLAY=unix${DISPLAY} \ 37 | -e LOCAL_USER_ID=`id -u ${USER}` \ 38 | -e XMODIFIERS="@im=fcitx" \ 39 | -e QT_IM_MODULE="fcitx" \ 40 | -e GTK_IM_MODULE="fcitx" \ 41 | -v ${HOME}:${BASENAME} \ 42 | --name ${COMMAND_NAME} \ 43 | ${IMAGE_NAME} \ 44 | ${COMMAND} ${FINALNAME} > /dev/null 2>&1 45 | } 46 | 47 | function run() 48 | { 49 | xhost + > /dev/null 2>&1 50 | 51 | START=$(docker ps -q --filter="name=${COMMAND_NAME}") 52 | STOP=$(docker ps -aq --filter="name=${COMMAND_NAME}") 53 | 54 | if [ -n "${START}" ] 55 | then 56 | docker exec -u user $START ${COMMAND} $FINALNAME > /dev/null 2>&1 57 | elif [ -n "${STOP}" ] 58 | then 59 | if [ -z ${FINALNAME} ] 60 | then 61 | docker restart ${STOP} > /dev/null 2>&1 62 | else 63 | docker container rm ${STOP} > /dev/null 2>&1 64 | startup 65 | fi 66 | else 67 | startup 68 | fi 69 | } 70 | 71 | function main() 72 | { 73 | NUM=$# 74 | if [ $NUM -eq 1 ] 75 | then 76 | parse_arg "$@" 77 | fi 78 | 79 | run "$@" 80 | exit 0 81 | } 82 | 83 | main "$@" -------------------------------------------------------------------------------- /dockerfiles/wps/wpp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo $@ 4 | 5 | FINALNAME= 6 | BASENAME="/home/user/Documents" 7 | 8 | COMMAND="wpp" 9 | COMMAND_NAME="wpp" 10 | IMAGE_NAME="zjzstu/wps:latest" 11 | 12 | # 替换主机文件路径为容器路径 13 | function parse_arg() 14 | { 15 | FILE_DIR="$1" 16 | 17 | if [[ ${FILE_DIR} == ./* ]] 18 | then 19 | FINALNAME=${PWD}${FILE_DIR#.} 20 | elif [[ ${FILE_DIR} == ../* ]] 21 | then 22 | FINALNAME=`dirname ${PWD}`${FILE_DIR#..} 23 | elif [[ ${FILE_DIR} == ${HOME}* ]] 24 | then 25 | FINALNAME=${FILE_DIR} 26 | else 27 | FINALNAME=${PWD}/${FILE_DIR} 28 | fi 29 | 30 | FINALNAME=${BASENAME}${FINALNAME#${HOME}} 31 | } 32 | 33 | # 启动wps镜像 34 | function startup() 35 | { 36 | docker run -d \ 37 | -v /tmp/.X11-unix:/tmp/.X11-unix \ 38 | -e DISPLAY=unix${DISPLAY} \ 39 | -e LOCAL_USER_ID=`id -u ${USER}` \ 40 | -e XMODIFIERS="@im=fcitx" \ 41 | -e QT_IM_MODULE="fcitx" \ 42 | -e GTK_IM_MODULE="fcitx" \ 43 | -v ${HOME}:${BASENAME} \ 44 | --name ${COMMAND_NAME} \ 45 | ${IMAGE_NAME} \ 46 | ${COMMAND} ${FINALNAME} > /dev/null 2>&1 47 | } 48 | 49 | function run() 50 | { 51 | xhost + > /dev/null 2>&1 52 | 53 | START=$(docker ps -q --filter="name=${COMMAND_NAME}") 54 | STOP=$(docker ps -aq --filter="name=${COMMAND_NAME}") 55 | 56 | if [ -n "${START}" ] 57 | then 58 | docker exec -u user $START ${COMMAND} $FINALNAME > /dev/null 2>&1 59 | elif [ -n "${STOP}" ] 60 | then 61 | if [ -z ${FINALNAME} ] 62 | then 63 | docker restart ${STOP} > /dev/null 2>&1 64 | else 65 | docker container rm ${STOP} > /dev/null 2>&1 66 | startup 67 | fi 68 | else 69 | startup 70 | fi 71 | } 72 | 73 | function main() 74 | { 75 | NUM=$# 76 | if [ $NUM -eq 1 ] 77 | then 78 | parse_arg "$@" 79 | fi 80 | 81 | echo `$FINALNAME` 82 | run "$@" 83 | exit 0 84 | } 85 | 86 | main "$@" -------------------------------------------------------------------------------- /dockerfiles/wps/wps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | FINALNAME= 4 | BASENAME="/home/user/Documents" 5 | 6 | COMMAND="wps" 7 | COMMAND_NAME="wps" 8 | IMAGE_NAME="zjzstu/wps:latest" 9 | 10 | # 替换主机文件路径为容器路径 11 | function parse_arg() 12 | { 13 | FILE_DIR=$1 14 | 15 | if [[ ${FILE_DIR} == ./* ]] 16 | then 17 | FINALNAME=${PWD}${FILE_DIR#.} 18 | elif [[ ${FILE_DIR} == ../* ]] 19 | then 20 | FINALNAME=`dirname ${PWD}`${FILE_DIR#..} 21 | elif [[ ${FILE_DIR} == ${HOME}* ]] 22 | then 23 | FINALNAME=${FILE_DIR} 24 | else 25 | FINALNAME=${PWD}/${FILE_DIR} 26 | fi 27 | 28 | FINALNAME=${BASENAME}${FINALNAME#${HOME}} 29 | } 30 | 31 | # 启动wps镜像 32 | function startup() 33 | { 34 | docker run -d \ 35 | -v /tmp/.X11-unix:/tmp/.X11-unix \ 36 | -e DISPLAY=unix${DISPLAY} \ 37 | -e LOCAL_USER_ID=`id -u ${USER}` \ 38 | -e XMODIFIERS="@im=fcitx" \ 39 | -e QT_IM_MODULE="fcitx" \ 40 | -e GTK_IM_MODULE="fcitx" \ 41 | -v ${HOME}:${BASENAME} \ 42 | --name ${COMMAND_NAME} \ 43 | ${IMAGE_NAME} \ 44 | ${COMMAND} ${FINALNAME} > /dev/null 2>&1 45 | } 46 | 47 | function run() 48 | { 49 | xhost + > /dev/null 2>&1 50 | 51 | START=$(docker ps -q --filter="name=${COMMAND_NAME}") 52 | STOP=$(docker ps -aq --filter="name=${COMMAND_NAME}") 53 | 54 | if [ -n "${START}" ] 55 | then 56 | docker exec -u user $START ${COMMAND} $FINALNAME > /dev/null 2>&1 57 | elif [ -n "${STOP}" ] 58 | then 59 | if [ -z ${FINALNAME} ] 60 | then 61 | docker restart ${STOP} > /dev/null 2>&1 62 | else 63 | docker container rm ${STOP} > /dev/null 2>&1 64 | startup 65 | fi 66 | else 67 | startup 68 | fi 69 | } 70 | 71 | function main() 72 | { 73 | NUM=$# 74 | if [ $NUM -eq 1 ] 75 | then 76 | parse_arg "$@" 77 | fi 78 | 79 | run "$@" 80 | exit 0 81 | } 82 | 83 | main "$@" -------------------------------------------------------------------------------- /dockerfiles/wps/wps_symbol_fonts.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Document-Collection/Containerization-Automation/1c26d368b07a390523ec1d8ab65f0b208bb16cf2/dockerfiles/wps/wps_symbol_fonts.zip -------------------------------------------------------------------------------- /docs/Travis-CI.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Document-Collection/Containerization-Automation/1c26d368b07a390523ec1d8ab65f0b208bb16cf2/docs/Travis-CI.md -------------------------------------------------------------------------------- /docs/docker/advanced/[Docker][SSH]远程登录Ubuntu.md: -------------------------------------------------------------------------------- 1 | 2 | # [Docker][SSH]远程登录Ubuntu 3 | 4 | 参考: 5 | 6 | [ssh远程连接docker中的container](https://blog.csdn.net/vincent2610/article/details/52490397) 7 | 8 | [Dockerize an SSH service](https://docs.docker.com/engine/examples/running_ssh_service/) 9 | 10 | 通过`docker`启动`Ubuntu`镜像,通过`ssh`进行远程登录 11 | 12 | ## Dockerfile 13 | 14 | 参考:[sshd命令](https://man.linuxde.net/sshd) 15 | 16 | 编写`Dockerfile`文件实现`ssh`应用安装,密码设置以及`sshd`命令后台运行 17 | 18 | ``` 19 | FROM zjzstu/ubuntu:18.04 20 | 21 | RUN apt-get update && apt-get install -y openssh-server 22 | RUN mkdir /var/run/sshd 23 | RUN echo 'root:THEPASSWORDYOUCREATED' | chpasswd 24 | RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config 25 | 26 | # SSH login fix. Otherwise user is kicked off after login 27 | RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd 28 | 29 | EXPOSE 22 30 | CMD ["/usr/sbin/sshd", "-D"] 31 | ``` 32 | 33 | * `FROM`指令使用`zjzstu/ubuntu:18.04`作为父镜像 34 | * `RUN`指令更新已安装应用,同时安装`openssh-server` 35 | * `RUN`指令创建文件夹`/var/run/sshd` 36 | * `RUN`指令指定登录密码,修改`THEPASSWORDYOUCREATED`为自定义密码 37 | * `RUN`指令允许`ssh`登录`root`账户,修改文件`/etc/ssh/sshd_config`中的`#PermitRootLogin prohibit-password`为`PermitRootLogin yes` 38 | * 对于`Ubuntu 14.04`而言,默认设置为`PermitRootLogin without-password` 39 | * **注意**:对于`Ubuntu 16.04`而言,`ssh`默认打开了`PermitRootLogin`功能;对于`Ubuntu 18.04`而言,`ssh`默认关闭了`PermitRootLogin`功能。所以如果使用`Ubuntu 16.04`,需要将`#`号去除 40 | * `RUN`指令设置`/etc/pam.d/sshd`,防止用户在登录后将被踢出 41 | * `EXPOSE`指令设置容器监听端口`22` 42 | * `CMD`指令设置容器启动`sshd`,并在后台运行(`-D`表示以后台守护进程方式运行服务器) 43 | 44 | ## 执行 45 | 46 | 首先生成镜像`zjzstu/ubuntu:18.04-ssh`,实现如下: 47 | 48 | ``` 49 | $ docker build -t zjzstu/ubuntu:18.04-ssh . 50 | ``` 51 | 52 | 启动镜像生成容器`test_sshd`,实现如下: 53 | 54 | ``` 55 | $ docker run -d -P --name test_sshd zjzstu/ubuntu:18.04-ssh 56 | 1b44046832b4fd13b1c60921567a431e5aff3bd4fe753ebb6c1e29b2df277828 57 | ``` 58 | 59 | * 参数`-d`表示后台运行 60 | * 参数`-P`表示将容器的端口(`22`)发布到主机 61 | * 参数`--name`表示设置容器名 62 | 63 | 使用命令`docker port`查询容器映射的主机端口 64 | 65 | ``` 66 | $ docker ps 67 | CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 68 | 1b44046832b4 zjzstu/ubuntu:18.04-ssh "/usr/sbin/sshd -D" About a minute ago Up About a minute 0.0.0.0:32769->22/tcp test_sshd 69 | 70 | $ docker port 1b44 71 | 22/tcp -> 0.0.0.0:32769 72 | ``` 73 | 74 | 即可在主机使用`ssh`连接容器`test_sshd` 75 | 76 | ``` 77 | $ ssh root@127.0.0.1 -p 32769 78 | The authenticity of host '[127.0.0.1]:32769 ([127.0.0.1]:32769)' can't be established. 79 | ECDSA key fingerprint is SHA256:LYUoJeWTbnRgJDxjvtAbukkhVRRXPiDHliUPg/c8wyI. 80 | Are you sure you want to continue connecting (yes/no)? yes 81 | Warning: Permanently added '[127.0.0.1]:32769' (ECDSA) to the list of known hosts. 82 | root@127.0.0.1's password: 83 | ... 84 | ... 85 | root@1b44046832b4:~# 86 | ``` 87 | 88 | ## 自定义 89 | 90 | 1. 主机`IP 127.0.0.1`可以替换为`localhost` 91 | 92 | $ ssh root@localhost -p 32769 93 | 94 | 2. 可以在启动容器时指定主机端口号 95 | 96 | $ docker run -d -p 32212:22 --name test_sshd zjzstu/ubuntu:18.04-ssh 97 | 98 | 参数`-p`将容器端口`22`映射到主机端口`32212` 99 | 100 | ## 环境变量 101 | 102 | `sshd`会在启动`shell`之前对会对环境进行清理,通过`Dockerfile`中`ENV`指令输入的环境变量将会失效 103 | 104 | 有两种解决方法: 105 | 106 | 1. 在`Dockerfile`中输入环境变量到`shell`初始文件,比如`/etc/profile` 107 | 108 | ... 109 | # 无效 110 | ENV NOTVISIBLE "in users profile" 111 | # 有效 112 | RUN echo "export VISIBLE=now" >> /etc/profile 113 | 114 | EXPOSE 22 115 | CMD ["/usr/sbin/sshd", "-D"] 116 | 117 | 2. 启动容器时手动设置 118 | 119 | $ docker run -e ENV=value ... -------------------------------------------------------------------------------- /docs/docker/advanced/[Ubuntu]nvidia-docker安装.md: -------------------------------------------------------------------------------- 1 | # [Ubuntu]nvidia-docker安装 2 | 3 | 参考:[NVIDIA/nvidia-docker](https://github.com/NVIDIA/nvidia-docker) 4 | 5 | 安装`Nvidia`容器工具包,允许在容器中实现`GPU`加速 6 | 7 | ![](./imgs/docker-nvidia.png) 8 | 9 | ## 环境 10 | 11 | 当前主机系统为`Ubuntu 18.04`,`Docker`版本为`19.03.5`,并且主机已安装了`Nvidia`驱动,参考[[Ubuntu 18.04]PPA方式安装Nvidia驱动](https://zj-linux-guide.readthedocs.io/zh_CN/latest/tool-install-configure/[Ubuntu%2018.04]PPA%E6%96%B9%E5%BC%8F%E5%AE%89%E8%A3%85Nvidia%E9%A9%B1%E5%8A%A8/) 12 | 13 | ## 安装 14 | 15 | 在主机系统上安装`Nvidia`容器工具包 16 | 17 | ``` 18 | # Add the package repositories 19 | $ distribution=$(. /etc/os-release;echo $ID$VERSION_ID) 20 | $ curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - 21 | $ curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list 22 | 23 | $ sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit 24 | $ sudo systemctl restart docker 25 | ``` 26 | 27 | ## 测试 28 | 29 | `Nvidia`提供了几个已配置好`cuda`的镜像,参考[nvidia](https://hub.docker.com/u/nvidia) 30 | 31 | 安装完成后,测试容器中是否可以使用`cuda` 32 | 33 | ``` 34 | $ docker run --gpus all nvidia/cuda:10.2-base-ubuntu18.04 nvidia-smi 35 | Unable to find image 'nvidia/cuda:10.2-base-ubuntu18.04' locally 36 | 10.2-base-ubuntu18.04: Pulling from nvidia/cuda 37 | Digest: sha256:15fc2f88d247eaa8781f6d3d01613250771ac9394e4543257f2bba5610b96974 38 | Status: Downloaded newer image for nvidia/cuda:10.2-base-ubuntu18.04 39 | Tue Dec 24 12:01:41 2019 40 | +-----------------------------------------------------------------------------+ 41 | | NVIDIA-SMI 440.26 Driver Version: 440.26 CUDA Version: 10.2 | 42 | |-------------------------------+----------------------+----------------------+ 43 | | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | 44 | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | 45 | |===============================+======================+======================| 46 | | 0 GeForce 940MX Off | 00000000:02:00.0 Off | N/A | 47 | | N/A 42C P0 N/A / N/A | 643MiB / 2004MiB | 21% Default | 48 | +-------------------------------+----------------------+----------------------+ 49 | 50 | +-----------------------------------------------------------------------------+ 51 | | Processes: GPU Memory | 52 | | GPU PID Type Process name Usage | 53 | |=============================================================================| 54 | +-----------------------------------------------------------------------------+ 55 | ``` -------------------------------------------------------------------------------- /docs/docker/advanced/[alpine]源配置.md: -------------------------------------------------------------------------------- 1 | 2 | # [alpine]源配置 3 | 4 | ## 问题 5 | 6 | 默认`alpine`源地址可通过`/etc/apk/repositories`文件查看 7 | 8 | ``` 9 | $ docker run -it alpine 10 | / # cd /etc/apk/ 11 | /etc/apk # pwd 12 | /etc/apk 13 | /etc/apk # ls 14 | arch keys protected_paths.d repositories world 15 | /etc/apk # 16 | /etc/apk # cat repositories 17 | http://dl-cdn.alpinelinux.org/alpine/v3.11/main 18 | http://dl-cdn.alpinelinux.org/alpine/v3.11/community 19 | ``` 20 | 21 | 使用默认源无法下载应用,以`NodeJS`为例 22 | 23 | ``` 24 | /etc/apk # apk add nodejs 25 | fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz 26 | ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.11/main: temporary error (try again later) 27 | WARNING: Ignoring APKINDEX.70f61090.tar.gz: No such file or directory 28 | fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz 29 | ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.11/community: temporary error (try again later) 30 | WARNING: Ignoring APKINDEX.ca2fea5b.tar.gz: No such file or directory 31 | ERROR: unsatisfiable constraints: 32 | nodejs (missing): 33 | required by: world[nodejs] 34 | ``` 35 | 36 | ## 解析 37 | 38 | 参考[Alpine Linux 源使用帮助](https://mirrors.ustc.edu.cn/help/alpine.html),替换成国内镜像源 39 | 40 | ``` 41 | /etc/apk # sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories 42 | /etc/apk # 43 | /etc/apk # cat repositories 44 | http://mirrors.ustc.edu.cn/alpine/v3.11/main 45 | http://mirrors.ustc.edu.cn/alpine/v3.11/community 46 | ``` 47 | 48 | 配置`NodeJS`环境如下 49 | 50 | ``` 51 | /etc/apk # apk add nodejs 52 | fetch http://mirrors.ustc.edu.cn/alpine/v3.11/main/x86_64/APKINDEX.tar.gz 53 | fetch http://mirrors.ustc.edu.cn/alpine/v3.11/community/x86_64/APKINDEX.tar.gz 54 | (1/7) Installing ca-certificates (20191127-r1) 55 | (2/7) Installing c-ares (1.15.0-r0) 56 | (3/7) Installing libgcc (9.2.0-r3) 57 | (4/7) Installing nghttp2-libs (1.40.0-r0) 58 | (5/7) Installing libstdc++ (9.2.0-r3) 59 | (6/7) Installing libuv (1.34.0-r0) 60 | (7/7) Installing nodejs (12.15.0-r1) 61 | Executing busybox-1.31.1-r9.trigger 62 | Executing ca-certificates-20191127-r1.trigger 63 | OK: 36 MiB in 21 packages 64 | /etc/apk # 65 | /etc/apk # apk add npm 66 | (1/1) Installing npm (12.15.0-r1) 67 | Executing busybox-1.31.1-r9.trigger 68 | OK: 64 MiB in 22 packages 69 | ``` 70 | 71 | ## dockerfile 72 | 73 | 编写一个`Dockerfile`脚本,实现镜像源替换 74 | 75 | ``` 76 | FROM alpine:latest 77 | LABEL maintainer "zhujian " 78 | 79 | RUN set -eux && sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories 80 | ``` 81 | 82 | ### 构建 83 | 84 | ``` 85 | $ docker build -t zjzstu/alpine:latest . 86 | Sending build context to Docker daemon 2.048kB 87 | Step 1/3 : FROM alpine:latest 88 | ---> e7d92cdc71fe 89 | Step 2/3 : LABEL maintainer "zhujian " 90 | ---> Running in e887d20623cd 91 | Removing intermediate container e887d20623cd 92 | ---> 260632029e45 93 | Step 3/3 : RUN set -eux && sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories 94 | ---> Running in 0481eecdd0e9 95 | + sed -i s/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g /etc/apk/repositories 96 | Removing intermediate container 0481eecdd0e9 97 | ---> 6c891a208c35 98 | Successfully built 6c891a208c35 99 | ``` 100 | 101 | ### 运行 102 | 103 | ``` 104 | $ docker run -it zjzstu/alpine 105 | / # node 106 | /bin/sh: node: not found 107 | / # apk add nodejs 108 | fetch http://mirrors.ustc.edu.cn/alpine/v3.11/main/x86_64/APKINDEX.tar.gz 109 | fetch http://mirrors.ustc.edu.cn/alpine/v3.11/community/x86_64/APKINDEX.tar.gz 110 | (1/7) Installing ca-certificates (20191127-r1) 111 | (2/7) Installing c-ares (1.15.0-r0) 112 | (3/7) Installing libgcc (9.2.0-r3) 113 | (4/7) Installing nghttp2-libs (1.40.0-r0) 114 | (5/7) Installing libstdc++ (9.2.0-r3) 115 | (6/7) Installing libuv (1.34.0-r0) 116 | (7/7) Installing nodejs (12.15.0-r1) 117 | Executing busybox-1.31.1-r9.trigger 118 | Executing ca-certificates-20191127-r1.trigger 119 | OK: 36 MiB in 21 packages 120 | / # 121 | / # node -v 122 | v12.15.0 123 | ``` -------------------------------------------------------------------------------- /docs/docker/advanced/[docker search]搜索镜像.md: -------------------------------------------------------------------------------- 1 | 2 | # [docker search]搜索镜像 3 | 4 | 参考:[docker search](https://docs.docker.com/engine/reference/commandline/search/) 5 | 6 | `Docker`提供了命令`docker search`来搜索`Docker Hub`镜像 7 | 8 | ## 语法 9 | 10 | ``` 11 | docker search [OPTIONS] TERM 12 | ``` 13 | 14 | 参数有以下4种: 15 | 16 | 1. `--limit`:搜索数量,默认`25` 17 | 2. `--no-trunc`:不截断输出 18 | 3. `--filter/-f`:基于给定条件过滤输出 19 | 4. `--format`:基于`GO`模板输出 20 | 21 | ## limit 22 | 23 | 默认打印`25`条搜索结果,可随机调整: 24 | 25 | ``` 26 | $ docker search --limit=3 hello-world 27 | NAME DESCRIPTION STARS OFFICIAL AUTOMATED 28 | hello-world Hello World! (an example of minimal Dockeriz… 1030 [OK] 29 | tutum/hello-world Image to test docker deployments. Has Apache… 63 [OK] 30 | ansibleplaybookbundle/hello-world-apb An APB which deploys a sample Hello World! a… 0 [OK] 31 | ``` 32 | 33 | ## no-trunc 34 | 35 | 如果描述过长,默认会截断输出,可调整: 36 | 37 | ``` 38 | $ docker search --limit=3 --no-trunc hello-world 39 | NAME DESCRIPTION STARS OFFICIAL AUTOMATED 40 | hello-world Hello World! (an example of minimal Dockerization) 1030 [OK] 41 | tutum/hello-world Image to test docker deployments. Has Apache with a 'Hello World' page listening in port 80. 63 [OK] 42 | ansibleplaybookbundle/hello-world-apb An APB which deploys a sample Hello World! app 0 [OK] 43 | ``` 44 | 45 | ## filter 46 | 47 | 按给定条件过滤搜索结果,当前有`3`种过滤选择: 48 | 49 | 1. 星数:`starts=3` 50 | 2. 是否自动构建:`is-automated=true/false` 51 | 3. 是否官方:`is-official=true/false` 52 | 53 | 这些过滤条件可一起使用 54 | 55 | ``` 56 | $ docker search --limit=3 --filter stars=3 --filter is-automated=false --filter is-official=true ubuntu 57 | NAME DESCRIPTION STARS OFFICIAL AUTOMATED 58 | ubuntu Ubuntu is a Debian-based Linux operating sys… 9965 [OK] 59 | ubuntu-upstart Upstart is an event-based replacement for th… 99 [OK] 60 | ubuntu-debootstrap debootstrap --variant=minbase --components=m… 40 [OK] 61 | ``` 62 | 63 | ## format 64 | 65 | 按照`GO`模板指定格式输出,有以下占位符: 66 | 67 | ![](./imgs/go-format.png) 68 | 69 | * `.Name`:镜像名 70 | * `.Description`:镜像描述 71 | * `.StarCount`:星数 72 | * `.IsOfficial`:如果镜像是官方的,输出`OK` 73 | * `.IsAutomated`:如果镜像是自动生成的,输出`OK` 74 | 75 | 下面仅输出镜像名和是否官方: 76 | 77 | ``` 78 | $ docker search --limit=3 --format "{{.Name}}: {{.IsOfficial}}" hello-world 79 | hello-world: [OK] 80 | tutum/hello-world: 81 | ansibleplaybookbundle/hello-world-apb: 82 | ``` 83 | 84 | 如果模板中添加指令`table`,会添加列标题 85 | 86 | ``` 87 | $ docker search --limit=3 --format "table {{.Name}}\t{{.IsOfficial}}" hello-world 88 | NAME OFFICIAL 89 | hello-world [OK] 90 | tutum/hello-world 91 | ansibleplaybookbundle/hello-world-apb 92 | ``` -------------------------------------------------------------------------------- /docs/docker/advanced/[译]Docker开发最佳实践.md: -------------------------------------------------------------------------------- 1 | 2 | # [译]Docker开发最佳实践 3 | 4 | 原文地址:[Docker development best practices](https://docs.docker.com/develop/dev-best-practices/) 5 | 6 | 下面的开发模式已经被证明有助于人们使用`Docker`构建应用程序。如果你发现了我们应该补充的东西,[请告诉我们](https://github.com/docker/docker.github.io/issues/new) 7 | 8 | ## How to keep your images small 9 | 10 | 启动容器或服务时,小镜像在网络上传输更快,在内存中加载更快。有一些经验法则可以使镜像保持较小尺寸: 11 | 12 | * 从一个合适的基础镜像开始。例如,如果您需要一个`jdk`,可以考虑基于官方的`openjdk`镜像,而不是用通用的`ubuntu`镜像,再安装`openjdk` 13 | * [Use multistage builds](https://docs.docker.com/engine/userguide/eng-image/multistage-build/)。例如,您可以使用`maven`镜像来构建Java应用程序,然后重置为`tomcat`镜像,并将`Java`工件复制到部署应用程序的正确位置,所有这些都在同一个`Dockerfile`中。这意味着您的最终镜像不包括构建所拉入的所有库和依赖项,而只包括运行它们所需的工件和环境 14 | * 如果需要使用不包含多级构建功能(`multistage build`)的`Docker`版本,请尝试通过最小化`Dockerfile`中`RUN`命令的数量来减少镜像层数。您可以通过将多个命令合并到一个`RUN`中,并使用`shell`的机制将它们组合在一起来实现。考虑以下两个片段。第一个在镜像中创建两个层,而第二个只创建一个层 15 | ``` 16 | RUN apt-get -y update 17 | RUN apt-get install -y python 18 | ``` 19 | 20 | ``` 21 | RUN apt-get -y update && apt-get install -y python 22 | ``` 23 | * 如果您有多个具有许多共同点的镜像,请考虑使用共享组件创建自己的[基础镜像](https://docs.docker.com/engine/userguide/eng-image/baseimages/)。`Docker`只需要加载一次公共层即可(因为它们在本地缓存了)。这意味着您的后续镜像可以更高效地使用`Docker`主机上的内存并更快地加载 24 | * 要使生产镜像保持精简但允许调试,请考虑使用生产镜像作为调试镜像的基础镜像。可以在生产镜像的顶部添加额外的测试或调试工具 25 | * 在构建镜像时,请始终使用有用的标记对其进行标记,这些标记用于编码版本信息、预期目标(例如`prod`或`test`)、稳定性或在不同环境中部署应用程序时有用的其他信息。不要依赖于自动创建的`latest`标记 26 | 27 | ## Where and how to persist application data 28 | 29 | * 避免使用存储驱动程序([storage drivers](https://docs.docker.com/engine/userguide/storagedriver/))将应用程序数据存储在容器的可写层中。这会增加容器的大小,从`I/O`的角度来看,这比使用卷(`volume`)或绑定装载(`bind mount`)效率低 30 | * 使用卷([volume](https://docs.docker.com/engine/admin/volumes/volumes/))存储数据 31 | * 在开发过程中,可能需要挂载源目录或刚刚构建到容器中的二进制文件,这时使用绑定挂载([bind mounts](https://docs.docker.com/engine/admin/volumes/bind-mounts/))是合适的。对于生产环境,请改用卷(`volume`),将其挂载到与开发过程中进行绑定挂载相同的位置 32 | * 在生产环境中,使用[secrets](https://docs.docker.com/engine/swarm/secrets/)存储服务使用的敏感应用程序数据,并对非敏感数据(如配置文件)使用[configs](https://docs.docker.com/engine/swarm/configs/)。如果您当前使用独立容器,请考虑迁移到使用单个副本服务,以便您可以利用这些仅限服务的功能 33 | 34 | ## Use swarm services when possible 35 | 36 | * 尽可能的使用`swarm`服务设计应用程序 37 | * 即使只需要运行应用程序的单个实例,`swarm`服务也比独立容器提供了一些优势。服务的配置是声明性的,`Docker`总是保持所需的和实际的状态同步 38 | * 网络和卷可以与`swarm`服务连接和断开,docker以非干扰(`non-disruptive`)的方式处理单个服务容器的重新部署。而独立容器需要手动停止、删除和重新创建以适应配置更改 39 | * 一些特性,例如存储[secrets](https://docs.docker.com/engine/swarm/secrets/)和[configs](https://docs.docker.com/engine/swarm/configs/)的能力,只针对服务而不是独立容器可用。这些特性允许您尽可能地保持镜像通用性,并避免在`Docker`镜像或容器本身中存储敏感数据 40 | * 使用`docker stack deploy`处理任何镜像拉取,而不是使用`docker pull`。这样,部署就不会试图从已关闭的节点中拉取。此外,当新的节点被添加到`swarm`中时,镜像会被自动提取 41 | 42 | 在`swarm`服务的节点之间共享数据有一些限制。如果你使用[Docker for AWS](https://docs.docker.com/docker-for-aws/persistent-data-volumes/)或[Docker for Azure](https://docs.docker.com/docker-for-azure/persistent-data-volumes/),你可以使用`Cloudstor`插件在`swarm`服务节点之间共享数据。您还可以将应用程序数据写入支持同步更新的单独数据库 43 | 44 | ## Use CI/CD for testing and deployment 45 | 46 | * 当对源代码控制进行更改或创建拉取请求时,请使用[Docker Hub](https://docs.docker.com/docker-hub/builds/automated-build/)或其他`CI/CD`管道自动进行生成,标记`Docker`镜像并对其进行测试 47 | * 在[Docker Engine-Enterprise](https://docs.docker.com/ee/)中更进一步,它要求您的开发、测试和安全团队在镜像部署到生产环境之前对其进行签名。这样就可以确保在将镜像部署到生产环境中之前,它已经过了测试,并得到了开发、质量和安全团队的批准 48 | 49 | ## Differences in development and production environments 50 | 51 | ![](./imgs/diff_dev_prod.png) -------------------------------------------------------------------------------- /docs/docker/advanced/imgs/diff_dev_prod.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Document-Collection/Containerization-Automation/1c26d368b07a390523ec1d8ab65f0b208bb16cf2/docs/docker/advanced/imgs/diff_dev_prod.png -------------------------------------------------------------------------------- /docs/docker/advanced/imgs/docker-nvidia.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Document-Collection/Containerization-Automation/1c26d368b07a390523ec1d8ab65f0b208bb16cf2/docs/docker/advanced/imgs/docker-nvidia.png -------------------------------------------------------------------------------- /docs/docker/advanced/imgs/go-format.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Document-Collection/Containerization-Automation/1c26d368b07a390523ec1d8ab65f0b208bb16cf2/docs/docker/advanced/imgs/go-format.png -------------------------------------------------------------------------------- /docs/docker/advanced/imgs/match_rule.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Document-Collection/Containerization-Automation/1c26d368b07a390523ec1d8ab65f0b208bb16cf2/docs/docker/advanced/imgs/match_rule.png -------------------------------------------------------------------------------- /docs/docker/advanced/编写.dockerignore.md: -------------------------------------------------------------------------------- 1 | 2 | # 编写.dockerignore 3 | 4 | 参考:[.dockerignore file](https://docs.docker.com/engine/reference/builder/#dockerignore-file) 5 | 6 | `.dockerignore`的作用和`.gitignore`类似,用于忽略或指定哪些文件不被`ADD`或`COPY`指令操作 7 | 8 | ## 匹配规则 9 | 10 | 其文件匹配规则遵循[Go's func Match](https://golang.org/pkg/path/filepath/#Match) 11 | 12 | ![](./imgs/match_rule.png) 13 | 14 | 其中通配符有星号、问号以及中括号 15 | 16 | * 星号(`*`)表示匹配任何非分隔字符序列 17 | * 问号(`?`)表示匹配任何单个非分隔符字符 18 | * 中括号(`[`)表示匹配位于字符范围内的字符 19 | 20 | `Docker`还提供了一个特殊的通配符字符串`**`,用于匹配任何路径。比如`**/*.go`将匹配所有目录中以`.go`结尾的所有文件,包括生成上下文的根目录 21 | 22 | 以`#`开头的行被视为注释,不起作用 23 | 24 | 以`!`开头的匹配字符串表示指定匹配文件不被忽略 25 | 26 | ## 示例一 27 | 28 | `.dockerignore`文件内容如下: 29 | 30 | ``` 31 | # comment 32 | */temp* 33 | */*/temp* 34 | temp? 35 | ``` 36 | 37 | * 第一行是注释 38 | * 第二行表示忽略所有二级目录中以`temp`开头的文件 39 | * 第三行表示忽略所有三级目录中以`temp`开头的文件 40 | * 第四行表示忽略根目录中以`temp`开头,后跟一个字符的文件 41 | 42 | ## 示例二 43 | 44 | 使用感叹号`!`指定匹配文件不被忽略,还需要考虑其在`.dockerignore`文件中的使用位置 45 | 46 | ``` 47 | *.md 48 | !README.md 49 | ``` 50 | 51 | 除了`README.md`外的所有`.md`文件都被忽略 52 | 53 | ``` 54 | *.md 55 | !README*.md 56 | README-secret.md 57 | ``` 58 | 59 | 此时`README-secret.md`同样会被忽略 60 | 61 | ``` 62 | *.md 63 | README-secret.md 64 | !README*.md 65 | ``` 66 | 67 | 此时`README-secret.md`同样不会被忽略 68 | 69 | ## 示例三 70 | 71 | 可以通过`.dockerignore`文件忽略`Dockerfile`和`.dockerignore`文件。这些文件仍然被发送到守护进程,因为需要它们来完成工作。但是`ADD`和`COPY`指令不会将它们复制到镜像中 -------------------------------------------------------------------------------- /docs/docker/advanced/镜像迁移.md: -------------------------------------------------------------------------------- 1 | 2 | # 镜像迁移 3 | 4 | 在服务器下载`docker`镜像太慢了,想着能不能在本地下载完成后迁移到服务器上。在网上一查,果然有这功能,参考[Docker镜像迁移](https://blog.csdn.net/sunbocong/article/details/78928535) 5 | 6 | ## docker save 7 | 8 | 保存一个或多个镜像为归档文件 9 | 10 | ``` 11 | $ docker save --help 12 | 13 | Usage: docker save [OPTIONS] IMAGE [IMAGE...] 14 | 15 | Save one or more images to a tar archive (streamed to STDOUT by default) 16 | 17 | Options: 18 | -o, --output string Write to a file, instead of STDOUT 19 | ``` 20 | 21 | ## docker load 22 | 23 | 从归档文件中加载镜像 24 | 25 | ``` 26 | $ docker load --help 27 | 28 | Usage: docker load [OPTIONS] 29 | 30 | Load an image from a tar archive or STDIN 31 | 32 | Options: 33 | -i, --input string Read from tar archive file, instead of STDIN 34 | -q, --quiet Suppress the load output 35 | ``` 36 | 37 | ## 示例 38 | 39 | ``` 40 | # 打包 41 | $ docker save nginx:latest -o nginx.tar.gz 42 | # 加载 43 | $ docker load -i nginx.tar.gz 44 | ``` -------------------------------------------------------------------------------- /docs/docker/basic/Docker启动设置.md: -------------------------------------------------------------------------------- 1 | 2 | # Docker启动设置 3 | 4 | 参考:[Control Docker with systemd](https://docs.docker.com/config/daemon/systemd/) 5 | 6 | 使用命令`systemctl`或`service`实现`docker`守护进程的启动和关闭 7 | 8 | ## systemctl使用 9 | 10 | 查看`docker`状态 11 | 12 | ``` 13 | $ systemctl status docker 14 | ● docker.service - Docker Application Container Engine 15 | Loaded: loaded (/lib/systemd/system/docker.service; disabled; vendor preset: enabled) 16 | Active: inactive (dead) since 四 2019-09-19 19:13:51 CST; 3s ago 17 | Docs: https://docs.docker.com 18 | ... 19 | ... 20 | ``` 21 | 22 | 启动`docker` 23 | 24 | ``` 25 | $ systemctl start docker 26 | ``` 27 | 28 | 关闭`docker` 29 | 30 | ``` 31 | $ systemctl stop docker 32 | ``` 33 | 34 | ## service使用 35 | 36 | 查看`docker`状态 37 | 38 | ``` 39 | $ service docker status 40 | ● docker.service - Docker Application Container Engine 41 | Loaded: loaded (/lib/systemd/system/docker.service; disabled; vendor preset: enabled) 42 | Active: inactive (dead) since 四 2019-09-19 19:13:51 CST; 2min 51s ago 43 | Docs: https://docs.docker.com 44 | Main PID: 8263 (code=exited, status=0/SUCCESS) 45 | ... 46 | ... 47 | ``` 48 | 49 | 启动`docker` 50 | 51 | ``` 52 | $ service docker start 53 | ``` 54 | 55 | 关闭`docker` 56 | 57 | ``` 58 | $ service docker stop 59 | ``` 60 | -------------------------------------------------------------------------------- /docs/docker/basic/[Aliyun]镜像加速.md: -------------------------------------------------------------------------------- 1 | 2 | # [Aliyun]镜像加速 3 | 4 | 参考:[Docker 镜像加速器](https://yq.aliyun.com/articles/29941) 5 | 6 | 配置`阿里云镜像加速器`来加快远程镜像下载 7 | 8 | ## 查询加速地址 9 | 10 | 登录[容器镜像服务](https://cr.console.aliyun.com/cn-hangzhou/mirrors)控制台,选择左侧的`镜像加速器`,获取`加速器地址` 11 | 12 | ## `Ubuntu`配置 13 | 14 | 修改配置文件 15 | 16 | # 没有就新建该文件 17 | /etc/docker/daemon.json 18 | 19 | 添加 20 | 21 | { 22 | "registry-mirrors": [""] 23 | } 24 | 25 | ## 测试 26 | 27 | 重启`docker`服务 28 | 29 | $ sudo /etc/init.d/docker restart 30 | [ ok ] Restarting docker (via systemctl): docker.service. 31 | # 或者 32 | $ sudo systemctl daemon-reload 33 | $ sudo systemctl restart docker 34 | 35 | 查看是否已配置 36 | 37 | $ sudo docker info | grep "aliyun" 38 | https://ssws38gn.mirror.aliyuncs.com/ 39 | 40 | 测试命令 41 | 42 | $ sudo docker run -it ubuntu bash -------------------------------------------------------------------------------- /docs/docker/basic/[Docker]DNS设置.md: -------------------------------------------------------------------------------- 1 | 2 | # [Docker]DNS设置 3 | 4 | 参考: 5 | 6 | [daemon](https://docs.docker.com/engine/reference/commandline/dockerd/) 7 | 8 | [Container networking](https://docs.docker.com/config/containers/container-networking/) 9 | 10 | ## 全局设置 11 | 12 | 在`docker`配置文件`/etc/docker/daemon.json`中设置 13 | 14 | ``` 15 | $ cat /etc/docker/daemon.json 16 | { 17 | "dns": ["119.29.29.29", "223.5.5.5", "223.6.6.6"] 18 | } 19 | ``` 20 | 21 | 重新启动`docker`服务 22 | 23 | ``` 24 | $ sudo /etc/init.d/docker restart 25 | ``` 26 | 27 | ## 容器设置 28 | 29 | 使用属性`--dns`指定要载入容器的`DNS` 30 | 31 | ``` 32 | $ docker run -it --dns 233.5.5.5 --dns 233.6.6.6 ubuntu bash 33 | ``` -------------------------------------------------------------------------------- /docs/docker/basic/[Docker][Ubuntu 18.04]中文环境配置.md: -------------------------------------------------------------------------------- 1 | 2 | # [Docker][Ubuntu 18.04]中文环境配置 3 | 4 | 当前使用`Docker Ubuntu 18.04`镜像,对官方镜像进行进一步配置以适应中文开发环境。有以下几个方面: 5 | 6 | 1. 镜像源 7 | 2. 中文字体 8 | 3. 中文字符集 9 | 4. 时区 10 | 5. 中文输入法 11 | 12 | ## 镜像源 13 | 14 | 参考[[Ali mirror]更换国内源](https://zj-linux-guide.readthedocs.io/zh_CN/latest/tool-install-configure/[Ali%20mirror]]%E6%9B%B4%E6%8D%A2%E5%9B%BD%E5%86%85%E6%BA%90/) 15 | 16 | ## 中文字体 17 | 18 | 参考:[[Ubuntu]中文乱码](https://zj-linux-guide.readthedocs.io/zh_CN/latest/tool-install-configure/[Ubuntu]%E4%B8%AD%E6%96%87%E4%B9%B1%E7%A0%81/) 19 | 20 | ## zh_CN.UTF_8字符集设置 21 | 22 | 参考[[Linux][locale]字符集设置](https://zj-linux-guide.readthedocs.io/zh_CN/latest/tool-install-configure/[LOCALE]%E5%AD%97%E7%AC%A6%E9%9B%86%E8%AE%BE%E7%BD%AE/) 23 | 24 | ## 时区设置 25 | 26 | 参考: 27 | 28 | [Synchronize timezone from host to container](https://forums.docker.com/t/synchronize-timezone-from-host-to-container/39116) 29 | 30 | [apt-get install tzdata noninteractive](https://stackoverflow.com/questions/44331836/apt-get-install-tzdata-noninteractive) 31 | 32 | `Docker Ubuntu 18.04`默认的时区和亚洲 - 上海时区相差`8`个小时(东八区) 33 | 34 | 在`Dockerfile`中增加以下命令 35 | 36 | ``` 37 | ENV DEBIAN_FRONTEND=noninteractive 38 | RUN ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 39 | RUN apt-get install -y tzdata && dpkg-reconfigure --frontend noninteractive tzdata 40 | ``` 41 | 42 | 还有一种方式是在使用`docker run`命令时同步主机时区 43 | 44 | ``` 45 | $ docker run -v /etc/localtime:/etc/localtime:ro ... 46 | ``` 47 | 48 | ## 中文输入法 49 | 50 | 在主机安装了`fcitx`中文输入法 - `google-pinyin`,在启动容器时配置 51 | 52 | ``` 53 | docker run \ 54 | -e XMODIFIERS="@im=fcitx" \ 55 | -e QT_IM_MODULE="fcitx" \ 56 | -e GTK_IM_MODULE="fcitx" \ 57 | ... 58 | ... 59 | ``` 60 | 61 | ## 编辑 62 | 63 | `Dockerfile`脚本如下: 64 | 65 | ``` 66 | FROM ubuntu:18.04 67 | LABEL maintainer "zhujian " 68 | 69 | COPY sources.list . 70 | ENV DEBIAN_FRONTEND=noninteractive 71 | RUN set -eux && \ 72 | rm /etc/apt/sources.list && \ 73 | mv sources.list /etc/apt/sources.list && \ 74 | apt-get update && \ 75 | apt-get install -y locales tzdata xfonts-wqy && \ 76 | locale-gen zh_CN.UTF-8 && \ 77 | update-locale LANG=zh_CN.UTF-8 LANGUAGE=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 && \ 78 | ln -fs /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ 79 | dpkg-reconfigure --frontend noninteractive tzdata && \ 80 | find /var/lib/apt/lists -type f -delete && \ 81 | find /var/cache -type f -delete 82 | 83 | ENV LANG=zh_CN.UTF-8 LANGUAGE=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 84 | ``` 85 | 86 | * 加载`docker`官方镜像`ubuntu:18.04` 87 | * 复制源配置文件`sources.list`到镜像 88 | * 替换源配置文件并更新安装列表,设置中文字体、设置`zh_CN.UTF-8`并删除额外文件 89 | * 设置字符集环境变量 90 | 91 | ## 构建 92 | 93 | ``` 94 | $ docker build -t zjzstu/ubuntu:18.04 -t zjzstu/ubuntu:latest . 95 | ``` 96 | 97 | ## 使用 98 | 99 | ``` 100 | $ docker run \ 101 | -e XMODIFIERS="@im=fcitx" \ 102 | -e QT_IM_MODULE="fcitx" \ 103 | -e GTK_IM_MODULE="fcitx" \ 104 | -it --rm \ 105 | --name ubuntu \ 106 | zjzstu/ubuntu:18.04-zh \ 107 | bash 108 | ``` -------------------------------------------------------------------------------- /docs/docker/basic/[docker commit]保存容器为镜像.md: -------------------------------------------------------------------------------- 1 | 2 | # [docker commit]保存容器为镜像 3 | 4 | 保存已修改后的容器为新的镜像 5 | 6 | ## 语法 7 | 8 | ``` 9 | docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] 10 | ``` 11 | 12 | * 参数`CONTAINER`指定容器`ID` 13 | * 参数`REPOSITORY`指定新的镜像名,格式为 14 | * 参数`TAG`指定额外标记,比如版本号 15 | 16 | 可添加额外选项,指定作者名,提交信息,是否在提交时暂停容器以及是否应用`Dockerfile`指令到创建的镜像 17 | 18 | ![](./imgs/commit-options.png) 19 | 20 | ## 示例 21 | 22 | ``` 23 | $ docker commit --author zjzstu --message "using aliyun mirrors" f8f8 zjzstu/ubuntu:18.04 24 | sha256:5493327e7708602f5ebb0b42d638234bf47ff4ee23804d3b3a96535d4c8dcec3 25 | 26 | $ docker image ls 27 | REPOSITORY TAG IMAGE ID CREATED SIZE 28 | zjzstu/ubuntu 18.04 5493327e7708 19 seconds ago 109MB 29 | ``` -------------------------------------------------------------------------------- /docs/docker/basic/docker-hub使用.md: -------------------------------------------------------------------------------- 1 | 2 | # Docker Hub使用 3 | 4 | 参考:[Get Started, Part 2: Containers](https://docs.docker.com/get-started/part2/#recap-and-cheat-sheet-optional) 5 | 6 | 注册表(`registry`)是存储库(`repository`)的集合,存储库是镜像(`image`)的集合,类似于`github`存储库,但代码已经构建 7 | 8 | 注册表上的帐户可以创建多个存储库。[Docker Hub](https://hub.docker.com)是`Docker`官方的注册表,可用于`Docker`镜像的远程存储和分发 9 | 10 | ## 登录 11 | 12 | 首先在`Docker Hub`官网上注册账户,然后在本地登录 13 | 14 | ``` 15 | $ docker login 16 | Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one. 17 | Username: zjzstu 18 | Password: 19 | WARNING! Your password will be stored unencrypted in /home/zj/.docker/config.json. 20 | Configure a credential helper to remove this warning. See 21 | https://docs.docker.com/engine/reference/commandline/login/#credentials-store 22 | 23 | Login Succeeded$ docker run zjzstu/hello-world:0.1.0 24 | Unable to find image 'zjzstu/hello-world:0.1.0' locally 25 | 0.1.0: Pulling from zjzstu/hello-world 26 | 35c102085707: Already exists 27 | 251f5509d51d: Already exists 28 | 8e829fe70a46: Already exists 29 | 6001e1789921: Already exists 30 | a0083f503c5a: Pull complete 31 | Digest: sha256:6ad989ee32e1f170c8e8e6c4e7dc9ee650f33d67c4deb21837b07cb272f076ee 32 | Status: Downloaded newer image for zjzstu/hello-world:0.1.0 33 | Hello World 34 | ``` 35 | 36 | ## 标记 37 | 38 | 需要重新标记本地镜像,使其符合远程注册表的命名方式 39 | 40 | ``` 41 | $ docker tag IMAGE username/repository:tag 42 | ``` 43 | 44 | * 参数`IMAGE`表示本地镜像名 45 | * `username`表示账户名 46 | * `repository`表示仓库名 47 | * `tag`是可选的,但可以给定一个意义的标记 48 | 49 | 比如 50 | 51 | ``` 52 | $ docker tag zj:0.1.0 zjzstu/hello-world:0.1.0 53 | ``` 54 | 55 | 重新标记完成后会生成一个新的镜像名和标记,指向同一个镜像(`ID`相同) 56 | 57 | ``` 58 | $ docker image ls 59 | REPOSITORY TAG IMAGE ID CREATED SIZE 60 | zjzstu/hello-world 0.1.0 7515c3706b27 23 minutes ago 64.2MB 61 | zj 0.1.0 7515c3706b27 23 minutes ago 64.2MB 62 | ubuntu 18.04 a2a15febcdf3 4 weeks ago 64.2MB 63 | ``` 64 | 65 | ## 发布 66 | 67 | 上传已标记的镜像到仓库 68 | 69 | ``` 70 | $ docker push zjzstu/hello-world:0.1.0 71 | The push refers to repository [docker.io/zjzstu/hello-world] 72 | e8d6f0abd7b0: Pushed 73 | 122be11ab4a2: Mounted from library/ubuntu 74 | 7beb13bce073: Mounted from library/ubuntu 75 | f7eae43028b3: Mounted from library/ubuntu 76 | 6cebf3abed5f: Mounted from library/ubuntu 77 | 0.1.0: digest: sha256:6ad989ee32e1f170c8e8e6c4e7dc9ee650f33d67c4deb21837b07cb272f076ee size: 1359 78 | ``` 79 | 80 | 完成之后即可在仓库中查看:[zjzstu/hello-world](https://hub.docker.com/r/zjzstu/hello-world/tags) 81 | 82 | ## 拉取 83 | 84 | 运行镜像`zjzstu/hello-world:0.1.0`,如果本地不存在,则会从远程拉取 85 | 86 | ``` 87 | $ docker run zjzstu/hello-world:0.1.0 88 | Unable to find image 'zjzstu/hello-world:0.1.0' locally 89 | 0.1.0: Pulling from zjzstu/hello-world 90 | 35c102085707: Already exists 91 | 251f5509d51d: Already exists 92 | 8e829fe70a46: Already exists 93 | 6001e1789921: Already exists 94 | a0083f503c5a: Pull complete 95 | Digest: sha256:6ad989ee32e1f170c8e8e6c4e7dc9ee650f33d67c4deb21837b07cb272f076ee 96 | Status: Downloaded newer image for zjzstu/hello-world:0.1.0 97 | Hello World 98 | ``` -------------------------------------------------------------------------------- /docs/docker/basic/docker定位.md: -------------------------------------------------------------------------------- 1 | 2 | # docker定位 3 | 4 | 参考:[Get Started, Part 1: Orientation and setup](https://docs.docker.com/get-started/) 5 | 6 | 理解`docker`工具以及容器、镜像等重要组成的概念 7 | 8 | ## Docker概念 9 | 10 | `Docker`是开发人员和系统管理员使用容器开发、部署和运行应用程序的平台。使用`Linux`容器部署应用程序称为容器化(`containerization`) 11 | 12 | 容器化有以下优点: 13 | 14 | 1. 灵活性(`flexible`):即使最复杂的应用也可以被容器化 15 | 2. 轻量级(`lightweight`):容器之间相互作用并共享主机内核 16 | 3. 可互换性(`interchangeable`):您可以动态部署更新和升级 17 | 4. 可移植性(`portable`):本地构建,云端部署,任意运行 18 | 5. 可伸缩性(`scalable`):可以增加并自动分发容器副本 19 | 6. 可堆叠(`stackable`):可以垂直和动态堆叠服务 20 | 21 | ![](./imgs/laurel-docker-containers.png) 22 | 23 | ## 镜像和容器 24 | 25 | 容器(`container`)通过运行镜像(`image`)来启动: 26 | 27 | * 镜像是一个可执行包,包含运行应用程序所需的所有内容 - 代码、运行时、库、环境变量和配置文件 28 | * 容器是一个镜像的运行时实例 - 映像在执行时在内存中的内容(即,具有状态的映像或用户进程)。可以使用命令`docker ps`查看正在运行的容器列表 29 | 30 | ## 容器和虚拟机 31 | 32 | * 容器在`Linux`上本地运行,与其他容器共享主机内核。它运行一个离散进程,占用的内存不比任何其他可执行文件多,因此它是轻量级 33 | * 虚拟机(`virtual machine, VM`)运行一个完整的`客户端`操作系统,通过虚拟机监控程序对主机资源进行虚拟访问。一般来说,`VM`资源比大多数应用程序需要的资源多 34 | 35 | ![](./imgs/Container@2x.png) 36 | 37 | ![](./imgs/VM@2x.png) 38 | 39 | ## 容器和CI/CD 40 | 41 | `docker`容器化的实现使得`CI/CD`可以无缝接轨: 42 | 43 | * 应用程序没有系统依赖 44 | * 可以将更新推送到分布式应用程序的任何部分 45 | * 可以优化资源密度 46 | 47 | ## 常用命令 48 | 49 | ``` 50 | ## List Docker CLI commands 51 | docker 52 | docker container --help 53 | 54 | ## Display Docker version and info 55 | docker --version 56 | docker version 57 | docker info 58 | 59 | ## Execute Docker image 60 | docker run hello-world 61 | 62 | ## List Docker images 63 | docker image ls 64 | 65 | ## List Docker containers (running, all, all in quiet mode) 66 | docker container ls 67 | docker container ls --all 68 | docker container ls -aq 69 | ``` -------------------------------------------------------------------------------- /docs/docker/basic/hello-world.md: -------------------------------------------------------------------------------- 1 | 2 | # Hello World 3 | 4 | 参考: 5 | 6 | [Get Started, Part 2: Containers](https://docs.docker.com/get-started/part2/#recap-and-cheat-sheet-optional) 7 | 8 | [Best practices for writing Dockerfiles](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/) 9 | 10 | `Docker`镜像由只读层组成,每个层代表一条`Dockerfile`指令。这些层是堆叠的,每一层都是前一层变化的增量 11 | 12 | 下面制作最简单的`Hello World`镜像 13 | 14 | ## Dockerfile 15 | 16 | 新建文件夹`docker`,进入该文件后新建文件`Dockerfile`,输入以下指令 17 | 18 | ``` 19 | $ mkdir docker 20 | $ cd docker 21 | $ vim docker 22 | FROM ubuntu:18.04 23 | COPY . /app 24 | CMD sh /app/app.sh 25 | ``` 26 | 27 | 每一条指令都会创建一个层,解释如下: 28 | 29 | * `FROM`指令创建一个层,来自于`ubuntu:18.04`镜像 30 | * `COPY`指令创建一个层,将当前`docker`文件夹内容复制到镜像的`/app`文件夹内 31 | * `CMD`指令创建一个层,运行脚本 32 | 33 | 创建脚本`app.sh`,内容如下: 34 | 35 | ``` 36 | echo 'Hello World' 37 | ``` 38 | 39 | ## 创建镜像 40 | 41 | 输入以下指令构建镜像,指定镜像名和版本号 42 | 43 | ``` 44 | $ docker build --tag=zj:0.1.0 . 45 | Sending build context to Docker daemon 3.072kB 46 | Step 1/3 : FROM ubuntu:18.04 47 | 18.04: Pulling from library/ubuntu 48 | 35c102085707: Pull complete 49 | 251f5509d51d: Pull complete 50 | 8e829fe70a46: Pull complete 51 | 6001e1789921: Pull complete 52 | Digest: sha256:d1d454df0f579c6be4d8161d227462d69e163a8ff9d20a847533989cf0c94d90 53 | Status: Downloaded newer image for ubuntu:18.04 54 | ---> a2a15febcdf3 55 | Step 2/3 : COPY . /app 56 | ---> 8d579b652ea1 57 | Step 3/3 : CMD sh /app/app.sh 58 | ---> Running in 0e0f6faa5749 59 | Removing intermediate container 0e0f6faa5749 60 | ---> 7515c3706b27 61 | Successfully built 7515c3706b27 62 | Successfully tagged zj:0.1.0 63 | ``` 64 | 65 | 有上面输出日志可知,共创建了`3`个镜像,其`ID`如下: 66 | 67 | ``` 68 | a2a15febcdf3 69 | 8d579b652ea1 70 | 7515c3706b27 71 | ``` 72 | 73 | 可通过`docker image ls`查询 74 | 75 | ``` 76 | $ docker image ls -a 77 | REPOSITORY TAG IMAGE ID CREATED SIZE 78 | zj 0.1.0 7515c3706b27 12 seconds ago 64.2MB 79 | 8d579b652ea1 14 seconds ago 64.2MB 80 | ubuntu 18.04 a2a15febcdf3 4 weeks ago 64.2MB 81 | ``` 82 | 83 | ## 运行容器 84 | 85 | 使用指令`docker run`启动容器,将`Hello World`输入到当前命令行窗口 86 | 87 | ``` 88 | $ docker run zj:0.1.0 89 | Hello World 90 | ``` -------------------------------------------------------------------------------- /docs/docker/basic/imgs/Container@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Document-Collection/Containerization-Automation/1c26d368b07a390523ec1d8ab65f0b208bb16cf2/docs/docker/basic/imgs/Container@2x.png -------------------------------------------------------------------------------- /docs/docker/basic/imgs/VM@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Document-Collection/Containerization-Automation/1c26d368b07a390523ec1d8ab65f0b208bb16cf2/docs/docker/basic/imgs/VM@2x.png -------------------------------------------------------------------------------- /docs/docker/basic/imgs/commit-options.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Document-Collection/Containerization-Automation/1c26d368b07a390523ec1d8ab65f0b208bb16cf2/docs/docker/basic/imgs/commit-options.png -------------------------------------------------------------------------------- /docs/docker/basic/imgs/engine-components-flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Document-Collection/Containerization-Automation/1c26d368b07a390523ec1d8ab65f0b208bb16cf2/docs/docker/basic/imgs/engine-components-flow.png -------------------------------------------------------------------------------- /docs/docker/basic/imgs/laurel-docker-containers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Document-Collection/Containerization-Automation/1c26d368b07a390523ec1d8ab65f0b208bb16cf2/docs/docker/basic/imgs/laurel-docker-containers.png -------------------------------------------------------------------------------- /docs/docker/basic/可选设置.md: -------------------------------------------------------------------------------- 1 | 2 | # 可选设置 3 | 4 | 参考:[Post-installation steps for Linux](https://docs.docker.com/install/linux/linux-postinstall/) 5 | 6 | 安装后可以配置以下步骤以进一步简化`docker`使用 7 | 8 | ## 以非root用户身份管理Docker 9 | 10 | `Docker`守护进程绑定到`Unix`套接字而不是`TCP`端口。默认情况下`Unix`套接字归`root`所有,其他用户只能使用`sudo`访问它。`Docker`守护进程始终作为根用户运行 11 | 12 | 可以创建一个`unix`组,名为`docker`,然后添加`home`用户到里面。当`docker`守护进程启动后会创建`Unix socket`访问`docker`组的成员 13 | 14 | 1. 创建`docker`组 15 | 16 | ``` 17 | $ sudo groupadd docker 18 | ``` 19 | 20 | 2. 添加用户到`docker`组 21 | 22 | ``` 23 | $ sudo usermod -aG docker $USER 24 | ``` 25 | 26 | 3. 注销并重新登录,以便重新评估组成员资格 27 | * 如果在虚拟机上测试,则需要重启虚拟机 28 | * 在桌面`Linux`环境(如`X Windows`)中,完全注销会话,然后重新登录 29 | * 在`Linux`上,还可以运行以下命令来激活对组的更改: 30 | 31 | $ newgrp docker 32 | 33 | 4. 使用`docker`命令验证: 34 | 35 | # 此命令下载测试镜像并在容器中运行它。当容器运行时,它会打印一条消息并退出 36 | $ docker run hello-world 37 | 38 | 如果在将用户添加到`Docker`组之前,最初使用`sudo`运行`Docker cli`命令可能会看到以下错误,这表明由于`sudo`命令的原因,`~/.docker/`目录是用不正确的权限创建的 39 | 40 | ``` 41 | WARNING: Error loading config file: /home/user/.docker/config.json - stat /home/user/.docker/config.json: permission denied 42 | ``` 43 | 44 | 要解决此问题,请删除`~/.docker/`目录(该目录将自动重新创建,但任何自定义设置都将丢失),或者使用以下命令更改其所有权和权限: 45 | 46 | ``` 47 | $ sudo chown "$USER":"$USER" /home/"$USER"/.docker -R 48 | $ sudo chmod g+rwx "$HOME/.docker" -R 49 | ``` 50 | 51 | ## 开机自启动 52 | 53 | 使用`systemctl`命令实现`docker`守护进程开机自启动 54 | 55 | ``` 56 | # 允许开机自启动 57 | $ sudo systemctl enable docker 58 | # 停止开机自启动 59 | $ sudo systemctl disable docker 60 | ``` 61 | 62 | -------------------------------------------------------------------------------- /docs/docker/basic/安装.md: -------------------------------------------------------------------------------- 1 | # 安装 2 | 3 | 参考:[Get Docker CE for Ubuntu](https://docs.docker.com/install/linux/docker-ce/ubuntu) 4 | 5 | ## 先决条件 6 | 7 | 支持`64`位`Ubuntu`版本 8 | 9 | * `Cosmic 18.10` 10 | * `Bionic 18.04 (LTS)` 11 | * `Xenial 16.04 (LTS)` 12 | 13 | 支持架构 14 | 15 | * `x86_64` 16 | * `amd64` 17 | * `armhf` 18 | * `s390x(IBM Z)` 19 | * `ppc64le(IBM Power)` 20 | 21 | ## 安装 22 | 23 | `docker`提供了`3`种方式 24 | 25 | 1. 设置`docker`仓库再安装 26 | 2. 下载`deb`包安装(适合不联网状态) 27 | 3. 脚本安装 28 | 29 | 下面介绍第一种方式 30 | 31 | ### 安装仓库 32 | 33 | $ sudo apt-get update 34 | $ sudo apt-get install \ 35 | apt-transport-https \ 36 | ca-certificates \ 37 | curl \ 38 | gnupg-agent \ 39 | software-properties-common 40 | $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - 41 | 42 | 可以验证是否设置成功 43 | 44 | $ sudo apt-key fingerprint 0EBFCD88 45 | 46 | pub 4096R/0EBFCD88 2017-02-22 47 | Key fingerprint = 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 48 | uid Docker Release (CE deb) 49 | sub 4096R/F273FCD8 2017-02-22 50 | 51 | 安装 52 | 53 | $ sudo add-apt-repository \ 54 | "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ 55 | $(lsb_release -cs) \ 56 | stable" 57 | 58 | ### 安装docker ce 59 | 60 | $ sudo apt-get update 61 | $ sudo apt-get install docker-ce docker-ce-cli containerd.io 62 | 63 | $ sudo docker version 64 | 65 | Client: 66 | Version: 18.09.1 67 | API version: 1.39 68 | Go version: go1.10.6 69 | Git commit: 4c52b90 70 | Built: Wed Jan 9 19:35:23 2019 71 | OS/Arch: linux/amd64 72 | Experimental: false 73 | 74 | Server: Docker Engine - Community 75 | Engine: 76 | Version: 18.09.1 77 | API version: 1.39 (minimum version 1.12) 78 | Go version: go1.10.6 79 | Git commit: 4c52b90 80 | Built: Wed Jan 9 19:02:44 2019 81 | OS/Arch: linux/amd64 82 | Experimental: false 83 | 84 | ### 测试 85 | 86 | $ sudo docker run hello-world 87 | 88 | Hello from Docker! 89 | This message shows that your installation appears to be working correctly. 90 | 91 | To generate this message, Docker took the following steps: 92 | 1. The Docker client contacted the Docker daemon. 93 | 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. 94 | (amd64) 95 | 3. The Docker daemon created a new container from that image which runs the 96 | executable that produces the output you are currently reading. 97 | 4. The Docker daemon streamed that output to the Docker client, which sent it 98 | to your terminal. 99 | 100 | To try something more ambitious, you can run an Ubuntu container with: 101 | $ docker run -it ubuntu bash 102 | 103 | Share images, automate workflows, and more with a free Docker ID: 104 | https://hub.docker.com/ 105 | 106 | For more examples and ideas, visit: 107 | https://docs.docker.com/get-started/ 108 | 109 | 测试命令启动了一个名为`hello-world`的镜像,输出的消息介绍了`docker`实现流程 110 | 111 | 1. `docker`客户端联系`docker`守护进程 112 | 2. `docker`守护进程从`docker hub`中拉取`hello-world`镜像 113 | 3. `docker`守护进程使用该镜像创建一个容器,运行里面的可执行文件,生成当前输出的消息 114 | 4. `docker`守护进程将该输出流向`docker`客户端,即打印在终端 115 | 116 | ## 升级 117 | 118 | 重复上面的安装命令,默认搜索最新版本进行安装 119 | 120 | $ sudo apt-get update 121 | $ sudo apt-get install docker-ce docker-ce-cli containerd.io 122 | 123 | ## 卸载 124 | 125 | $ sudo apt-get purge docker-ce 126 | $ sudo rm -rf /var/lib/docker -------------------------------------------------------------------------------- /docs/docker/basic/镜像和容器.md: -------------------------------------------------------------------------------- 1 | 2 | # 镜像和容器 3 | 4 | 镜像(image)是一个可执行包,包含了运行应用需要的代码、运行环境、库、环境变量和配置文件 5 | 6 | 容器是镜像的运行实例,可以称为有状态的镜像或者是一个用户进程。一个镜像可以产生多个容器 7 | 8 | -------------------------------------------------------------------------------- /docs/docker/compose/Compose安装.md: -------------------------------------------------------------------------------- 1 | 2 | # Compose安装 3 | 4 | 参考:[Install Docker Compose](https://docs.docker.com/compose/install/) 5 | 6 | ## 必要条件 7 | 8 | 需要先安装`Docker`,参考[Docker安装](../basic/安装.md) 9 | 10 | ## 安装 11 | 12 | 下载`Compose`二进制文件到`/usr/local/bin` 13 | 14 | ``` 15 | $ sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose 16 | ``` 17 | 18 | **从官网上找到上面这一步,获取最新的版本** 19 | 20 | 授予可执行权限 21 | 22 | ``` 23 | $ sudo chmod +x /usr/local/bin/docker-compose 24 | ``` 25 | 26 | 测试是否安装成功 27 | 28 | ``` 29 | $ docker-compose version 30 | docker-compose version 1.24.1, build 4667896b 31 | docker-py version: 3.7.3 32 | CPython version: 3.6.8 33 | OpenSSL version: OpenSSL 1.1.0j 20 Nov 2018 34 | ``` 35 | 36 | ## 升级 37 | 38 | 如果正在从`Compose 1.2`或更早升级,删除或迁移升级后的现有容器。这是因为,在第`1.3`版中,`Compose`使用`Docker`标签来跟踪容器,并且需要重新创建容器来添加标签 39 | 40 | 如果`Compose`检测到没有标签创建的容器会拒绝运行。如果想继续使用现有的容器(例如,因为它们拥有要保存的数据卷),可以使用`Compose 1.5.x`以以下命令迁移它们: 41 | 42 | ``` 43 | docker-compose migrate-to-labels 44 | ``` 45 | 46 | 或者,如果你不担心保存它们,你可以移除它们。`Compose`只是创造新的 47 | 48 | ``` 49 | docker container rm -f -v myapp_web_1 myapp_db_1 ... 50 | ``` 51 | 52 | ## 卸载 53 | 54 | 如果使用`curl`安装,卸载方式如下: 55 | 56 | ``` 57 | sudo rm /usr/local/bin/docker-compose 58 | ``` 59 | 60 | 如果使用`pip`安装,卸载方式如下: 61 | 62 | ``` 63 | pip uninstall docker-compose 64 | ``` 65 | 66 | ### Got a “Permission denied” error? 67 | 68 | 如果使用上述任一方法时出现`Permission denied`错误,则可能没有删除`docker-compose`的适当权限。若要强制删除,将`sudo`置于上述任一命令的前面,然后再次运行 -------------------------------------------------------------------------------- /docs/docker/compose/Compose文件格式 - Service设置.md: -------------------------------------------------------------------------------- 1 | # Compose文件格式 - Service设置 2 | 3 | 参考:[Compose file version 3 reference](https://docs.docker.com/compose/compose-file/) 4 | 5 | `Service`可以指定一个或多个容器的配置 6 | 7 | ## 指定镜像 8 | 9 | 使用键`image`指定启动容器的镜像 10 | 11 | ``` 12 | image: compose:latest 13 | image: compose:0.2.0 14 | ``` 15 | 16 | 如果镜像不存在本地,那么`compose`会从远程进行拉取,除非额外设置了`build`键进行构建 17 | 18 | **注意:即使设置了多个,仅会使用最后一个`image`键值对** 19 | 20 | ## 构建镜像 21 | 22 | 使用键`build`指定要构建的镜像: 23 | 24 | 1. `context`:包含`Dockerfile`的目录 25 | 2. `dockerfile`:指定要使用的`Dockerfile`文件路径 26 | 3. `args`:指定构建阶段的参数 27 | 4. `labels`:添加镜像元数据,其作用类似于`LABEL`标签 28 | 29 | 示例如下: 30 | 31 | ``` 32 | build: 33 | context: ./dir/ 34 | dockerfile: /path/to/Dockerfile-alternate 35 | args: 36 | buildno: 1 37 | gitcommithash: cdc3b19 38 | labels: 39 | - "com.example.description=Accounting webapp" 40 | - "com.example.department=Finance" 41 | - "com.example.label-with-empty-value" 42 | ``` 43 | 44 | **注意一:当不需要额外设置,仅指定`context`选项时,可以使用以下方式** 45 | 46 | ``` 47 | build: ./dir/ 48 | ``` 49 | 50 | **注意二:设置构建参数时,需要现在`Dockerfile`文件中指定参数名** 51 | 52 | ``` 53 | # Dockerfile 54 | ARG buildno 55 | ARG gitcommithash 56 | 57 | RUN echo "Build number: $buildno" 58 | RUN echo "Based on commit: $gitcommithash" 59 | 60 | # docker-compose 61 | args: 62 | - buildno=1 63 | - gitcommithash=cdc3b19 64 | # 或者 65 | args: 66 | buildno: 1 67 | gitcommithash: cdc3b19 68 | ``` 69 | 70 | ## 容器名设置 71 | 72 | ``` 73 | container_name: my-web-container 74 | ``` 75 | 76 | ## 容器启动设置 77 | 78 | 涉及两个键:`command`和`entrypoint` 79 | 80 | ### 启动命令command 81 | 82 | 重写默认的`COMMAND`命令 83 | 84 | ``` 85 | command: bundle exec thin -p 3000 86 | # 或者 87 | command: ["bundle", "exec", "thin", "-p", "3000"] 88 | ``` 89 | 90 | ### 入口点程序entrypoint 91 | 92 | 重写`ENTRYPOINT`命令指定的文件 93 | 94 | ``` 95 | entrypoint: /code/entrypoint.sh 96 | ``` 97 | 98 | ## 环境变量设置 99 | 100 | 涉及两个键: `env_file`和`environment` 101 | 102 | ### 直接添加环境变量 103 | 104 | 使用`environment`可以直接设置环境变量 105 | 106 | ``` 107 | environment: 108 | RACK_ENV: development 109 | SHOW: 'true' 110 | SESSION_SECRET: 111 | # 或者 112 | environment: 113 | - RACK_ENV=development 114 | - SHOW=true 115 | - SESSION_SECRET 116 | ``` 117 | 118 | ### 使用配置文件 119 | 120 | 使用`env_file`键指定环境变量配置文件(可以指定多个配置文件) 121 | 122 | ``` 123 | services: 124 | some-service: 125 | env_file: 126 | - a.env 127 | - b.env 128 | ``` 129 | 130 | 配置文件的格式为 131 | 132 | ``` 133 | # a.env 134 | VAR=1 135 | # b.env 136 | VAR=hello 137 | ``` 138 | 139 | **注意:重复设置的环境变量会被覆盖** 140 | 141 | ## 硬件设备映射 142 | 143 | 使用键`devices`指定容器和主机之间映射的设备 144 | 145 | ``` 146 | devices: 147 | - "/dev/ttyUSB0:/dev/ttyUSB0" 148 | ``` 149 | 150 | 或者设置`privileged: true`允许容器操作所有主机硬件 151 | 152 | ## 端口设置 153 | 154 | ### 指定内部端口 155 | 156 | 使用键`expose`指定服务内部容器之间开放的端口 157 | 158 | ``` 159 | expose: 160 | - "3000" 161 | - "8000" 162 | ``` 163 | 164 | ### 指定外部端口 165 | 166 | 使用键`ports`指定主机映射的端口 167 | 168 | * 短格式语法:指定主机和容器端口(`HOST:CONTAINER`)或者仅指定容器端口(主机端口临时设置) 169 | 170 | ``` 171 | ports: 172 | - "3000" 173 | - "3000-3005" 174 | - "8000:8000" 175 | - "9090-9091:8080-8081" 176 | - "49100:22" 177 | - "127.0.0.1:8001:8001" 178 | - "127.0.0.1:5000-5010:5000-5010" 179 | - "6060:6060/udp" 180 | ``` 181 | 182 | * 长格式语法:... 183 | 184 | ## 添加元数据 185 | 186 | 除了使用`build`进行镜像构建时设置元数据,还可以通过`labels`键设置容器的元数据 187 | 188 | ``` 189 | labels: 190 | com.example.description: "Accounting webapp" 191 | com.example.department: "Finance" 192 | com.example.label-with-empty-value: "" 193 | # 或者 194 | labels: 195 | - "com.example.description=Accounting webapp" 196 | - "com.example.department=Finance" 197 | - "com.example.label-with-empty-value" 198 | ``` 199 | 200 | ## 重启设置 201 | 202 | 使用键`restart`指定重启设置 203 | 204 | ``` 205 | restart: "no"       # 默认设置,任何情况下不重启容器 206 | restart: always # 无论哪种情况都要重启 207 | restart: on-failure # 仅在容器启动失败时重启 208 | restart: unless-stopped 209 | ``` 210 | 211 | ## 主机名设置 212 | 213 | ``` 214 | hostname: foo 215 | ``` 216 | 217 | ## 当前用户设置 218 | 219 | ``` 220 | user: root 221 | ``` 222 | 223 | ## 交互式Shell设置 224 | 225 | 参考: 226 | 227 | [使用Docker Compose的交互式shell](https://www.itranslater.com/qa/details/2131115956192674816) 228 | 229 | [使用Docker Compose的交互式shell?](https://cloud.tencent.com/developer/ask/111359) 230 | 231 | ``` 232 | tty: true 233 | stdin_open: true 234 | ``` -------------------------------------------------------------------------------- /docs/docker/compose/Compose文件格式 - 存储设置.md: -------------------------------------------------------------------------------- 1 | 2 | # Compose文件格式 - 存储设置 3 | 4 | 存储设置分两部分,一是在单个容器上设置,二是设置多容器共用的卷 5 | 6 | ## 单容器存储设置 7 | 8 | 参考:[volumes](https://docs.docker.com/compose/compose-file/#volumes) 9 | 10 | 可以为每个容器单独指定和主机的存储设置(*绑定挂载设置或卷设置*),示例如下 11 | 12 | ``` 13 | version: "3.7" 14 | services: 15 | web: 16 | image: nginx:alpine 17 | volumes: 18 | - type: volume 19 | source: mydata 20 | target: /data 21 | volume: 22 | nocopy: true 23 | - type: bind 24 | source: ./static 25 | target: /opt/app/static 26 | 27 | db: 28 | image: postgres:latest 29 | volumes: 30 | - "/var/run/postgres/postgres.sock:/var/run/postgres/postgres.sock" 31 | - "dbdata:/var/lib/postgresql/data" 32 | 33 | volumes: 34 | mydata: 35 | dbdata: 36 | ``` 37 | 38 | **注意:命名卷必须列在顶级键`volumes`下** 39 | 40 | 有两种语法: 41 | 42 | 1. 短格式语法 43 | 2. 长格式语法 44 | 45 | #### 短格式语法 46 | 47 | 同时指定主机和容器的路径(`HOST:CONTAINER`),还可以添加访问模式(`HOST:CONTAINER:ro`) 48 | 49 | ``` 50 | volumes: 51 | # Just specify a path and let the Engine create a volume 52 | - /var/lib/mysql # 仅指定单个路径,会生成一个mysql卷 53 | 54 | # Specify an absolute path mapping 55 | - /opt/data:/var/lib/mysql # 使用绝对路径进行绑定挂载 56 | 57 | # Path on the host, relative to the Compose file 58 | - ./cache:/tmp/cache # 使用相对路径进行绑定挂载 59 | 60 | # User-relative path 61 | - ~/configs:/etc/configs/:ro # 指定访问模式为只读 62 | 63 | # Named volume 64 | - datavolume:/var/lib/mysql # 卷设置 65 | ``` 66 | 67 | #### 长格式语法 68 | 69 | ... 70 | 71 | ## 多容器存储设置 72 | 73 | 参考:[Volume configuration reference](https://docs.docker.com/compose/compose-file/#volume-configuration-reference) 74 | 75 | 在顶级键`volumes`可以命名多个卷,在多个容器之间使用 76 | 77 | ``` 78 | version: "3.7" 79 | 80 | services: 81 | db: 82 | image: db 83 | volumes: 84 | - data-volume:/var/lib/db 85 | backup: 86 | image: backup-service 87 | volumes: 88 | - data-volume:/var/lib/backup/data 89 | 90 | volumes: 91 | data-volume: 92 | ``` 93 | 94 | ### external 95 | 96 | 参考:[docker使用小记6 - docker-compose挂载数据卷出现的问题](https://www.cnblogs.com/qvennnnn/p/11732324.html) 97 | 98 | 顶级键`volumes`包含多个属性,`external`属性默认设置为`false`,启动容器时会创建一个命名为`[projectname]_[volumename]`的卷;如果已存在待使用的卷,可以设置`external`属性为`true`,那么启动容器时会直接使用命名为`volumename`的卷。示例如下: 99 | 100 | ``` 101 | version: "3.7" 102 | 103 | services: 104 | db: 105 | image: postgres 106 | volumes: 107 | - data:/var/lib/postgresql/data 108 | 109 | volumes: 110 | data: 111 | external: true 112 | ``` -------------------------------------------------------------------------------- /docs/docker/compose/Compose文件格式概述.md: -------------------------------------------------------------------------------- 1 | 2 | # Compose文件格式概述 3 | 4 | 参考:[Compose file version 3 reference](https://docs.docker.com/compose/compose-file/) 5 | 6 | 之前配置完`Dockerfile`文件后,通过命令进行构建(`build`)和运行(`run`)。除此之外,`docker`提供了工具`docker-compose`来辅助容器编排,通过`docker-compose.yml`文件进行配置 7 | 8 | *`docker-compose`文件格式涉及诸多参数和设置,当前仅学习使用到的功能,之后再逐步更新* 9 | 10 | ## 文件概述 11 | 12 | 示例`docker-compose.yml`文件如下: 13 | 14 | ``` 15 | version: "3.7" 16 | services: 17 | 18 | redis: 19 | image: redis:alpine 20 | ports: 21 | - "6379" 22 | networks: 23 | - frontend 24 | deploy: 25 | replicas: 2 26 | update_config: 27 | parallelism: 2 28 | delay: 10s 29 | restart_policy: 30 | condition: on-failure 31 | 32 | db: 33 | image: postgres:9.4 34 | volumes: 35 | - db-data:/var/lib/postgresql/data 36 | networks: 37 | - backend 38 | deploy: 39 | placement: 40 | constraints: [node.role == manager] 41 | 42 | networks: 43 | frontend: 44 | backend: 45 | 46 | volumes: 47 | db-data: 48 | ``` 49 | 50 | `compose`文件包含了`4`个顶级键: 51 | 52 | 1. `version`:指定文件规范版本 53 | 2. [services](https://docs.docker.com/compose/compose-file/#service-configuration-reference):指定要操作的容器 54 | 3. [networks](https://docs.docker.com/compose/compose-file/#network-configuration-reference):指定共用的网络配置 55 | 4. [volumes](https://docs.docker.com/compose/compose-file/#volume-configuration-reference):指定共用的存储配置 56 | 57 | 在顶级键下面指定了要配置的章节,在章节下面按`: