# docker-training **Repository Path**: violetff/docker-training ## Basic Information - **Project Name**: docker-training - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2020-03-19 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # docker-training #### Description {**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**} #### Software Architecture Software architecture description #### Installation 1. xxxx 2. xxxx 3. xxxx #### Instructions 1. xxxx 2. xxxx 3. xxxx #### Contribution 1. Fork the repository 2. Create Feat_xxx branch 3. Commit your code 4. Create Pull Request #### Gitee Feature 1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md 2. Gitee blog [blog.gitee.com](https://blog.gitee.com) 3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) 4. The most valuable open source project [GVP](https://gitee.com/gvp) 5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) 6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) ## 1. 创建目录 mkdir docker-training ### 1.1在docker-training目录下新建一个项目目录,命名为docker-django-base django-admin startproject docker-django-base ## 2. 新建必要的文件 ### 2.1 在该目录下创建requirements.txt文件,requirements.txt本质上是项目的依赖包 ### 2.2 在该目录下创建Dockerfile ### Dockerfile本质上是一个文本文件,其中明确定义了如何为我们的项目构建Docker镜像 FROM python:3.7-buster ADD requirements.txt / RUN pip install --no-cache-dir -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com RUN mkdir -p /usr/src/app ADD . /usr/src/app WORKDIR /usr/src/app EXPOSE 8000 CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"] #### FROM - 所有Dockerfile的第一个指令都必须是 FROM ,用于指定一个构建镜像的基础源镜像,如果本地没有就会从公共库中拉取,没有指定镜像的标签会使用默认的latest标签 #### RUN - RUN命令是一个常用的命令,执行完成之后会成为一个新的镜像,通常用于运行安装任务从而向映像中添加额外的内容。 #### 在第一个 RUN 命令中使用 pip 来安装 requirements.txt 文件中的所有包。 #### 在第二个 RUN 命令创建指定的工作目录 #### ADD - 一个复制命令,把文件复制到镜像中 #### WORKDIR - 为RUN、CMD、ENTRYPOINT指令配置工作目录。 #### EXPOSE - 暴漏容器运行时的监听端口给外部 #### CMD - 为容器启动时要运行的命令 ### 2.3 定义 Dockerfile 文件后,然后使用 docker build、docker run 等命令操作容器 #### Dockerfile创建好后,可以利用命令行构建镜像 #### docker build -t dockerdjangobase_web . #### 也可以将该命令行放到可执行文件中 build.sh 直接运行 ./build.sh ## 3. docker-compose构建镜像 ### 3.1 在Dockerfile 文件下创建文件 docker-compose.yml,添加以下内容 ##### 表示该 Docker-Compose 文件使用的是 Version 3 file version: "3" ##### 多个容器集合 services: web: ##### 指定 Dockerfile 所在路径 build: . ##### 指定端口映射 ports: - 8001:8000 ### 3.2 在 docker-compose.yml 所在路径下执行该命令 Compose 就会自动构建镜像并使用镜像启动容器 ### 3.3 build:构建或者重新构建服务 docker-compose build ### 3.4 up:构建、启动容器. 当服务的配置发生更改时,可使用 docker-compose up 命令更新配置 docker-compose up