项目往基于容器上迁移,涉及到最基本的基础镜像制作,本文介绍制作一个基础的jdk的镜像并push到私有仓库。
准备文件
sources.list
由于需要使用apt安装一些相关的组件,将源指向我们公司内部的源,内容如下:
deb http://192.168.88.8/ubuntu/ trusty main restricted universe multiverse
deb http://192.168.88.8/ubuntu/ trusty-security main restricted universe multiverse
deb http://192.168.88.8/ubuntu/ trusty-updates main restricted universe multiverse
deb http://192.168.88.8/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://192.168.88.8/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://192.168.88.8/ubuntu/ trusty main restricted universe multiverse
deb-src http://192.168.88.8/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://192.168.88.8/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://192.168.88.8/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://192.168.88.8/ubuntu/ trusty-backports main restricted universe multiverse
jdk
下载jdk-7u79-linux-x64.tar.gz拷贝过来即可
java.sh
设置java的环境变量,内容为:
export JAVA_HOME=/opt/jdk1.7.0_79
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/
Dockerfile
最重要的,内容为:
build the base image: jdk
this is the docker file, use the ubuntu 14.04
VERSION 1
Author: jthink
the basic image
FROM 192.168.xx.xx:5000/ubuntu:14.04
maintainer
MAINTAINER jthink qianjc@xxx.com
copy the file
ADD ./sources.list /etc/apt
RUN apt-get update
RUN apt-get install tar
RUN apt-get install unzip
ADD ./jdk-7u79-linux-x64.tar.gz /opt
ADD ./java.sh /etc/profile.d
CMD to start
CMD /usr/sbin/sshd -D
选择基础镜像为ubuntu:14.04
将相关的文件拷贝至镜像容器中的位置
安装相关的软件
设置java的环境变量
构建
执行命令
sudo docker build -t 192.168.xx.xx:5000/ubuntu:14.04-jdk7 .
sudo docker push 192.168.xx.xx:5000/ubuntu:14.04-jdk7
启动
执行命令
sudo docker run -ti -d --name ubuntu-jdk7 192.168.xx.xx:5000/ubuntu:14.04-jdk7 /bin/bash
进入容器验证下是否有安装的命令和java -version
转载于:https://blog.51cto.com/zengfuqiu/2093818