skip to Main Content

I created the images locally and created one repository in DockerHub called testName/backend.

The docker images command shows the created images.

 REPOSITORY              TAG              IMAGE ID       CREATED          SIZE  
    testName/backend       0.0.1-SNAPSHOT   10fc47e065ff   25 minutes ago   459MB 
    backend                 0.0.1-SNAPSHOT   10fc47e065ff   25 minutes ago   459MB 
    backend                 latest           2f5cc7be2b5d   41 minutes ago   479MB 
    alpine/git              latest           22a2874e1112   3 weeks ago      39.5MB
    hello-world             latest           feb5d9fea6a5   10 months ago    13.3kB

And I would like to run the container with a command in the format docker run yourImage:version. So according to this (so I think I should call such a command: docker run 10fc47e065ff:0.0.1-SNAPSHOT
However, I get this message: Unable to find image ’10fc47e065ff:0.0.1-SNAPSHOT’ locally
docker: error response from daemon: pull access denied for 10fc47e065ff, repository does not exist or may require ‘docker login’: denied: requested access to the resource is denied.

I will add that I am logged in.

What am I doing wrong that I can’t get the container to work?

By the way, I have a question about the docker in the context of the application. Generally, in this image there is a Spring Boot + Angular application. I am uploading it to a container, and spring + angular is supposed to work together with each other . And generally the question I have is whether I will have to create a new image every time I make a modification to the application code, or if I run the application using the docker run command then the image will be automatically overwritten and every time I run the application I will get the "latest version" of the application.

Dockerfile

FROM eclipse-temurin:17-jdk-alpine
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} backend.jar
ENTRYPOINT ["java","-jar","/backend-0.0.1-SNAPSHOT.jar"]

build.gradle

plugins {
    id 'org.springframework.boot' version '2.7.2'
    id 'io.spring.dependency-management' version '1.0.12.RELEASE'
    id 'java'
    id "com.palantir.docker" version "0.34.0"
    id "com.palantir.docker-run" version "0.34.0"

}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

docker {
    name "${project.name}:${project.version}"
    dockerfile file('Dockerfile')
    copySpec.from(jar).rename(".*", "backend.jar")
    buildArgs(['JAR_FILE': "backend.jar"])
    files 'backend.jar'
    tag 'DockerHub', "testName/backend:${project.version}"
}

dockerRun {
    name "${project.name}"
    image "${project.name}:${project.version}"
    ports '8081:8081'
    clean true
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compileOnly 'org.projectlombok:lombok'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
    useJUnitPlatform()
}

4

Answers


  1. You are not using the correct image name. The image ID (10fc47e065ff) is a unique identifier so you could use that and not need to refer to a tag at all, or else you use the image name (repository as shown in the list) in combination with the tag to reference a unique image. eg. testName/backend:0.0.1-SNAPSHOT.

    If you application code changes, you will need to build a new image. So if you needed to rebuild the spring boot application you would also rebuild the image – this would produce a new image with a new ImageID. The ImageID is unique to each image build, but you can name/rename and label/relabel any image anytime. The ImageID is a unique identifier but the name/tag combination is not. Typically you might use the image label latest to always get the most recently build image. Alternatively, if you want to know exactly what image you want to deploy/run you would use a specific image name and tag that you have assigned to the image.

    Login or Signup to reply.
  2. I am not sure that you have to use the Image ID. Do docker -ps -a and try with docker run [container_id].

    Login or Signup to reply.
  3. try use docker run -d backend: 0.0.1-SNAPSHOT

    Login or Signup to reply.
  4. It should helps you:

    docker run -d testName/backend:0.0.1-SNAPSHOT
    

    As for your second question… Yes, you have to rebuild the image every time you change the code. If you run docker build and an image with the same repository name and tag already locally exists, then the name and tag of the previous image will be set to <none>.

    It looks like you should modify your Dockerfile as follows:

    FROM eclipse-temurin:17-jdk-alpine
    ARG JAR_FILE=build/libs/*.jar
    COPY ${JAR_FILE} backend.jar
    ENTRYPOINT ["java", "-jar", "backend.jar"]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search