• Docker: 创建保存镜像


    镜像的创建和保存

    • 基于现有父镜像开发并commit
    • 使用Dockerfile文件创建

    一.基于现有父镜像开发并commit

    1. pull and start a new container
    docker pull ubuntu:18.04
    docker run -it ubuntu:18.04 bash
    
    1. deploy app and edit /run.sh

    2. exit and commit this container

    // docker commit ID SW_NAME:VERSION
    // example:
    root@13336c183077:/# exit
    exit
    bear@k40 ~% docker commit 13336c183077 ubuntu.18.04:v1
    
    1. run the new container by run.sh
    docker run ubuntu.18.04:v1 /run.sh
    

    二.使用Dockerfile文件创建

    1. touch a new Dockerfile and edit:
    FROM nginx
    RUN echo 'I'm nginx' > /usr/share/nginx/html/index.html
    
    • FROM: IMAGE, base 父镜像
    • RUN:["可执行文件", "参数1", "参数2"], like RUN ["./test.php", "dev", "offline"] == RUN ./test.php dev offline
      注意:
    FROM centos
    RUN yum install wget
    RUN wget -O redis.tar.gz "http://download.redis.io/releases/redis-5.0.3.tar.gz"
    RUN tar -xvf redis.tar.gz
    以上执行会创建 3 层镜像。可简化为以下格式:
    FROM centos
    RUN yum install wget 
        && wget -O redis.tar.gz "http://download.redis.io/releases/redis-5.0.3.tar.gz" 
        && tar -xvf redis.tar.gz
    
    1. build new image

    当前目录.上下文路径创建镜像:

    docker build -t myimage:v1 .
    
  • 相关阅读:
    CSS强制换行
    Android 软件开发的盈利模式
    比较Collection 和Collections的区别
    Jsp 中taglib标签的妙用
    常用搜索引擎大全
    Jsp 中登陆界面的实现方法
    Jsp 中JavaScript 和 Java代码的异步执行特点
    Jsp struts 标准配置测试版
    div demo
    多线程模拟银行业务调度系统
  • 原文地址:https://www.cnblogs.com/kumata/p/14120475.html
Copyright © 2020-2023  润新知