Instructions
8 methodsDeclarative directives parsed top-to-bottom to assemble a container image.
FROM image[:tag] [AS stage]Sets the base image for subsequent instructions. Must be the first non-arg instruction.
Parameters
| Name | Type | Description |
|---|---|---|
| image | string | Base image name. |
| tag | string | Image tag (defaults to latest). |
| stage | string | Optional name for a multi-stage build stage. |
Returns
void
Example
FROM node:18-alpine AS builderRUN <command> | RUN ["exec", "arg1", ...]Executes a command in a new layer on top of the current image and commits the result.
Parameters
| Name | Type | Description |
|---|---|---|
| command | string | Shell command (shell form) or JSON array (exec form). |
Returns
void
Example
RUN apt-get update && apt-get install -y curl gitCOPY [--chown=user:group] src... destCopies new files or directories from the build context into the image filesystem.
Parameters
| Name | Type | Description |
|---|---|---|
| src | string | string[] | Source path(s) in the build context. |
| dest | string | Absolute or relative destination inside the container. |
| --chown | string | Optional user:group ownership for the copied files. |
Returns
void
Example
COPY --chown=node:node ./src ./app/srcWORKDIR pathSets the working directory for RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it.
Parameters
| Name | Type | Description |
|---|---|---|
| path | string | Absolute path; created if it does not exist. |
Returns
void
Example
WORKDIR /app
RUN pwd # /appENV KEY=VALUESets an environment variable that persists in the built image and containers run from it.
Parameters
| Name | Type | Description |
|---|---|---|
| KEY | string | Variable name. |
| VALUE | string | Variable value. |
Returns
void
Example
ENV NODE_ENV=productionEXPOSE port[/protocol]Documents which ports the container listens on at runtime. Does not publish the port.
Parameters
| Name | Type | Description |
|---|---|---|
| port | number | TCP/UDP port number. |
| protocol | string | Optional 'tcp' (default) or 'udp'. |
Returns
void
Example
EXPOSE 8080/tcpCMD ["exec", "arg1", ...] | CMD command arg1 ...Provides default executable and arguments for the container. Overridable at runtime. Only the last CMD takes effect.
Parameters
| Name | Type | Description |
|---|---|---|
| exec | string | Executable to run. |
| args | string[] | Arguments passed to the executable. |
Returns
void
Example
CMD ["node", "server.js"]ENTRYPOINT ["exec", "arg1", ...]Configures the executable that always runs when the container starts. CMD arguments are appended.
Parameters
| Name | Type | Description |
|---|---|---|
| exec | string | Executable to run. |
| args | string[] | Fixed arguments appended to the executable. |
Returns
void
Example
ENTRYPOINT ["/usr/bin/node", "server.js"]