dockerfile
FROM openjdk:alpine
ARG JAR_FILE=target/*.jar
COPY ./target/diplomAPI-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
docker-compose.yml
version: '3'
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:8080"
depends_on:
- db
db:
image: postgres
restart: always
ports:
- "5432:5432"
environment:
POSTGRES_DB: mobilka
POSTGRES_USER: postgres
POSTGRES_PASSWORD: 12345
error code:
PS C:UsersextreIdeaProjectsdiplomAPI> docker-compose build
[+] Building 0.0s (0/0) docker:default
[+] Building 0.0s (0/0) docker:defaultr reading preface from client //./pipe/docker_engine: file has already been closed
[+] Building 2.2s (6/7) docker:default
=> [app internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 180B 0.0s
=> [app internal] load metadata for docker.io/library/openjdk:alpine 2.0s
=> [app auth] library/openjdk:pull token for registry-1.docker.io 0.0s
=> [app internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> ERROR [app internal] load build context 0.0s
=> => transferring context: 57B 0.0s
=> [app 1/2] FROM docker.io/library/openjdk:alpine@sha256:1fd5a77d82536c88486e526da26ae79b6cd8a14006eb3da3a25eb8d2d682ccd6 0.0s
------
> [app internal] load build context:
------
failed to solve: changes out of order: "target/diplomAPI-0.0.1-SNAPSHOT.jar" ""
The Dockerfile
and docker-compose.yml
files are in the same folder. The file diplomAPI-0.0.1-SNAPSHOT.jar
actually exists and is located in the specified folder.
I attempted deleting a line ARG JAR_FILE=target/*.jar
without any improvement.
I attempted to put the Dockerfile and docker-compose.yml in a separate folders and specified this path as the context without any improvement.
2
Answers
The error you’re encountering is due to the inability to find the
diplomAPI-0.0.1-SNAPSHOT.jar
file during the Docker build process. Here’s a simplified version of yourDockerfile
that directly copies the JAR file into the container:Ensure that the
diplomAPI-0.0.1-SNAPSHOT.jar
file exists in the target directory relative to yourDockerfile
anddocker-compose.yml
file.If the
JAR
file exists in a different directory, adjust the path accordingly in theCOPY
command.Then, try building your Docker image again using
docker-compose build
.The
failed to solve: changes out of order
error message is a bug in docker compose running in Docker Desktop.According to the issue, this is resolved by upgrading our downgrading Docker Desktop to a version other than 4.27.1. You could also build with
docker build
directly, or attempt to disable buildkit withDOCKER_BUILDKIT=0 docker compose build
.