liveBook · Manning

Container

As explained in Essential TypeScript 5, Third Edition

A container is an isolated, lightweight execution environment that packages an application with the functionality it needs to run.

A container is an isolated, lightweight execution environment that packages an application with the functionality required to run it. Docker creates a pared-down Linux environment suitable for production deployment across supported hosting platforms. section 17.5

A typical Docker workflow packages and operates an application in a few steps:

  • Define the environment in a Dockerfile using a Node.js base image, application files, dependencies, a working directory, an exposed port, and a startup command. section 17.5.3
  • Exclude unnecessary files such as node_modules with .dockerignore to reduce processing time. section 17.5.3
  • Build an image with docker build; the image acts as a template containing copied code, configuration, and installed NPM packages. section 17.5.3
  • Start a container from the image, test the application through its mapped localhost port, inspect running containers with docker ps, and stop one with docker stop. section 17.5.4

Running a packaged web application

Build an image with `docker build . -t webapp -f Dockerfile`, then start it with `docker run -p 4000:4000 webapp`. Open `http://localhost:4000` to test the server, use `docker ps` to find its container ID, and stop it with `docker stop <container-id>`. 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"]

Use the Dockerfile listing to inspect how a Node.js base image, copied application artifacts, dependency installation, port exposure, and the server startup command form a container. section 17.5.3

How Essential TypeScript 5, Third Edition covers it

How deep it goes
Explains Dockerfile definition, image construction, port mapping, inspection, testing, and stopping, but not deeper container internals.
Examples
Demonstrates containerized web, Angular, and React applications using Dockerfiles, build commands, mapped ports, browser tests, and lifecycle commands.
What it assumes
Assumes a prepared application and requires Docker installation; teaches container definition and lifecycle operations through application examples.
What you can do after
Operate/configure a Docker image and container for a prepared Node.js application, including building, running, testing, inspecting, and stopping it.
How it connects
Connects containers with Docker, Dockerfile, Docker images, Node.js, NPM packages, and production deployment.

Also explained in

Compare how 27 books explain container →

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.