Dockerfile
FROM centos:centos6
MAINTAINER Linus Chien <linus_chien@mail.gss.com.tw>
RUN yum install -y openssh-server java-1.7.0-openjdk wget tar python-setuptools mysql-server
# setup root's password
RUN echo 'root:12345678' | chpasswd
# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
# init SSH keys
RUN /sbin/service sshd start && /sbin/service sshd stop
# init MySQL database
RUN /sbin/service mysqld start && /sbin/service mysqld stop
ENV TOMCAT_SITE https://archive.apache.org/dist/tomcat
ENV TOMCAT_MAJOR_VERSION 7
ENV TOMCAT_MINOR_VERSION 7.0.57
RUN wget -q ${TOMCAT_SITE}/tomcat-${TOMCAT_MAJOR_VERSION}/v${TOMCAT_MINOR_VERSION}/bin/apache-tomcat-${TOMCAT_MINOR_VERSION}.tar.gz && \
wget -qO- ${TOMCAT_SITE}/tomcat-${TOMCAT_MAJOR_VERSION}/v${TOMCAT_MINOR_VERSION}/bin/apache-tomcat-${TOMCAT_MINOR_VERSION}.tar.gz.md5 | md5sum -c - && \
tar zxf apache-tomcat-*.tar.gz && \
rm apache-tomcat-*.tar.gz && \
mv apache-tomcat* /opt/
RUN easy_install supervisor
ADD supervisord.conf /etc/supervisord.conf
EXPOSE 22 3306 8080
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
MAINTAINER Linus Chien <linus_chien@mail.gss.com.tw>
RUN yum install -y openssh-server java-1.7.0-openjdk wget tar python-setuptools mysql-server
# setup root's password
RUN echo 'root:12345678' | chpasswd
# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
# init SSH keys
RUN /sbin/service sshd start && /sbin/service sshd stop
# init MySQL database
RUN /sbin/service mysqld start && /sbin/service mysqld stop
ENV TOMCAT_SITE https://archive.apache.org/dist/tomcat
ENV TOMCAT_MAJOR_VERSION 7
ENV TOMCAT_MINOR_VERSION 7.0.57
RUN wget -q ${TOMCAT_SITE}/tomcat-${TOMCAT_MAJOR_VERSION}/v${TOMCAT_MINOR_VERSION}/bin/apache-tomcat-${TOMCAT_MINOR_VERSION}.tar.gz && \
wget -qO- ${TOMCAT_SITE}/tomcat-${TOMCAT_MAJOR_VERSION}/v${TOMCAT_MINOR_VERSION}/bin/apache-tomcat-${TOMCAT_MINOR_VERSION}.tar.gz.md5 | md5sum -c - && \
tar zxf apache-tomcat-*.tar.gz && \
rm apache-tomcat-*.tar.gz && \
mv apache-tomcat* /opt/
RUN easy_install supervisor
ADD supervisord.conf /etc/supervisord.conf
EXPOSE 22 3306 8080
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]
supervisord.conf
[supervisord]
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=10MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=true ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)
;[program:apache2]
;command = /usr/sbin/httpd -D FOREGROUND
;priority = 30
;[program:tomcat7]
;command = /opt/apache-tomcat-7.0.57/bin/catalina.sh run
;priority = 20
[program:mysql5]
command = /usr/bin/pidproxy /var/run/mysqld/mysqld.pid /usr/bin/mysqld_safe
priority = 10
[program:sshd]
command = /usr/sbin/sshd -D
priority = 40
步驟:
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=10MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=true ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)
;[program:apache2]
;command = /usr/sbin/httpd -D FOREGROUND
;priority = 30
;[program:tomcat7]
;command = /opt/apache-tomcat-7.0.57/bin/catalina.sh run
;priority = 20
[program:mysql5]
command = /usr/bin/pidproxy /var/run/mysqld/mysqld.pid /usr/bin/mysqld_safe
priority = 10
[program:sshd]
command = /usr/sbin/sshd -D
priority = 40
- 安裝docker,並啟動,細節請自行參閱官方文件。
- 準備好上述兩個檔案:Dockerfile、supervisord.conf
- 執行
- docker build -t cao:tomcat7 . # use your own tag name, don't miss the dot
- docker run -d --name="tomcat" cao:tomcat7 # assign a unique name to container for convenience
- docker inspect tomcat # you can find container's IP address
- ssh {IP} # default root's password setup in Dockerfile