liveBook · Manning

Container image

As explained in Essential TypeScript 5, Third Edition

A Docker image is an immutable package containing the files, metadata, and configuration needed to create a Docker container.

A container image is an immutable package and template for creating containers. It combines application files, configuration, metadata, and the packages needed to run the application. section 17.5.3 section 17.6

A Dockerfile defines what the image contains and how a container starts:

  • Selects a Node.js base image. section 17.5.3
  • Copies compiled application files, data, server code, and the deployment package manifest. section 19.4.2
  • Installs the NPM packages required at deployment time. section 21.5.2
  • Declares the application port and the command used to start the server. section 17.5.3
  • Excludes unnecessary files such as node_modules through .dockerignore, reducing processing time. section 19.4.2

Build and run an image

From an application folder containing Dockerfile, build a named image with docker build . -t webapp -f Dockerfile. Create and start a container with docker run -p 4000:4000 webapp, then test it at http://localhost:4000. Use docker ps to find running containers and docker stop with the container ID to stop one. section 17.5.3 section 17.5.4

Listing 17.21 The contents of the Dockerfile file in the webapp folder
FROM node:18.14.0

RUN mkdir -p /usr/src/webapp

COPY dist /usr/src/webapp/dist
COPY assets /usr/src/webapp/assets

COPY data.json /usr/src/webapp/
COPY server.js /usr/src/webapp/
COPY deploy-package.json /usr/src/webapp/package.json

WORKDIR /usr/src/webapp

RUN echo 'package-lock=false' >> .npmrc
RUN npm install

EXPOSE 4000

CMD ["node", "server.js"]

Inspect a complete Dockerfile showing the base image, copied files, dependency installation, exposed port, and startup command. section 17.5.3

How Essential TypeScript 5, Third Edition covers it

How deep it goes
Explains image construction through Dockerfile instructions, file exclusion, dependency installation, execution, and stopping, without detailing image internals.
Examples
Uses webapp, Angular, and React application images with Dockerfiles, build commands, port mappings, and browser tests.
What it assumes
Assumes a prepared compiled web application and deployment package, while demonstrating Dockerfile and .dockerignore setup.
What you can do after
Operate/configure Docker to build a named image, run it as a container, test its mapped port, list containers, and stop execution.
How it connects
Connects Dockerfile, base image, container, .dockerignore, Node.js, NPM packages, and application deployment.

Also explained in

Compare how 25 books explain container image →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Essential TypeScript 5, Third Edition. The section links point to the parts of the book it draws on.