Sachin Chandra
Sachin Chandra

Reputation: 39

Unable to build docker image from docker file

I am trying to build a docker image from my docker file however I get an error javac: file not found: HelloWorld.java.Can someone help me in this. I am doing this on my window 10 machine where I have installed docker. My docker file is as below

    FROM java:8
    WORKDIR /abc
    RUN javac HelloWorld.java
    CMD ["java", "HelloWorld"]

Build command

    C:\EclipseJavaWorkspace\HelloWorldDocker>docker build -t java-app .
    Sending build context to Docker daemon  9.728kB
    Step 1/4 : FROM java:8
    ---> d23bdf5b1b1b
    Step 2/4 : WORKDIR /abc
    ---> Using cache
 ---> 60d073ad2c81
Step 3/4 : RUN javac HelloWorld.java
 ---> Running in da2d882fc830
javac: file not found: HelloWorld.java
Usage: javac <options> <source files>
use -help for a list of possible options
The command '/bin/sh -c javac HelloWorld.java' returned a non-zero code: 2

Upvotes: 0

Views: 309

Answers (2)

Sachin Chandra
Sachin Chandra

Reputation: 39

Thanks a lot for the help. Yes after adding the line COPY HelloWorld.java . it works now.So it means COPY is mandatory after we add the WORKDIR. Below are the lines of code which works perfectly.

FROM java:8
WORKDIR /abc
COPY HelloWorld.java .      // I added this one with a dot at the end
RUN javac HelloWorld.java
CMD ["java", "HelloWorld"]

Upvotes: 0

Mihai
Mihai

Reputation: 10767

You need to also copy the file inside the container:

FROM java:8
WORKDIR /abc
COPY HelloWorld.java .
RUN javac HelloWorld.java
CMD ["java", "HelloWorld"]

Upvotes: 1

Related Questions