2

I have a jar file, pom file and config.yml file along with dockerfile inside a folder named app which is in /Desktop. How can I pack all those files into a docker image?

This is my current docker file. What should I change?

FROM java:8
WORKDIR /
ADD /Desktop/app $HOME/app
CMD ["java", "-jar", "appserver.jar", "server", "config.yml"]

1 Answer 1

1

You could start with this simple Dockerfile:

FROM java:8
WORKDIR /
ADD app /app
CMD ["java", "-jar", "/app/appserver.jar", "server", "/app/config.yml"]

The Dockerfile should be created in a directory which contains also the app directory with your appserver.jar and config.yml files:

├── workdir/
│   ├── Dockerfile
│   └── app/
|       ├── application.jar
|       └── config.yml

Now, to build the docker image, run, in the workdir, the following command:

docker build -t app-name:1.0 .
5
  • can you explain the change, please @thanh Jan 31, 2019 at 7:42
  • just added in the answer Jan 31, 2019 at 7:44
  • one more question @thanh, in COPY . /app that mentions root directory right? that means it will copy all my files from the root into the image?? Jan 31, 2019 at 8:59
  • it means it will copy all files and folders in /Desktop/app to /app folder in the image. Jan 31, 2019 at 9:01
  • CMD ["java", "-jar", "/app/appserver.jar", "server", "/app/config.yml"] only after making this change it worked.I have pom.xml file which is inside app/ folder is not getting recognised. Jan 31, 2019 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.