Issue
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()
}
Solution
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.
Answered By - JohnXF
Answer Checked By - Candace Johnson (JavaFixing Volunteer)