skip to Main Content

Does Docker link images at build time or execution time? I am presenting a very simple case here to demonstrate my dilemma but I am presently rebuilding a chain of Docker files every time I change the base docker image and Im not sure if I even need to.

I have two docker files:

my base-docker-file contains

# this is not based on another image

RUN build commands here 

which I build with

docker build --no-cache -t base-image -f base-docker-file.

and my from-docker-file here:

# this is based on the base-image
FROM base-image

RUN build commands here 

which I build with

docker build --no-cache -t from-image -f from-docker-file.

Based on this simple setup, do I need to rebuild my from-image whenever I make a change to my base-image or does image linking occur at run time?

2

Answers


  1. 1. Multi-stage build

    Multi-stage build allows you to isolate images in one Dockerfile. 1

    Example:

    # syntax=docker/dockerfile:1
    FROM alpine:latest AS builder
    RUN apk --no-cache add build-base
    
    FROM builder
    COPY source1.cpp source.cpp
    RUN g++ -o /binary source.cpp
    

    2. Turn off no-cache when building the base-image.

    Simple. If there are no changes in the base image, it will not rebuild due to cache.

    Login or Signup to reply.
  2. you will have to build each time if you make a change to the base-image. You could add these individual commands in a script to be executed together rather than running them separate everytime

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search