docker build constructs a container image from a Dockerfile and its build context. It turns repeatable setup steps—copying application files, installing dependencies, setting permissions, and choosing a startup command—into a portable image. section 5.4.2
Build and run a Node.js image with a tagged name:
- Build it: docker build -t rk8s-js -f Dockerfile . section 5.4.2
- Run it: docker run -p 3000:3000 rk8s-js. section 5.4.2
- Override settings when running: docker run -p 3002:3000 -e MESSAGE="Hello World" rk8s-js. section 5.4.2
Listing 5.13 Node.js Dockerfile
# Using the official Node.js image for the LTS version FROM node:18.17.0 # Set our app's working directory WORKDIR /app # copy the primary source code COPY ./src /app/src/ # copy the package.json and package-lock.json to # ensure we use the same dependencies COPY package.json /app/ COPY package-lock.json /app/ # copy the entrypoint.sh for running the app COPY conf/entrypoint.sh /app/ # install dependencies RUN npm install # make the entrypoint.sh executable RUN chmod +x entrypoint.sh # run our app CMD ["./entrypoint.sh"]
Inspect the Dockerfile behind the build: it selects Node.js 18.17.0, copies source and lockfiles, installs dependencies, and defines the entrypoint. section 5.4.2
Build for different environments
Use separate Dockerfiles and tags for development, staging, and production: docker build -f Dockerfile.prod -t my-container:prod . Registry-bound images need valid tags, typically including a username, repository name, and tag. section 7.2.1 section 5.5



