zoukankan      html  css  js  c++  java
  • Docker自制CentOS镜像

    系统环境:CentOS 7.3

    将yum源切换到阿里源

    可以直接写成一个脚本

    #!/bin/sh
    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
    mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
    wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
    View Code

     1. 安装Docker

    [root@localhost ~]# yum -y install docker-engine
    [root@localhost ~]# systemctl start docker
    [root@localhost ~]# systemctl enable docker

     2. 安装制作CentOS镜像的工具

    [root@localhost ~]# yum -y install febootstrap

     ps: CentOS7中的yum源没有febootstrap包,可以在CentOS6中使用 "yumdownloader febootstrap"命令将febootstrap下载到本地,之后放在7上进行安装

    3. 制作CentOS镜像文件centos6-image目录

    [root@localhost ~]# febootstrap -i bash -i wget -i yum -i iputils -i iproute -i man -i vim-minimal -i openssh-server -i openssh-clients centos6 centos6-image http://mirrors.aliyun.com/centos/6/os/x86_64/

     PS:-i 安装package, centos6 操作系统版本,centos6-doc安装目录,最后是源地址

    4. 制作Docker镜像,镜像名字是centos6-base

    [root@localhost ~]# cd centos6-image && tar -c .|docker import - centos6-base

     制作可以ssh登陆的Docker镜像,名字是centos6-ssh

    1.创建一个Dockerfile文件

    #Dockerfile
    FROM centos6-base
    RUN ssh-keygen -q -N "" -t dsa -f /etc/ssh/ssh_host_dsa_key
    RUN ssh-keygen -q -N "" -t rsa -f /etc/ssh/ssh_host_rsa_key
    RUN sed -ri 's/session    required     pam_loginuid.so/#session    required     pam_loginuid.so/g' /etc/pam.d/sshd
    RUN mkdir -p /root/.ssh && chown root.root /root && chmod 700 /root/.ssh
    EXPOSE 22
    RUN echo 'root:123.com' | chpasswd
    ENV LANG en_US.UTF-8
    ENV LC_ALL en_US.UTF-8
    CMD /usr/sbin/sshd -D
    #End
    Dockerfile
    [root@localhost ~]# docker build -t centos6-ssh .

    2.  创建容器

    [root@localhost ~]# docker run -itd -p 33301:22 centos6-ssh

    3. ssh登陆容器

    [root@localhost ~]# ssh root@127.0.0.1 -p 33301
  • 相关阅读:
    NPOI 的使用心得
    uploadfiy 动态传递Form 参数
    积分系统总结
    easyui dataBox 增加一天,减少一天
    easyui datagrid footer 页脚问题
    sql server 视图 的一个例子
    sql server int 列 NULLIF,isnull 判断是0还是1 ,如果是0就变成1
    easyui 小知识
    获取 日期 最后一天
    my97 日期控件
  • 原文地址:https://www.cnblogs.com/zhichaoma/p/7788128.html
Copyright © 2011-2022 走看看