背景
需求:将现有的一个java程序迁移为容器化部署。大致过程为,根据目前物理机部署环境,以centos7为基础镜像,加入程序运行用到的jdk和oracle client环境,然后指定启动命令。
文件准备
$ ls
Dockerfile test-3.3.tar.gz jdk-8u251-linux-x64.tar.gz oracle-instantclient19.8.tar.gz README.md
编写Dockerfile
$ vi Dockerfile
FROM centos:7
MAINTAINER Peter<peter1024@qq.com>
ADD oracle-instantclient19.8.tar.gz /app
ADD test-3.3.tar.gz /app
ADD jdk-8u251-linux-x64.tar.gz /app
RUN yum install -y libaio
RUN rpm -ivh /app/oracle-instantclient19.8/oracle-instantclient19.8-basic-19.8.0.0.0-1.x86_64.rpm
RUN rpm -ivh /app/oracle-instantclient19.8/oracle-instantclient19.8-devel-19.8.0.0.0-1.x86_64.rpm
RUN rpm -ivh /app/oracle-instantclient19.8/oracle-instantclient19.8-sqlplus-19.8.0.0.0-1.x86_64.rpm
RUN rpm -ivh /app/oracle-instantclient19.8/oracle-instantclient19.8-tools-19.8.0.0.0-1.x86_64.rpm
ENV JAVA_HOME /app/jdk1.8.0_251
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
ENV ORACLE_HOME /usr/lib/oracle/19.8/client64
ENV PATH $PATH:$ORACLE_HOME/bin
ENV LD_LIBRARY_PATH $ORACLE_HOME/lib:$LD_LIBRARY_PATH
VOLUME /app/test-3.3/conf
ENTRYPOINT ["/app/test-3.3/bin/startup.sh", "-ftp", "y"]
$
构建镜像
$ docker build -t test:3.3 .
查看镜像
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
test 3.3 2f1c200490ae 2 days ago 1.1GB
$
运行容器
$ docker run -d \
-v /work/test-3.3-conf:/app/test-3.3/conf \
--name test \
test:3.3
$
导出镜像
$ docker save test:3.3 > test-3.3.tar
$ ls fpf-xml2db-lte-nrm.tar
fpf-xml2db-lte-nrm.tar
$
导入镜像
$ docker load < fpf-xml2db-lte-nrm.tar