Can't build docker image from Dockerfile

8.7k Views Asked by At

Hello I'm trying to build a Docker image from a Docker file and get the following error:

java.lang.IllegalStateException: Could not acquire image ID or digest following build at com.google.common.base.Preconditions.checkState(Preconditions.java:444) ~[guava-21.0.jar:na] at com.spotify.docker.client.DefaultDockerClient$BuildProgressHandler.getImageId(DefaultDockerClient.java:298) ~[docker-client-8.11.7.jar:8.11.7] at com.spotify.docker.client.DefaultDockerClient$BuildProgressHandler.access$1200(DefaultDockerClient.java:287) ~[docker-client-8.11.7.jar:8.11.7] at com.spotify.docker.client.DefaultDockerClient.build(DefaultDockerClient.java:1481) ~[docker-client-8.11.7.jar:8.11.7]

I can build the same exact Dockerfile from the command line, but I can't debug this as the stack trace isn't very informative. Below I leave some information that may be relevant:

Docker version:

Client: Version: 17.03.2-ce API version: 1.27 Server: Version: 17.03.2-ce API version: 1.27 (minimum version 1.12)

spotify/docker-client version: 8.11.7

How I call the docker build function:

final AtomicReference<String> imageIdFromMessage = new AtomicReference<>();

final String returnedImageId = dockerClient.build(

Paths.get("/absolute/path/to/folder"), image.getImageName(), dockerfilefilename,new ProgressHandler() {
    @Override
    public void progress(ProgressMessage message) throws DockerException {

        final String imageId = message.buildImageId();

        if (imageId != null) {
            imageIdFromMessage.set(imageId);
        }
    }
});

I can submit any other relevant info and would appreciate any help or ideas.

Edit to add requested info:

image is a personal data representation of a docker image, the only relevant thing about it is it has the name I want to tag the docker.

dockerfilefilename again is just a string that contains the filename of the dockerfile. For example, the string "Dockerfile".

dockerClient is an instance of DockerClient. It was created like this:

`

    DockerClient dc = DefaultDockerClient.fromEnv().build();
    final RegistryAuth registryAuth = RegistryAuth.builder() //TODO change to external config
            .email("REDACTED")
            .username("REDACTED")
            .password("REDACTED")
            .build();
    final int statusCode = dc.auth(registryAuth);

    return dc;

`

I have checked and the status code is in fact 200. I've tried many Docker commands with the driver which are successful.

3

There are 3 best solutions below

0
On

I had the following problem at my end. In my dockerfile, the maintainer was mis-spelled. Please debug by trying to build the image using docker build -t .

0
On

I have encountered the same problem (as I've stated in comment to the question) and managed to fix it. The error that you get is a generic one and results from a failed sanity check inside the Docker client code that can be caused by a myriad of different things.

To get the specific reason that caused the sanity check fail you can look into message.error() in the progress handler - in my case the error message that was there was very clear.

0
On

In the Dockerfile, had added an environment variable but missed ENV.

Correct: ENV KEYCLOAK_ADMIN=keycloak

Bad: KEYCLOAK_ADMIN=keycloak