[Linux] Docker 镜像及容器自动化思路

Docker 镜像及容器自动化思路

通过Dockerfile 自动化生成镜像, 有镜像环境后就运行容器, sh进行自动化部署了...

1. 编写 Dockerfile 文件

  From python:3.7                                                                  
                                                                                   
  RUN mkdir /work                                                                  
  WORKDIR  /work                                                                   
  # 为了保证复制目录, 多写一级目录结构                                             
  COPY ./dakj_site_plan/ /work/dakj_site_plan/                                     
  COPY ./dakj_site_plan/requirements.txt /work/dakj_site_plan/                     
  COPY ./dakj_core_mvc/mvc/ /work/dakj_site_plan/web/mvc/                          
                                                                                   
  RUN pip install -r /work/dakj_site_plan/requirements.txt                         
                                                                                   
  CMD ["python", "/work/dakj_site_plan/web/run.py"]                                
                                                                                   

2. 有Dockerfile后, 就可以生成镜像

 docker build -f Dockerfile_Site_Plan -t site_plan:v01 .

3. 运行容器

运行时,可指定 -v 挂载; -p 端口映射

 docker run -itd --name=test_site_plan03  -p 18888:18888 site_plan:v01

4. 导出镜像

 docker save -o site_plan.tar site_plan:v01  

有镜像文件后, 就可以自由cp, 导入生成,运行容器了.

posted @ 2021-03-18 17:01  ABeen  阅读(65)  评论(0编辑  收藏  举报