Compile a java file using docker with own path

Hy. I’m trying to compile a .java file using docker. I read the files on docker’s website, also I read these links:

docker’s website

  • Is there any point in Dockerizing a remote Git repository?
  • grails/mysql with docker compose
  • Unable to start any container when Volumes are enabled Docker Toolbox
  • Develop guide with docker images
  • Why can't I extend docker postgres image to create extra database and user
  • How to rebuild docker image on push before CI script jobs
  • about volumes

    and another question I had put up for gcc compiler

    I understood the concept for the gcc compiler since it doesn’t create any extra file for compiling.
    But the java one does. It creates a Main.class file on my /home directory if I use the following command and compile a file named

    sudo docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp java:7 javac

    after learning from the above links I was able to successfully compile a java file with my own path using:

    docker run --rm -v /mypathhere/ java:7 javac"

    if there is any error it shows an error but if there isn’t it just compiles and gives me no output, and that’s justified because it creates a Main.class file.

    My problem is that I am unable to find that Main.class file. I don’t know where docker is creating it and I have zero understanding for it. Please help me out.

  • Containerizing a web application using Docker: copy source code to multiple images?
  • Build with docker into host directory
  • How to manage Docker private registry
  • Docker Container Usage
  • Custom Docker Bridge w/ Fedora 22
  • Docker Ubuntu image missing prompt, color and completion?
  • One Solution collect form web for “Compile a java file using docker with own path”

    The .class file will be inside the container, under the root directory.

    The best plan is to mount the whole source directory and have javac put the result to the same directory e.g:

    docker run --rm -v /mypathhere:/mycode java:7 sh -c "cd mycode; javac"

    That way, you should get the class file written to the mypathhere directory.

    Apologies if that doesn’t quite work – it’s off the top of my head. Hopefully you get the idea though.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.