0

I am migrating a java standalone maven project in docker. As of now we create a jar file for this maven project and it runs with public static void main method.

java -cp app.jar com.xxx.ExportManager db.properties

After completion of this code it exports a file in its current directory.

Dockerfile

FROM centos:7

RUN yum install -y \
   java-1.8.0-openjdk \
   java-1.8.0-openjdk-devel

ENV JAVA_HOME /usr/lib/jvm/java-1.8.0-openjdk/

ENV echo $JAVA_HOME

RUN  java -version

ARG JAR_FILE=target/manager.jar
ARG JAR_LIB_FILE=target/lib/

WORKDIR /opt/manager/app/

COPY ${JAR_FILE} app.jar

COPY conf/db.properties /opt/manager/app/db.properties

ADD ${JAR_LIB_FILE} lib/

ENTRYPOINT ["java","-jar","app.jar"]

Commands:

  • Building image: docker build -t pc .
  • Run the main method: docker run -t pc /opt/manager/app/db.properties

After run it's exporting file inside image (I am sure because i have checked it through loggers) to /opt/manager/app/. But when i see the contents of image using command

docker run -it --entrypoint sh pc 
cd /opt/manager/app

the directory doesn't have exported file however it contains all other project files.

How to retain the exported file in the image?

PS: I'm new in docker, please forgive any mistakes.

James Z
  • 12,209
  • 10
  • 24
  • 44
Raushan
  • 307
  • 3
  • 12

1 Answers1

1

docker run -it --entrypoint sh pc actually starts a new container instead of starting a shell in a running one. So you are looking inside a new container where the exporting has not been done (because you overwrote the entry point).

To start a shell in a running container and attach your stdin/stdout to it, you need exec instead of run, e.g.:

docker exec -it pc bash

However in your particular scenario, you probably won't be able to start the shell anyway, because once the exporting is done, the container will be stopped. See this answer for examining the filesystem of a stopped container.

jingx
  • 3,698
  • 3
  • 24
  • 40