liveBook · Manning

Docker

As explained in Essential TypeScript 5, Third Edition

Docker is a platform and toolset for building, distributing, and running applications in software containers.

Docker packages an application into a container for production deployment. A container is a pared-down Linux environment with enough functionality to run the application, and Docker images provide templates for creating containers. section 17.5 section 17.5.3

A typical web application container uses a Dockerfile to select a Node.js base image, copy the deployment files, install NPM packages, expose the application port, and define the startup command. section 17.5.3

A practical containerization workflow is:

  • Install Docker on macOS, Windows, or Linux; the free edition is sufficient for the examples. section 17.5.1
  • Add a Dockerfile and a .dockerignore file to the application folder; excluding node_modules reduces processing time. section 17.5.3
  • Start the image with docker run -p 4000:4000 webapp, test it at localhost:4000, inspect it with docker ps, and stop it with docker stop. section 17.5.4

Minimal web application container

A deployment Dockerfile can start with FROM node:18.14.0, copy dist, assets, data.json, server.js, and deploy-package.json into /usr/src/webapp, run npm install, expose port 4000, and start server.js with CMD ["node", "server.js"].

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 the complete Dockerfile, including its base image, copied files, working directory, package installation, exposed port, and startup command. section 17.5.3

Listing 17.24 Starting the Docker container
docker run -p 4000:4000 webapp

Inspect the command that creates a running container and maps its internal port to localhost. section 17.5.4

How Essential TypeScript 5, Third Edition covers it

How deep it goes
Explains image construction and container lifecycle through Dockerfiles and commands, but does not detail Docker internals.
Examples
Uses standalone, Angular, and React web applications with Dockerfiles, port mappings, localhost tests, and container stop commands.
What it assumes
Assumes a prepared web application and Docker installation, while introducing Dockerfile-based packaging from the deployment workflow.
What you can do after
Operate/configure Docker to build images, run mapped-port containers, test applications locally, inspect running containers, and stop them.
How it connects
Connects containers and images with Dockerfiles, Node.js, NPM packages, TypeScript compilation, and web application deployment.

Also explained in

Compare how 26 books explain Docker →

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.