I have a directory and it’s structure is something like this:
.
├── docker
│ ├── docker-compose.yml
│ └── Dockerfile
├── java-app
│ ├── pom.xml
│ └── src
I want to create a docker image without changing the structure but I am getting this error:
=> [internal] load build context 0.0s
=> => transferring context: 2B 0.0s
=> CACHED [2/5] WORKDIR /app 0.0s
=> ERROR [3/5] COPY java-app/pom.xml /app/ 0.0s
=> ERROR [4/5] COPY java-app/src /app/src 0.0s
------
> [3/5] COPY java-app/pom.xml /app/:
------
------
> [4/5] COPY java-app/src /app/src:
------
Dockerfile:8
--------------------
6 |
7 | # Copy the necessary files to the working directory
8 | >>> COPY java-app/pom.xml /app/
9 | COPY java-app/src /app/src
10 |
--------------------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref b1c85d8c-d082-47bf-843c-99a804945668a::o15zbeasfb4ieh2fetvzcczhp4a: "/java-app/pom.xml": not found
This is my Dockerfile
# Use a base image with Java 11 installed
FROM eclipse-temurin:11-jdk
# Set the working directory inside the container
WORKDIR /app
# Copy the necessary files to the working directory
COPY ../java-app/pom.xml /app/
COPY ../java-app/src /app/src
# Build the application
RUN ./mvn package -DskipTests
# Expose the port on which the application will run
EXPOSE 8080
# Start the application
CMD ["java", "-jar", "target/your-app.jar"]
What am I doing wrong here? I would appreciate some help
3
Answers
Docker sends the set of files around the docker file to the server (called “context”)
The server sees this copy only. You cannot go outside of it.
Move the docker file.
Docker will set the context folder with the folder which you run the command. You can run from outside of Dockerfile
And in the Dockerfile you can edit path 2 line with COPY
From the documentation:
so you could, from the java app directory, use: