- Notifications
You must be signed in to change notification settings - Fork0
This project was created for educational purposes to practice working with Docker. It demonstrates how to set up a Node.js application using Docker, and includes a Makefile for easy management of Docker commands. Below is an explanation of each component in the project.
NotificationsYou must be signed in to change notification settings
KaplunMaxym/DockerDocs
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This project is designed for educational purposes to practice working with Docker. It demonstrates how to set up a Node.js application using Docker, and includes a Makefile for easy management of Docker commands. Below is an explanation of each component in the project.
FROM nodeWORKDIR /appCOPY package.json /appRUN npm installCOPY . .ENV PORT 4200EXPOSE $PORTVOLUME ["/app/data"]CMD ["node","main.js"]
The Dockerfile contains the instructions to build a Docker image for the Node.js application. Here is a breakdown of each command:
FROM nodeThis line specifies the base image for the Docker image. The node image includes Node.js and npm pre-installed.
WORKDIR /appThis command sets the working directory inside the container to /app. All subsequent commands will be run in this directory.
COPY package.json /appThis line copies the package.json file from the host machine to the /app directory in the container. This file contains the dependencies required for the Node.js application.
RUN npm installThis command runs npm install inside the container to install the dependencies listed in the package.json file.
COPY . .This line copies all files from the current directory on the host machine to the /app directory in the container.
ENV PORT 4200This command sets an environment variable PORT inside the container to 4200. The application will use this port to listen for incoming requests.
EXPOSE $PORTThis line informs Docker that the container will listen on the specified port (4200). This is used for documentation purposes and doesn't actually publish the port.
VOLUME ["/app/data"]
This command creates a volume at /app/data inside the container. Volumes are used to persist data generated by and used by Docker containers.
CMD ["node","main.js"]
This command specifies the default command to run when the container starts. It runs the Node.js application by executing node main.js.
node_modules.idea.gitDockerfilenode_modules: This directory contains local Node.js dependencies and should not be included in the Docker image.
create_image:docker build -t node_docker:env.run:docker run -d -p 3000:4200 -v logs:/app/data --env-file .env --rm --name node_docker node_docker:envrun_dev:docker run -d -p 3000:4200 -v$(shell pwd):/app -v /app/node_modules --env-file .env --rm --name node_docker node_docker:envrun_dev_nodemon:docker run -d -p 3000:4200 -v$(shell pwd):/app -v /app/node_modules --env-file .env --rm --name node_docker --entrypoint"npx" node_docker:env nodemon main.jsstop:docker stop node_docker
The Makefile defines a set of commands to manage Docker operations. Here is an explanation of each command:
create_image:docker build -t node_docker:env.
create_image: This target builds the Docker image with the tag node_docker:env using the Dockerfile in the current directory (.).
run:docker run -d -p 3000:4200 -v logs:/app/data --env-file .env --rm --name node_docker node_docker:envrun: This target runs the Docker container in detached mode (-d), mapping port 3000 on the host to port 4200 in the container (-p 3000:4200). It also mounts the logs volume to /app/data inside the container and loads environment variables from the .env file. The container is named node_docker and will be removed automatically when stopped (--rm).
run_dev:docker run -d -p 3000:4200 -v$(shell pwd):/app -v /app/node_modules --env-file .env --rm --name node_docker node_docker:env
run_dev: This target runs the Docker container in development mode. It mounts the current directory ($(shell pwd)) to /app inside the container, allowing live editing of files. It also mounts a volume for node_modules to use local dependencies. The rest of the parameters are the same as the run target.
run_dev_nodemon:docker run -d -p 3000:4200 -v$(shell pwd):/app -v /app/node_modules --env-file .env --rm --name node_docker --entrypoint"npx" node_docker:env nodemon main.js
run_dev_nodemon: This target runs the Docker container in development mode with nodemon to automatically restart the server on file changes. It overrides the default entry point to use npx nodemon main.js.
stop:docker stop node_dockerVolumes are used to persist data generated by and used by Docker containers. In this project, there are both named and anonymous volumes:
- -v logs:/app/data: This command creates a named volume called logs and mounts it to /app/data in the container. This is useful for persisting log data.
- -v $(shell pwd):/app: This command mounts the current directory on the host machine to /app in the container. This allows for live editing of files during development.
- -v /app/node_modules: This command mounts an anonymous volume for the node_modules directory, preventing local node_modules from being overwritten in the container.
About
This project was created for educational purposes to practice working with Docker. It demonstrates how to set up a Node.js application using Docker, and includes a Makefile for easy management of Docker commands. Below is an explanation of each component in the project.
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.



