docker build
9840 ワード
file_dockerfile
# Tomcat
# Version 0.0.1
# GET_IMAGE
FROM 192.168.0.216:5000/centos
# MAINTAINER_INFO
MAINTAINER hongxue [email protected]
# YUM
#RUN rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
#RUN yum clean all
RUN yum -y install net-tools openssh-server wget curl elinks vim-enhanced openssh-clients lsof rsync
# SSH
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN sed -i 's/session required pam_loginuid.so/#session required pam_loginuid.so/g' /etc/pam.d/sshd
RUN mkdir /var/run/sshd
RUN echo "root:3dq2w3y2" | chpasswd
RUN mkdir /root/.ssh/
RUN echo "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAs+W8Wb/++MjXk3jndcF7676mjKlHJcPVoD2iTVTwvQEIFzn8D98PhJKp+BHwPbtjOrQr4LNlP7rBWFOK7tb4tLyTkcJVZ0s11Ovx0+OgIXpadstjKxSowW782FBiIL2nR3DKobWB26ccbC4xT0DFfctifdf4KN7B9ZO/owrAcFtIgAfmZtoAHrN5GktldazSvtYep79JW/sA3TV6a2LD9lNtnh5yA8+6qAwHLFkwqKYkiL7I7NEYVDET995OYpHowyG3kAgaYNNf69NAX1YqbmgjJsvpb8SPa31vp2S2ru8iIF5wP0O2VgpALK4PRuVN1VmOPTr2vtzNXXdXVKYB0w== root@hongxue_225" >> /root/.ssh/authorized_keys
# PORT
EXPOSE 22
EXPOSE 8080
EXPOSE 8009
EXPOSE 8005
EXPOSE 8443
# ADD Tomcat
ADD tomcat /usr/local/tomcats/tomcat
# ADD JDK
ADD java /usr/local/java
RUN echo "" >> /etc/profile
RUN echo "JAVA_HOME=/usr/local/java" >> /etc/profile
RUN echo "JAVA_BIN=/usr/local/java/bin" >> /etc/profile
RUN echo "PATH=$PATH:$JAVA_BIN" >> /etc/profile
RUN echo "CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar" >> /etc/profile
RUN echo "export JAVA_HOME JAVA_BIN PATH CLASSPATH" >> /etc/profile
# Start_All_Service
#RUN mkdir -p /var/log/supervisor
#COPY supervisord.conf /etc/supervisord.conf
#CMD ["/usr/bin/supervisord"]
CMD ["/usr/sbin/sshd","-D"]
file_build.sh
#!/bin/bash
server_addr="192.168.0.225"
server_file="/root/deploy/server_list.txt"
server_mod_CI="/root/deploy/ShowJoy-Module-CI.sh"
other_dir="/root/deploy/Other"
ui_dir="/root/deploy/UI"
service_dir="/root/deploy/Service"
local_addr=$(ifconfig eth0 | grep 'inet addr' | awk -F':' '{print $2}' | awk '{print $1}')
line=$(docker ps -a | grep -v 'CONTAINER ID' | wc -l)
ssh=$[$line * 10 + 10000]
http=$[$line * 10 + 10001]
shutdown=$[$line * 10 + 10002]
ajp=$[$line * 10 + 10003]
redirect=$[$line * 10 + 10004]
read -p "Please input service type [ jenkins|tomcat ] : " service_name
read -p "Please input item name : " name
docker run -d -it --name ${name} -v /etc/localtime:/etc/localtime:ro -p ${ssh}:22 -p ${http}:8080 -p ${shutdown}:8005 -p ${redirect}:8443 -p ${ajp}:8009 $service_name
if [ ${service_name} == "tomcat" ]
then
ssh root@${server_addr} "echo ${name} ${server_addr} ${ssh} ${http} >> ${server_file}"
read -p "Please input item type : [UI|Service|Other]:" type
item_name=$(echo ${name} | awk -F'-' '{print $1}')
case "${type}" in
[Uu][Ii])
ssh root@${server_addr} "cp -rf ${server_mod_CI} ${ui_dir}/ShowJoy-${item_name}-CI.sh"
ssh root@${server_addr} "sed -i s/Host/${local_addr}/g ${ui_dir}/ShowJoy-${item_name}-CI.sh"
ssh root@${server_addr} "sed -i s/Item/${name}/g ${ui_dir}/ShowJoy-${item_name}-CI.sh"
;;
[Ss][Ee][Rr][Vv][Ii][Cc][Ee])
ssh root@${server_addr} "cp -rf ${server_mod_CI} ${service_dir}/ShowJoy-${item_name}-CI.sh"
ssh root@${server_addr} "sed -i s/Host/${local_addr}/g ${service_dir}/ShowJoy-${item_name}-CI.sh"
ssh root@${server_addr} "sed -i s/Item/${name}/g ${service_dir}/ShowJoy-${item_name}-CI.sh"
;;
[Oo][Tt][Hh][Ee][Rr])
ssh root@${server_addr} "cp -rf ${server_mod_CI} ${other_dir}/ShowJoy-${item_name}-CI.sh"
ssh root@${server_addr} "sed -i s/Host/${local_addr}/g ${other_dir}/ShowJoy-${item_name}-CI.sh"
ssh root@${server_addr} "sed -i s/Item/${name}/g ${other_dir}/ShowJoy-${item_name}-CI.sh"
;;
*)
echo "Bad name!!! Tomcat type is a [ui|service|other]"
exit 1;
;;
esac
fi