Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give name or tag for intermediate image?

Tags:

java

docker

I used docker to build my Java application and I using the multi-stage building and I have some problems every time when I run the docker command for building the docker creates new intermediate image with tag and name none and I need the possibility to called intermediate containers.

That is my dockerfile:

FROM jdk8_201-ubuntu16.04 as java_build
RUN apt-get update && \
    apt-get install -y dos2unix

ARG MVN_USER
ARG MVN_PASS
ARG GIT_BRANCH
ARG BUILD_ID
ARG COMMIT_ID
WORKDIR /tmp/app

COPY pom.xml /maven-build/pom.xml
COPY /.mvn/settings.xml /maven-build/settings.xml
COPY mvnw ./mvnw
COPY mvnw.cmd ./mvnw.cmd
COPY /.mvn ./.mvn

RUN chmod +x ./mvnw && \
./mvnw -s /maven-build/settings.xml -B -f /maven-build/pom.xml dependency:resolve dependency:resolve-plugins dependency:go-offline

COPY ./ ./

FROM ubuntu
...

and after each running docker build command I had a many none images:

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
<none>              <none>              30e2325fcf15        18 hours ago        1.68GB
<none>              <none>              30e2325fcf16        18 hours ago        1.68GB
<none>              <none>              30e2325fcf14        18 hours ago        1.68GB
<none>              <none>              30e2325fcf18        18 hours ago        1.68GB
<none>              <none>              30e2325fcf13        18 hours ago        1.68GB

How can I replace none name of intermediate images to my_image_name?

like image 883
John Avatar asked Nov 21 '19 09:11

John


People also ask

What is the correct command to tag an image?

2. Explicitly tagging an image through the tag command. This command just creates an alias (a reference) by the name of the TARGET_IMAGE that refers to the SOURCE_IMAGE. That's all it does.

Can I use 2 from in Dockerfile?

With multi-stage builds, you use multiple FROM statements in your Dockerfile. Each FROM instruction can use a different base, and each of them begins a new stage of the build. You can selectively copy artifacts from one stage to another, leaving behind everything you don't want in the final image.

What is intermediate container in Docker?

Docker containers are building blocks for applications. Each container is an image with a readable/writeable layer on top of a bunch of read-only layers. These layers (also called intermediate images) are generated when the commands in the Dockerfile are executed during the Docker image build.


1 Answers

You can use the --target keyword to build just a specific stage:

docker build --target compile-image --tag compile-image:0.0.1 .

like image 195
mierzwid Avatar answered Oct 22 '22 02:10

mierzwid