1

I have a composer file:

version: '2'
services:
        applic:
              image: tomcat
              ports:
                    - "8082:8080"
              depends_on:
                    - rabbit_image
                    -packager
              volumes:
                    - "/home/ustin/second_try/common_data:/home"
       rabbit_image:
              image: rabbitmq
              ports:
                    - "15673:5672"
       packager:
              build:
                     context: ./maven_images
                     dockerfile: Dockerfile
              volumes:
                    - "/home/ustin/second_try/common_data:/home"

and Dockerfile:

FROM maven
RUN mkdir clonefolder && cd clonefolder && git clone <repo.git> && cd docker-test-task && mvn clean package && cd target/ && cp docker-test-task-1.0.war /home && cd /home && ls

The main idea: using Dockerfile in image with maven i want to clone repo, create .war file using "clean package" command and lay it to "/home" folder, that before was defined as volume-folder and linked with "/home/ustin/second_try/common_data" on host-machine. At this moment i expect .war file on my host-machine. And then i want to get this .war to other image and lay this file into tomcat.

Question is: why i cannot find .war file not in my image in /home folder (but cp command was succesful), not in host-machine folder ? (ubuntu)

All steps - done: with re-build: http://prntscr.com/jrolk7 or cached: http://prntscr.com/jrolun

Ustin
  • 568
  • 6
  • 19

1 Answers1

1

You are running all of your commands in one RUN directive. You are building an image with one layer in which your compiled .war file exists.

The short answer is that you need to run a container using this image and docker cp your file out of it onto your host.

The long answer is that you should consider creating a reusable image that will dynamically build your WAR file and output to your host using a volume.

Here is some info on best practices for Dockerfiles: https://docs.docker.com/develop/develop-images/dockerfile_best-practices/

sp0gg
  • 3,722
  • 1
  • 17
  • 20
  • ok, but i don't understand where i should run "docker cp" command.. in "command" block of current service in composer file ?( – Ustin Jun 06 '18 at 16:59
  • First you need to start up a container using the image. See documentation here:https://stackoverflow.com/questions/18497688/run-a-docker-image-as-a-container After you start the container, you can run `docker cp` against the container. See more here: https://docs.docker.com/engine/reference/commandline/cp/ Note that this is not the long-term, recommended solution to this problem - the "long answer" option above is far more preferable and maintainable. – sp0gg Jun 06 '18 at 17:05