docker基础镜像制作

项目往基于容器上迁移,涉及到最基本的基础镜像制作,本文介绍制作一个基础的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
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值