🐳 Docker
22 Sep, 2022
👋 FYI, this note is over 6 months old. Some of the content may be out of date.
On this page
Best practices Jump to heading
Dockerfile examples Jump to heading
FROM node:12.4.0-alpine
ENV NPM_CONFIG_LOGLEVEL info
WORKDIR /usr/src/app
EXPOSE 8080
ENTRYPOINT ["yarn", "start"]
RUN mkdir -p /usr/src/app
COPY . .
RUN yarn install && \
yarn build && \
yarn test && \
yarn install --production && \
rm -rf .git
Build a Dockerfile locally Jump to heading
docker build .
# or
docker build -t yourTagName .
Run a Dockerfile locally Jump to heading
docker run -p 1717:1717 yourTagName
Docker commands Jump to heading
# list all running containers
docker ps
# stop/remove particular running container
docker rm -f $containerId
# stop all containers
docker rm -f (docker ps -aq)
# browse running container files
docker exec -it $containerId sh
Using private npm packages Jump to heading
Securely using .npmrc files in Docker images
Here’s an example of the above
# Multi-stage build info & npm security
# from https://www.alexandraulsh.com/2018/06/25/docker-npmrc-security/
# First build
FROM node:13.2.0 AS build
ENV NPM_CONFIG_LOGLEVEL info
WORKDIR /usr/src/app
ARG NPM_TOKEN
RUN mkdir -p /usr/src/app
COPY . .
RUN echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc && \
yarn install && \
yarn build && \
yarn test && \
yarn storybook:build && \
yarn install --production && \
rm -f .npmrc \
rm -rf .git
# Second build
FROM node:13.2.0-alpine
WORKDIR /usr/src/app
EXPOSE 8080
COPY /usr/src/app .
ENTRYPOINT ["yarn", "start"]
Then you would run the build like so:
docker build -t mrmartineau/${CIRCLE_PROJECT_REPONAME}:${CIRCLE_SHA1} \
+ --build-arg NPM_TOKEN=${NPM_TOKEN} \
The above extract is from one project’s CircleCI config.
This is how you would run it locally
docker build . -f dockerfile -t kiss --build-arg NPM_TOKEN=9e012519-aba7-4372-8381-abcdefghi
Security Jump to heading
https://cloudberry.engineering/article/dockerfile-security-best-practices/
Hacker News comments for the above article: https://news.ycombinator.com/item?id=24776771
Using Docker on a Mac Jump to heading
- Rancher Desktop (https://rancherdesktop.io/)
- Using Rancher Desktop as Docker Desktop replacement on macOS - Daniel’s Tech Blog
- Podman Desktop
- Colima (CLI tool) - Container runtimes on macOS (and Linux) with minimal setup
- Portainer (Web-based) Docker and Kubernetes Management
← Back home