• (三)将容器变成镜像


    提交保存镜像命令

    docker commit <container> [repo:tag]

    当我们在制作自己的镜像的时候,会在container中安装一些工具、修改配置,如果不做commit保存 起来,那么container停止以后再启动,这些更改就消失了

    一.通过命令来创建镜像

    这种做法的优点: 最方便 最快速

                      缺点: 不规范 无法自动化

    手动构建一个 myjava3的镜像 过程如下:

    [root@docker ~]# docker create --name myjava3 -it java /bin/bash
    0814ffc5a92b66d017a620648205b1031b810ec1cb9da2ca411571dd75f4daac
    [root@docker ~]# docker start myjava3
    myjava3
    [root@docker ~]# docker ps
    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
    0814ffc5a92b        java                "/bin/bash"         20 seconds ago      Up 6 seconds                            myjava3

    [root@docker ~]# docker exec -it 0814ffc5a92b /bin/bash
    root@0814ffc5a92b:/# 

    root@0814ffc5a92b:/# ls
    bin dev home lib64 mnt proc run srv tmp var
    boot etc lib media opt root sbin sys usr


    root@0814ffc5a92b:/# mkdir createimage

    #退出容器 提交保存镜像

    root@0814ffc5a92b:/# exit
    exit

    [root@docker ~]# docker commit 0814ffc5a92b myjava3:v1.0
    sha256:c7644e42d29b5938518e624ce8c1033ff8973d1b73501de7cc288c0f4dabbb76
    [root@docker ~]# docker images
    REPOSITORY TAG IMAGE ID CREATED SIZE
    myjava3 v1.0 c7644e42d29b 16 seconds ago 643MB

    [root@docker ~]# docker run -it myjava3:v1.0 ls
    bin createimage etc lib media opt root sbin sys usr
    boot dev home lib64 mnt proc run srv tmp var

    二.Buildfile自动化创建镜像

    1.一个ubuntu下的Java镜像的buildfile

    FROM nimmis/ubuntu:14.04
    MAINTAINER nimmis <kjell.havneskold@gmail.com>
    # disable interactive functions
    ENV DEBIAN_FRONTEND noninteractive
    # set default java environment variable
    ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
    RUN apt-get install -y software-properties-common && 
    add-apt-repository ppa:openjdk-r/ppa -y && 
    apt-get update && 
    apt-get install -y --no-install-recommends openjdk-8-jre && 
    rm -rf /var/lib/apt/lists/*

     执行Dockerfile

    [root@docker ~]# docker build -t benjamin/java .

    2.Dockfile  复杂案例实战:制作ubuntu+java+tomcat+ssh server镜像

    mkdir test
    cd test
    vi Dockfile
    FROM ubuntu
    MAINTAINER yongboy "yongboy@gmail.com"
    # 更新源,安装ssh server
    RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe"> /etc/apt/sources.list
    RUN apt-get update
    RUN apt-get install -y openssh-server
    RUN mkdir -p /var/run/sshd
    # 设置root ssh远程登录密码为123456
    RUN echo "root:123456" | chpasswd
    # 添加orache java7源,一次性安装vim,wget,curl,java7,tomcat7等必备软件
    RUN apt-get install python-software-properties
    RUN add-apt-repository ppa:webupd8team/java
    RUN apt-get update
    RUN apt-get install -y vim wget curl oracle-java7-installer tomcat7
    # 设置JAVA_HOME环境变量
    RUN update-alternatives --display java
    RUN echo "JAVA_HOME=/usr/lib/jvm/java-7-oracle">> /etc/environment
    RUN echo "JAVA_HOME=/usr/lib/jvm/java-7-oracle">> /etc/default/tomcat7
    # 容器需要开放SSH 22端口
    EXPOSE 22
    # 容器需要开放Tomcat 8080端口
    EXPOSE 8080
    # 设置Tomcat7初始化运行,SSH终端服务器作为后台运行
    ENTRYPOINT service tomcat7 start && /usr/sbin/sshd -D
  • 相关阅读:
    kafka集群搭建
    更改:把redis替换成kafka
    mysql+canal+kafka+elasticsearch构建数据查询平台
    zookeeper集群搭建
    另类--kafka集群中jmx端口设置
    kafka集群中jmx端口设置
    使用zookeeper报错 stat is not executed because it is not in the whitelist. envi is not executed because it is not in the whitelist.
    使用python的kazoo模块连接zookeeper实现最基本的增删改查
    Maven之阿里云镜像仓库配置
    通过yum安装maven
  • 原文地址:https://www.cnblogs.com/benjamin77/p/9083639.html
Copyright © 2020-2023  润新知