項目往基於容器上遷移,涉及到最基本的基礎鏡像製作,本文介紹製作一個基礎的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 [email protected]
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