# Docker for CentOS 7
#Base image
FROM centos:7
#Who
MAINTAINER ShiManQiang "shimanqiang@huizhaofang.com"
ADD motd /etc/motd
#更换repo镜像源-替换为网易的镜像源
ADD CentOS7-Base-163.repo /etc/yum.repos.d/CentOS7-Base-163.repo
#RUN cd /etc/yum.repos.d && mv CentOS-Base.repo CentOS-Base.repo.bk && wget http://mirrors.163.com/.help/CentOS7-Base-163.repo && yum update && yum clean all && yum makecache
#生成缓存
RUN yum update -y && yum makecache
#########################################中文乱码处理################################################
RUN rm -rf /etc/localtime && ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #修改时区
RUN yum -y install kde-l10n-Chinese && yum -y reinstall glibc-common #安装中文支持
RUN localedef -c -f UTF-8 -i zh_CN zh_CN.utf8 #配置显示中文
ENV LC_ALL zh_CN.utf8 #设置环境变量
RUN echo "export LC_ALL=zh_CN.utf8" >> /etc/profile
##########################################基本软件####################################################
RUN \
yum install -y vim openssh-clients openssl-devel openssh-server wget curl lrzsz supervisor git tree net-tools less telnet lsof sudo psmisc zip unzip python subversion && \
yum clean all
#RUN yum install -y mysql-devel redis && yum clean all
##########################################oracle jdk###################################################
RUN \
mkdir /mysoft && cd /mysoft && \
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u121-b13/e9e7ea248e2c4826b92b3f075a80e441/jdk-8u121-linux-x64.tar.gz && \
#tar -zxvf jdk-8u121-linux-x64.tar.gz && \
tar -zxvf $(ls) && \
mv $(ls -d */) oracle-jdk && \
mkdir -p /usr/local/java && \
mv oracle-jdk /usr/local/java/oracle-jdk && \
rm -rf /mysoft
ENV JAVA_HOME /usr/local/java/oracle-jdk/
ENV PATH $PATH:$JAVA_HOME/bin
##########################################nginx#########################################################
RUN yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel tar && yum clean all
#切换目录
RUN \
mkdir /mysoft && \
cd /mysoft && \
wget http://nginx.org/download/nginx-1.11.10.tar.gz && \
tar -zxvf nginx-1.11.10.tar.gz && \
cd nginx-1.11.10 && \
./configure && \
make && \
make install && \
rm -rf /mysoft
ENV PATH $PATH:/usr/local/nginx/sbin/
############################################gradle###########################################
#Gradle工具
ADD gradle-3.4-all.zip /gradle-3.4-all.zip
#提前打包好的app需要的libs,Gradle组织方式
COPY gradle.lib.tar.gz /gradle.lib.tar.gz
RUN \
yum install -y zip unzip python subversion && yum clean all && \
#wget https://services.gradle.org/distributions/gradle-3.4-all.zip && \
mkdir -p /usr/local/gradle && \
unzip gradle-3.4-all.zip -d /usr/local/gradle && \
mkdir -p /data/www/payment/ && \
mkdir -p /data/www/comm_project
RUN tar -zxvf gradle.lib.tar.gz -C /usr/local/gradle/
#Gradle环境
ENV GRADLE_HOME /usr/local/gradle/gradle-3.4/
#修改Gradle下载lib目录
ENV GRADLE_USER_HOME /usr/local/gradle/.gradle
#PATH
ENV PATH $PATH:$GRADLE_HOME/bin
########################################设置环境变量######################################
#此处设置是因为当ssh登录docker容器,ENV设置的变量不生效问题
RUN \
echo "JAVA_HOME=/usr/local/java/oracle-jdk/" >> /etc/profile && \
echo "CLASSPATH=$JAVA_HOME/lib/" >> /etc/profile && \
echo "GRADLE_HOME=/usr/local/gradle/gradle-3.4/" >> /etc/profile && \
echo "GRADLE_USER_HOME=/usr/local/gradle/.gradle" >> /etc/profile && \
echo "PATH=$PATH:$JAVA_HOME/bin:$GRADLE_HOME/bin:/usr/local/nginx/sbin/" >> /etc/profile && \
echo "export PATH JAVA_HOME CLASSPATH GRADLE_HOME GRADLE_USER_HOME" >> /etc/profile
####################################app需要的脚本文件#####################################
RUN \
mkdir -p /data/www/payment/ && \
mkdir -p /data/www/comm_project
##增加app需要的脚本到目录:/data/www/payment/
ADD deploy.py /data/www/payment/deploy.py
ADD deploy_conf.ini /data/www/payment/deploy_conf.ini
#设置脚本可执行
RUN chmod a+x /data/www/payment/deploy.py
##增加app需要的脚本到目录:/data/www/comm_project/
ADD deploy.py /data/www/comm_project/deploy.py
ADD deploy_conf.ini /data/www/comm_project/deploy_conf.ini
RUN chmod a+x /data/www/comm_project/deploy.py
#######################################其他配置###########################################
#给root创建密码密码
RUN echo "root:root123" | chpasswd
# 添加测试用户hfqtest,密码hfqtest,并且将此用户添加到sudoers里
RUN useradd hfqtest
RUN echo "hfqtest:hfqtest" | chpasswd
RUN echo "hfqtest ALL=(ALL) ALL" >> /etc/sudoers
# 初始化ssh登陆
#将sshd的UsePAM参数设置成no
#RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
RUN ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
RUN ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ''
RUN echo "RSAAuthentication yes" >> /etc/ssh/sshd_config
RUN echo "PubkeyAuthentication yes" >> /etc/ssh/sshd_config
# 启动sshd服务并且暴露22端口
RUN mkdir /var/run/sshd
EXPOSE 22
EXPOSE 80 443
#EXPOSE 12007
#开机启动sshd
RUN systemctl enable sshd.service
#ENTRYPOINT ["/usr/sbin/sshd", "-D"]
CMD ["/usr/sbin/sshd", "-D"]
#CMD ["/usr/sbin/init"]
###############################################构建脚本####################################
#构建image镜像
#docker build -t hfq/centos7:eden .
#启动container后台运行提供sshd服务
#docker run -d -P --name <container name> hfq/centos7:eden
#进入sshd启动的container
#docker exec -it <container name or id> /bin/bash
#docker rm $(docker ps -a | grep "xxx/jedi:v5" | awk '{print $1}')
#操作记录
#docker run -d -p 30001:12007 -p 31001:22 -P --name hfq-jedi-smq-eden hfq/centos7:eden
#docker run -d -p 30002:12007 -p 31002:22 -P --name hfq-jedi-zfc-eden hfq/centos7:eden
#docker run -d -p 30003:12007 -p 31003:22 -P --name hfq-jedi-wx-eden hfq/centos7:eden
#docker run -d -p 30004:12007 -p 31004:22 -P --name hfq-jedi-zxf-eden hfq/centos7:eden
#docker run -d -p 30005:12007 -p 31005:22 -P --name hfq-jedi-wjl-eden hfq/centos7:eden
#docker run -d -p 30006:12007 -p 31006:22 -P --name hfq-jedi-liqiang-eden hfq/centos7:eden
Docker使用-中文乱码问题处理
最新推荐文章于 2024-06-21 18:07:24 发布