万里长征docker化
2018-04-14 本文已影响22人
木易爽
FROM ubuntu
MAINTAINER by yangshuang (l247677858my@126.com)
#切换更新源
RUN sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/' /etc/apt/sources.list
#升级系统
RUN apt-get update
#安装openssh-server
RUN apt-get install -y openssh-server --fix-missing
#安装weget
RUN apt-get install -y wget --fix-missing
#修改/etc/ssh/sshd_config
RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config
#将密钥文件复制到/etc/ssh/目录中
ADD ssh_host_rsa_key /etc/ssh/ssh_host_rsa_key
ADD ssh_host_rsa_key.pub /etc/ssh/ssh_host_rsa_key.pub
RUN mkdir -p /root/.ssh
ADD authorized_keys /root/.ssh/authorized_keys
#将ssh服务启动脚本复制到/usr/local/sbin目录中,并改变权限为755
ADD run.sh /usr/local/sbin/run.sh
RUN chmod 755 /usr/local/sbin/run.sh
#变更root密码为147258
RUN echo "root:123456"|chpasswd
# 安装JDK
RUN mkdir /var/tmp/jdk
RUN wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" -P /var/tmp/jdk http://211.162.138.35/files/5167000003625F49/download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jdk-8u161-linux-x64.tar.gz
RUN tar xzf /var/tmp/jdk/jdk-8u161-linux-x64.tar.gz -C /var/tmp/jdk && rm -rf /var/tmp/jdk/jdk-8u161-linux-x64.tar.gz
#设置环境变量
ENV JAVA_HOME /var/tmp/jdk/jdk1.8.0_161
ENV PATH $PATH:$JAVA_HOME/bin
ENV CLASSPATH .:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
#开放窗口的22端口
EXPOSE 22
#运行脚本,启动sshd服务
CMD ["/usr/local/sbin/run.sh"]
运行容器
docker run -it --name jvm_centos origin_ubuntu:test /bin/bash #构建并启动容器
docker exec -it jvm_centos /bin/sh #进入已经创建好的容器
后记
倒腾docker的初衷是摒弃vmbox,后来发现不错
接下来 准备尝试把rocktemq集群docker化,前路漫漫