Base Docker images for Node.js applications.
Docker releases >=2.4.0.0 have BuildKit enabled by default - this breaks image builds due to a known issue (moby/buildkit#816) with BuildKit and ONBUILD COPY --from directives which we use in our runtime image.
To fix this you can disable BuildKit in one of two ways:
- Prefix
docker buildcommands withDOCKER_BUILDKIT=0 - Disable BuildKit system wide by configuring the Docker daemon for your system - see: https://docs.docker.com/config/daemon/#configure-the-docker-daemon
| Tag | OS | Node.js version |
|---|---|---|
169942020521.dkr.ecr.eu-west-1.amazonaws.com/base/node:14-alpine-builder |
Alpine | 14.x |
169942020521.dkr.ecr.eu-west-1.amazonaws.com/base/node:14-alpine-runtime |
Alpine | 14.x |
Here are the build arguments used in the base builder images:
| Name | Default value | Required | Comment |
|---|---|---|---|
SSH_PRIVATE_KEY |
none | no | used to pull dependencies from GitHub during build phase, needed only if dependencies are stored in private GitHub repository |
SSH_PRIVATE_KEY_PASSPHRASE |
none | no | used to remove passphrase from key, needed only if key is protected |
Here are the properties used in the base images:
| Directive | Value |
|---|---|
WORKDIR |
/app |
ENTRYPOINT |
node |
Follow below steps to package Node.js application as a Docker image:
-
create
.dockeringorefile to filter out files that should not be copied to Docker image -
create
Dockerfilefile with instructions below and adjust port number to one application uses:FROM 169942020521.dkr.ecr.eu-west-1.amazonaws.com/base/node:14-alpine-builder FROM 169942020521.dkr.ecr.eu-west-1.amazonaws.com/base/node:14-alpine-runtime CMD ["/app/dist/server.js"] EXPOSE 9999
-
build Docker image with the command
DOCKER_BUILDKIT=0 docker build -t 169942020521.dkr.ecr.eu-west-1.amazonaws.com/local/[application name] .or if project requires dependencies stored in private GitHub repository use commandDOCKER_BUILDKIT=0 docker build --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)" --build-arg SSH_PRIVATE_KEY_PASSPHRASE -t 169942020521.dkr.ecr.eu-west-1.amazonaws.com/local/[application name] .
This project is licensed under the MIT License - see the LICENSE file for details.