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
  • 相关阅读:
    MVC3、如何应用EntityFramework 连接MySql 数据库 Kevin
    DEV EXPRESS Summary Footer 不显示 Kevin
    装饰模式 Kevin
    Dev 控件 GridControl 控件 二次绑定数据源的问题。 Kevin
    System.InvalidOperationException 异常 Kevin
    LINQ to XML Kevin
    代理模式——代码版“吊丝的故事” Kevin
    VS2012 中的设备 面板 Kevin
    maven 学习笔记(三)创建一个较复杂的 eclipse+android+maven 工程
    maven 学习笔记(一)eclipse+android+maven
  • 原文地址:https://www.cnblogs.com/zhichaoma/p/7788128.html
Copyright © 2011-2022 走看看