Linux系统环境基于Docker搭建系统基础镜像
时间: 2020-01-08来源:OSCHINA
前景提要
【围观】麒麟芯片遭打压成绝版,华为亿元投入又砸向了哪里?>>>
制作系统基础环境镜像 [x] 基于Ubuntu制作镜像资源
>⚠️[注意事项]:由于拉取的Docker hub 的大多数镜像都没有安装Vim ss 等等资源,而且大部分镜像资源是官方镜像库更新资源后安装极其不方便,因此自己构建一个通用镜像尤为重要。
基于Ubuntu制作镜像资源
1.在宿主机创建文件目录:/docker/ubuntu/environment mkdir -p /docker/ubuntu/environment
2.安装的资源如下: java shh 等 vim psmisc rsync supervisor netcat
3.替换阿里云的镜像资源 bionic版本: deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
xenial版本: deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
>⚠️[注意事项]:具体的依据自己的选择的系统版本进行替换
4.编写Dockerfile 文件: ######################################## #Setting source to base images ######################################## ARG IMAGE_VERSION=bionic-20191202 FROM ubuntu:${IMAGE_VERSION} ######################################## #Setting images author ######################################## MAINTAINER marklin<marklin1992@outlook.com> ######################################## #Setting and update datasource ######################################## WORKDIR /etc/apt RUN mv sources.list sources-backup.list RUN echo 'deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse' >>sources.list RUN echo 'deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse' >>sources.list RUN echo 'deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse' >>sources.list RUN echo 'deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse' >>sources.list RUN apt-get update ######################################## #Setting install software tools ######################################## RUN apt-get install vim openssh-server openssh-client openjdk-8-jdk ssh git dirmngr netcat psmisc rsync supervisor --assume-yes RUN apt-get clean && \ rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ######################################## #Setting sytem path ######################################## RUN rm -rf /root/.bashrc ADD .bashrc /root RUN chmod -R 777 /root/.bashrc ######################################## #Setting JAVA_HOME path ######################################## ENV JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 ENV PATH=${PATH}:${JAVA_HOME}/bin ######################################## #Setting ssh start ######################################## RUN mkdir /var/run/sshd RUN echo 'root:root' |chpasswd RUN sed -ri 's/^#?PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config RUN mkdir /root/.ssh ######################################## #Setting hadoop start ######################################## WORKDIR / EXPOSE 22 CMD ["/usr/sbin/sshd", "-D"]
另外有一个全局的系统环境变量配置文件.bashrc: # ~/.bashrc: executed by bash(1) for non-login shells. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for examples # If not running interactively, don't do anything [ -z "$PS1" ] && return # don't put duplicate lines in the history. See bash(1) for more options # ... or force ignoredups and ignorespace HISTCONTROL=ignoredups:ignorespace # append to the history file, don't overwrite it shopt -s histappend # for setting history length see HISTSIZE and HISTFILESIZE in bash(1) HISTSIZE=1000 HISTFILESIZE=2000 # check the window size after each command and, if necessary, # update the values of LINES and COLUMNS. shopt -s checkwinsize # make less more friendly for non-text input files, see lesspipe(1) [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" # set variable identifying the chroot you work in (used in the prompt below) if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then debian_chroot=$(cat /etc/debian_chroot) fi # set a fancy prompt (non-color, unless we know we "want" color) case "$TERM" in xterm-color) color_prompt=yes;; esac # uncomment for a colored prompt, if the terminal has the capability; turned # off by default to not distract the user: the focus in a terminal window # should be on the output of commands, not on the prompt #force_color_prompt=yes if [ -n "$force_color_prompt" ]; then if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then # We have color support; assume it's compliant with Ecma-48 # (ISO/IEC-6429). (Lack of such support is extremely rare, and such # a case would tend to support setf rather than setaf.) color_prompt=yes else color_prompt= fi fi if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]