docker是个好东西,我用它来当做轻量级虚拟机
自己写的一个Dockerfile,在一个Tomcat镜像的基础上加上redis、maven、MySQL等,可以当做轻量级的虚拟机,拿来做测试环境分分钟的事。
FROM dordoka/tomcat MAINTAINER yuanye@yuanyec.cn # RUN rm -rf /etc/apt/sources.list # COPY sources.list /etc/apt/sources.list RUN apt-get update RUN yes|apt-get remove vim-common RUN yes|apt-get install vim # tomcat RUN rm -rf /opt/tomcat/conf/tomcat-users.xml COPY tomcat-users.xml /opt/tomcat/conf/ RUN sed -i '2a edis-server &' /opt/tomcat/bin/catalina.sh RUN sed -i '3a#service mysql start' /opt/tomcat/bin/catalina.sh # maven COPY apache-maven-3.6.0-bin.tar.gz /opt/ RUN cd /opt && tar -zxvf apache-maven-3.6.0-bin.tar.gz RUN echo 'export M2_HOME=/opt/apache-maven-3.6.0' >> ~/.bashrc && echo 'export CLASSPATH=$CLASSPATH:$M2_HOME/lib' >> ~/.bashrc && echo 'export PATH=$PATH:$M2_HOME/bin' >> ~/.bashrc && source ~/.bashrc RUN rm -rf /opt/apache-maven-3.6.0/settings.xml COPY settings.xml /opt/apache-maven-3.6.0/ RUN yes|apt-get install redis-server # RUN yes|apt-get install mysql-server # RUN chown -R mysql:mysql /var/lib/mysql /var/run/mysqld
备注:docker安装MySQL比较麻烦(Ubuntu),因为在build的时候不能弹出输入MySQL密码的对话框,需要安装成功后进入容器手动修改root密码,比进入容器再安装MySQL还麻烦,Ubuntu上安装MySQL就一条命令sudo apt-get install mysql-server,而安装的时候不输入密码然后修改则需要12345步,懒人不干,所以我就把MySQL注释了