Docker

Useful commands

Build Image

docker build . -t $TAG

# no cache: --no-cache
# build args (like env vars): --build-arg NPM_TOKEN=$NPM_TOKEN

With file in monorepo:

docker build -t $TAG -f $FILE --build-arg NAME=value .

Check size

# save image
docker save $NAME -o $OUTPUT_FILE.tar

# login to image and run the following:
# root
du -h -s app/ bin/ dev/ etc/ home/ lib/ lib64/ media/ opt/ run/ sbin/ srv/ sys/ tmp/ usr/ var/

# usr
du -h -s bin/ include/ lib libexec/ local/ sbin/ share/

# app
du -h -s apps/ node_modules/ packages/

# by size
du -h | sort -h

Check vulnerabilities

Run Image

Monitoring

Clean up (more here)

Navigate docker image

Stop all running containers

Remove all containers

Dockerfile Best Practices

Use the right Node base image: https://snyk.io/blog/choosing-the-best-node-js-docker-image/

dockerfile best practices

Using dumb-init

Avoid calling npm, use instead:

Non user example:

Docker Compose

Local build:

Last updated