zoukankan      html  css  js  c++  java
  • 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 .
    
  • 相关阅读:
    语言特性-上下文对象
    语言特性-闭包
    语言特性-变量作用域
    语言特性-函数重载与类型检查
    面向对象的JS代码
    单例模式
    wait操作接口
    进程的创建模型
    模拟密码登陆过程
    目录操作的一些函数理解
  • 原文地址:https://www.cnblogs.com/kumata/p/14120475.html
Copyright © 2011-2022 走看看