Build node.js docker images without docker
npm install containerifycontainerify (previously known as doqr) allows you to build node.js docker images without docker, allowing you to build a node.js docker image _from within a docker container_. This means you can build the container image on Kubernetes or Openshift - or locally in a docker container for more hermetic builds.
It will pull an image you specify from a given registry, add the node.js application from a given folder, and push the result to a(nother) given registry.
```
npm install -g containerify
This will pull the node:13-slim image from Docker hub, build the image by adding the application in src/, and push the result to the given registry, and set time timestamp of files in the created layers and configs to the current timestamp of the latest git commit.
``
containerify --fromImage node:13-slim --folder src/ --toImage myapp:latest --toRegistry https://registry.example.com/v2/ --setTimeStamp=$(git show -s --format="%aI" HEAD)
If you want to build a non-node container (e.g. add compiled frontend code to an nginx container), you can use --customContent. When doing thisnode_modules
the normal etc layers will not be added. By default it does _NOT_ modify then entrypoint, user or workdir, so the base image settings are still used when running. You can still override with --entrypoint etc. if needed.
``
npm run build # or some other build command
containerify --fromImage nginx:alpine --folder . --toImage frontend:latest --customContent dist:/usr/share/nginx/html --toRegistry https://registry.example.com/v2/
This will take the nginx:alpine image, and copy the files from ./dist/ into /usr/share/nginx/html.
1. Create a token from https://github.com/settings/tokens/new?scopes=write:packages or use GITHUB_TOKEN from Github Actions
2. Example: containerify --registry https://ghcr.io/v2/ --token "$GITHUB_TOKEN" --fromImage docker-mirror/node:alpine --toImage
1. Create the repository in AWS from the console or through using the CLI
2. Create token using aws ecr get-authorization-token --output text --query 'authorizationData[].authorizationToken'containerify --toToken "Basic $TOKEN" --toRegistry https://
3. Example:
1. Create the repository in GitLab
2. Login using your username and password, CI-credentials, or obtain a token from GitLab
3. Example using CI-credentials containerify --toToken "Basic $(echo -n "${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}" | base64)" --to registry.gitlab.com/
`
Usage: containerify [options]
Options:
--from
--to
--fromImage
--toImage
--folder
--file
--doCrossMount Optional: Cross mount image layers from the base image (only works if fromImage and toImage are in the same registry) (default: false)
--fromRegistry
--fromToken
--toRegistry
--optimisticToRegistryCheck Treat redirects as layer existing in remote registry. Potentially unsafe, but can save bandwidth.
--toToken
--toTar
--toDocker Optional: Export to local docker registry
--registry
--platform
--token
--user
--workdir
--entrypoint
--label, --labels
--env, --envs
--setTimeStamp
--preserveTimeStamp Optional: Preserve timestamps on files in the added layers. This might help with cache invalidation.
--verbose Verbose logging
--allowInsecureRegistries Allow insecure registries (with self-signed/untrusted cert)
--allowNoPushAuth Allow pushing images without authentication/token if the registry allows it
--customContent
local-path:absolute-container-path if you want to place it in a specific location
--extraContent
--layerOwner
--buildFolder
--layerCacheFolder
--version Get containerify version
-h, --help display help for command
`
Everything in the specified folder (--folder) is currently added to the image. It adds one layer with package.json, package-lock.json and node_modules and then a separate layer with the rest.
You may want to prune dev-dependencies and remove any unwanted files before running containerify`.