This repository contains implementation of docker images and container for learning purpose and is sepecially designed for the docker-based implemnentation of Node JS, such that there is separate docker for the frontend, backend and a data volume for the MangoDB.
The backend directory contains a collection of Dockerfiles for learning how to build Docker images for backend applications.
The frontend directory contains a collection of Dockerfiles for learning how to build Docker images for frontend applications.
The fullstack directory contains a collection of Dockerfiles for learning how to build Docker images for fullstack Node JS applications.
Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package. By doing so, thanks to the container, the developer can rest assured that the application will run on any other machine regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code.
Dockerfiles are a set of instructions that Docker reads and executes in order to build a Docker image. Docker images are read-only templates that contain a set of instructions for creating a Docker container. Docker containers are run-time instances of Docker images.
Dockerfile commands are used to build Docker images. The following is a list of the most commonly used Dockerfile commands:
FROM- Sets the Base Image for subsequent instructions.RUN- Executes commands in a new layer on top of the current image and commits the results.CMD- Provides defaults for an executing container.LABEL- Adds metadata to an image.EXPOSE- Informs Docker that the container listens on the specified network ports at runtime.ENV- Sets the environment variable.ADD- Copies new files, directories or remote file URLs from<src>and adds them to the filesystem of the image at the path<dest>.COPY- Copies new files or directories from<src>and adds them to the filesystem of the container at the path<dest>.ENTRYPOINT- Configures a container that will run as an executable.VOLUME- Creates a mount point with the specified name and marks it as holding externally mounted volumes from native host or other containers.USER- Sets the user name for following RUN / CMD / ENTRYPOINT commands.WORKDIR- Sets the working directory.ARG- Defines a variable that users can pass at build-time to the builder with the docker build command using the--build-arg <varname>=<value>flag.ONBUILD- Adds a trigger instruction to an image. The trigger will be executed at a later time, when the image is used as the base for another build.
The following is a list of best practices for writing Dockerfiles:
- Use only one
RUNcommand perDockerfileinstruction. - Use
COPYinstead ofADDfor files and directories. - Use
CMDinstead ofENTRYPOINTfor running applications. - Use
ENTRYPOINTfor running commands that need to be run before the application is started. - Use
EXPOSEto document which ports are used by the container. - Use
VOLUMEto document which volumes are used by the container. - Use
ENVto set environment variables. - Use
ARGto set build-time variables. - Use
LABELto add metadata to an image. - Use
USERto run the process as a non-root user. - Use
WORKDIRto set the working directory. - Use
HEALTHCHECKto check that the container is still working. - Use
SHELLto change the default shell. - Use
--chownflag to avoid permission issues.
- Docker for Developers on LinkedIn Learning
- Docker Essentials: A Developer Introduction on Cognitive class AI