Docker: Is it Build-time or Runtime ?
February 18, 2025
•
3 mins read
TLDR:
Build-time:
FROM,LABEL,ARG,COPY,ADD,RUN,ONBUILDRuntime:
EXPOSE,CMD,ENTRYPOINT,VOLUME,HEALTHCHECKBoth:
USER,WORKDIR,ENV
This has always been popping up when I'm working with Dockerfile or Docker compose. Some of the commands can be run in build-time, but some can't. Maybe you want to run a specific command only in runtime. Totally depends on your situation 🥂. On my end, this issue showed up in my prisma migration, quite similar to this github issue where I can't run prisma migrate on RUN instruction.

I'll be listing the things that I know currently is under Build-time, and Runtime.
These will run while the image is building (some came from this reference).
| Instruction | Description |
|---|---|
| FROM | Specifies the base image. |
| LABEL | Adds metadata |
| ARG | Defines a build-time variable |
| COPY | Copies new files or directories from <src> and adds them to the filesystem of the container at the path <dest>. |
| ADD | Copies new files, directories or remote file URLs from <src> and adds them to the filesystem of the container at the path <dest>. |
| RUN | Executes any commands in a new layer on top of the current image and commits the results. |
| ONBUILD | Executes instructions when the image is used as a base image |
These will run when the image has been built, and the container will run.
| Instruction | Description |
|---|---|
| EXPOSE | Documents the port the container listens on |
| CMD | Provides defaults for an executing container. These can include an executable, or they can omit the executable, in which case you must specify an ENTRYPOINT instruction. |
| ENTRYPOINT | Allows you to configure a container that will run as an executable. |
| VOLUME | Creates a mount point for persistent storage (ensures data is not lost when the container stops). |
| HEALTHCHECK | Defines a command to monitor the container’s health while it is running. |
These are being used for both Build-time, and Runtime.
| Instruction | Description |
|---|---|
| USER | Sets the user for subsequent commands in buildtime, and sets the user for runtime CMD, and ENTRYPOINT |
| WORKDIR | Sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow in the Dockerfile. |
| ENV | Defines environment variables that are available both at build-time and runtime. |
When using Docker compose, env is actually runtime. If you want to use it for build-time, use build arg instead.
That's it! 🔥

© 2025 Alec Blance
Bacolod, PH