{"id":19140923,"url":"https://github.com/fakhranii/docker-with-nodejs","last_synced_at":"2026-03-01T14:32:48.087Z","repository":{"id":254597821,"uuid":"846282125","full_name":"fakhranii/docker-with-nodejs","owner":"fakhranii","description":"A nodejs application which deals with docker-compose \u0026 Dockerfile","archived":false,"fork":false,"pushed_at":"2024-09-10T12:41:00.000Z","size":127,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-06T23:17:15.149Z","etag":null,"topics":["docker","docker-compose","dockerf","mongodb","mongoose","nodejs","pg","postgresql"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fakhranii.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-22T22:15:38.000Z","updated_at":"2024-09-10T12:44:13.000Z","dependencies_parsed_at":"2024-09-10T14:10:01.460Z","dependency_job_id":"459a3fc6-9d35-4a67-848b-6b4ff7721e40","html_url":"https://github.com/fakhranii/docker-with-nodejs","commit_stats":null,"previous_names":["fakhranyy/docker-with-nodejs","fakhranii/docker-with-nodejs"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fakhranii/docker-with-nodejs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fakhranii%2Fdocker-with-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fakhranii%2Fdocker-with-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fakhranii%2Fdocker-with-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fakhranii%2Fdocker-with-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fakhranii","download_url":"https://codeload.github.com/fakhranii/docker-with-nodejs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fakhranii%2Fdocker-with-nodejs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29970989,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T14:11:48.712Z","status":"ssl_error","status_checked_at":"2026-03-01T14:11:48.352Z","response_time":124,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","docker-compose","dockerf","mongodb","mongoose","nodejs","pg","postgresql"],"created_at":"2024-11-09T07:19:21.964Z","updated_at":"2026-03-01T14:32:48.068Z","avatar_url":"https://github.com/fakhranii.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ⭐ This Repo Is About Mastering Docker ⭐\n\n## Table of Contents\n\n1. [Start With Docker](#start-with-docker)\n2. [How To Write Instructions In Dockerfile](#how-to-write-instructions-in-dockerfile)\n3. [How to Deal With Docker Via Terminal Commands](#how-to-deal-with-docker-via-terminal-commands)\n4. [Dockerfile Commands](#dockerfile-commands)\n5. [Docker Compose](#docker-compose)\n   - [Common Docker Compose Commands](#common-docker-compose-commands)\n6. [Difference Between Images \u0026 Containers](#difference-between-images--containers)\n   - [Docker Images](#docker-images)\n   - [Docker Containers](#docker-containers)\n   - [Key Differences](#key-differences)\n\n---\n\n## _Start With Docker_\n\n- **The first step to start with docker is create file named `Dockerfile`.**\n- **There is a helpful extension in vsc called `Docker` you have to install it, it will help you engage with docker.**\n- **Once you did create an `image` you can create `container` from it.**\n\n---\n\n## _How To write Instructions In Dockerfile_\n\n- **At the first `Dockerfile` is just a file to write some instructions in it, to tell `docker` how to works!, what dependencies are required in our application, how to build the application, how to run the application.**\n- **`Container` is the output of running `Dockerfile`.**\n- **People usually start the `Dockerfile` with this line ➡ `FROM baseImage`, `baseImage` is the thing that will give me the dependencies which my application requires, and the `baseImage` in our app is `node` so in our case we'll write `FROM node` we replaced `baseImage` with the image name which is `node` .**\n- **if i wrote only `FROM node` it will give me the latest version of `node`, and i wanna specific version i should write `FROM node:14` for example.**\n- **To create a `folder` inside `Dockerfile` we'll use this keyword ➡ `WORKDIR /name`.**\n- **To copy a file content we'll use the keyword `COPY source dest` .. the source is the place we'll take the copy from and the dest is the place we'll past the copy in.**\n- **To run a command inside `Dockerfile` ➡ `RUN command` and replace the command keyword with the command you wanna run.**\n- **`EXPOSE` Define the network ports that this container will listen on at runtime .. for example `EXPOSE 3000` , its just for documentation ..**\n\n---\n\n## _How to Deal With `Docker` Via Terminal Commands_\n\n- **`docker version`: Displays the Docker version installed.**\n\n- **`docker info`: Shows detailed information about the Docker installation.**\n\n- **`docker pull \u003cimage\u003e`: Downloads a Docker image from a registry.**\n\n- **`docker build -t \u003cname\u003e \u003cpath\u003e`: Builds a Docker image from a Dockerfile in the specified path.**\n\n- **`docker images`: Lists all Docker images on the local system.**\n\n- **`docker rmi \u003cimage\u003e`: Removes a Docker image.**\n\n- **`docker tag \u003csource-image\u003e \u003ctarget-image\u003e`: Tags an image for easy reference.**\n\n- **`docker run \u003cimage\u003e`: Runs a command in a new container.**\n\n- **`docker run --name express-container -v d:\\programming\\projects\\local-projects\\nodejs-docker-app/src:/app/src:ro -d -p 4000:4000 node-docker-dev`: Create a container that listen to changes at `src` folder and make hot reload at the container to reload any change happened at `src` folder.**\n\n- **`docker run --name containerName -v fullPathOfTheMainFile Or %cd%:/folderNameInDockerfile -d -p 4000:4000 node-docker-dev`: This is an instance of create a hot reload container, for example ➡ `docker run --name express-container -v d:\\programming\\projects\\local-projects\\nodejs-docker-app:/app:ro -d -p 4000:4000 node-docker-dev.`, And remember to set `start:dev` script in `package.json` to ➡ `nodemon --legacy-watch src/index.ts` and we put this option `:ro` to make the container `read-only`**\n\n- **`docker run --name dockerName -v  fullPathOfTheMainFile Or %cd%:/folderNameInDockerfile -v specifyFolderOrFileIdidnotWannaChangeAnythingAtIt(/app/node_modules) -d -p 4000:4000 node-docker-dev`: Creates a new container with anonymous volume, That's mean it'll keep the `docker container` without any change, And if there's changes at local machine won't influnce at the `docker container`.**\n\n- **`docker run -d \u003cimage\u003e`: Runs a container in detached mode (in the background).**\n\n- **`docker run -it \u003cimage\u003e`: Runs a container interactively with a terminal.**\n\n- **`docker run --name \u003ccontainer-name\u003e \u003cimage\u003e`: Runs a container with a specified name.**\n\n- **`docker ps`: Lists all running containers.**\n\n- **`docker ps -a`: Lists all containers, including stopped ones.**\n\n- **`docker stop \u003ccontainer\u003e`: Stops a running container.**\n\n- **`docker start \u003ccontainer\u003e`: Starts a stopped container.**\n\n- **`docker restart \u003ccontainer\u003e`: Restarts a container.**\n\n- **`docker kill \u003ccontainer\u003e`: Kills a running container.**\n\n- **`docker rm \u003ccontainer\u003e`: Removes a container.**\n\n- **`docker rm \u003ccontainer\u003e -f`: Forces Remove a container .**\n\n- **`docker exec -it \u003ccontainer\u003e \u003ccommand\u003e`: Runs a command in a running container (interactive).**\n\n- **`docker logs \u003ccontainer\u003e`: Shows the logs from a container.**\n\n- **`docker inspect \u003ccontainer\u003e`: Displays detailed information about a container or image.**\n\n- **`docker commit \u003ccontainer\u003e \u003cnew-image-name\u003e`: Creates a new image from a container's changes.**\n\n- **`docker attach \u003ccontainer\u003e`: Attaches to a running container's console.**\n\n- **`docker volume create \u003cvolume-name\u003e`: Creates a new volume.**\n\n- **`docker volume ls`: Lists all volumes.**\n\n- **`docker volume rm \u003cvolume-name\u003e`: Removes a volume.**\n\n- **`docker volume inspect \u003cvolume-name\u003e`: Displays detailed information about a volume.**\n\n- **`docker network create \u003cnetwork-name\u003e`: Creates a new network.**\n\n- **`docker network ls`: Lists all Docker networks.**\n\n- **`docker network rm \u003cnetwork-name\u003e`: Removes a Docker network.**\n\n- **`docker network inspect \u003cnetwork-name\u003e`: Displays detailed information about a network.**\n\n- **`docker network connect \u003cnetwork\u003e \u003ccontainer\u003e`: Connects a container to a network.**\n\n- **`docker network disconnect \u003cnetwork\u003e \u003ccontainer\u003e`: Disconnects a container from a network.**\n\n- **`docker-compose up`: Builds, (re)creates, starts, and attaches to containers for a service.**\n\n- **`docker-compose up -d`: Starts containers in detached mode.**\n\n- **`docker-compose down`: Stops and removes containers, networks, images, and volumes.**\n\n- **`docker-compose ps`: Lists containers in the current Docker Compose project.**\n\n- **`docker-compose logs`: Shows logs from Docker Compose services.**\n\n- **`docker-compose build`: Builds or rebuilds services.**\n\n- **`docker-compose stop`: Stops running containers without removing them.**\n\n- **`docker-compose start`: Starts existing containers.**\n\n- **`docker-compose restart`: Restarts all the services defined in the docker-compose.yml.**\n\n- **`docker login`: Logs in to a Docker registry.**\n\n- **`docker logout`: Logs out from a Docker registry.**\n\n- **`docker push \u003cimage\u003e`: Uploads a local image to a Docker registry.**\n\n- **`docker pull \u003cimage\u003e`: Downloads an image from a Docker registry.**\n\n- **`docker system df`: Shows disk usage by Docker.**\n\n- **`docker system prune`: Cleans up unused Docker data (containers, images, networks, etc.).**\n\n- **`docker system info`: Displays system-wide information about Docker.**\n\n- **`docker stats`: Shows a live stream of resource usage statistics for containers.**\n\n- **`docker save -o \u003cfile-name.tar\u003e \u003cimage\u003e`: Saves an image to a tar archive.**\n\n- **`docker load -i \u003cfile-name.tar\u003e`: Loads an image from a tar archive.**\n\n### _Dockerfile Commands_\n\n- **First to build an image of Dockerfile ➡ `docker build .` it works in case if i'm in the folder which include the Dokerfile.**\n\n- **To name the Docker image to separate the iamges with names ➡ `docker build -t imageName .` .**\n\n- **To see list of all images in your device ➡ `docker image ls`.**\n\n- **To run the a container and name it, from `Docker Image` that we have ➡ `docker run --name containerName -p  forward port:internal port  imageName`.**\n\n- **To see list of all running containers in your device ➡ `docker ps`.**\n\n- **To stop container ➡ `docker stop containerName`.**\n\n- **To remove a container ➡ `docker rm containerName -f`.**\n\n- **`FROM \u003cimage\u003e`: Specifies the base image for the Docker image.**\n\n- **`LABEL \u003ckey\u003e=\u003cvalue\u003e`: Adds metadata to the image in the form of key-value pairs.**\n\n- **`ENV \u003ckey\u003e=\u003cvalue\u003e`: Sets environment variables within the image.**\n\n- **`RUN \u003ccommand\u003e`: Executes a command during the image build process, typically used for installing packages.**\n\n- **`COPY \u003csrc\u003e \u003cdest\u003e`: Copies files or directories from the host machine into the image.**\n\n- **`ADD \u003csrc\u003e \u003cdest\u003e`: Similar to `COPY`, but with additional features like auto-extracting compressed files.**\n\n- **`WORKDIR \u003cpath\u003e`: Sets the working directory for subsequent instructions in the Dockerfile.**\n\n- **`CMD [\"executable\", \"param1\", \"param2\"]`: Specifies the default command to run when a container is started.**\n\n- **`ENTRYPOINT [\"executable\", \"param1\", \"param2\"]`: Configures a container to run as an executable.**\n\n- **`EXPOSE \u003cport\u003e`: Informs Docker that the container listens on the specified network ports at runtime.**\n\n- **`VOLUME [\"/data\"]`: Creates a mount point with the specified path and marks it as holding externally mounted volumes or bind mounts.**\n\n- **`USER \u003cusername or UID\u003e`: Sets the user to use when running the image’s CMD or ENTRYPOINT.**\n\n- **`ARG \u003ckey\u003e[=\u003cdefault value\u003e]`: Defines a variable that users can pass at build-time to the builder with the docker build command.**\n\n- **`ONBUILD \u003ccommand\u003e`: Adds a trigger instruction to be executed when the image is used as a base for another build.**\n\n- **`HEALTHCHECK \u003coptions\u003e CMD \u003ccommand\u003e`: Defines a command that runs to check that the container is healthy.**\n\n- **`SHELL [\"executable\", \"param1\", \"param2\"]`: Allows the default shell used for the shell form of commands to be overridden.**\n\n---\n\n- ## _Docker Compose_\n\n- **The first step to use `Docker-Compose` is create file called `docker-compose.yml`.**\n\n- **If you wanna run docker in different enviroments, You should run docker-compose file for each enviroments.**\n\n- **When i had different `docker-compose` files and i wanna run specific file : `docker-compose -f dockerComposeFileName up`.**\n\n- **In case if we had many different `docker-compose` files like `dev | pord | stag`, we create a file called `docker-compose.yml` and write all common structure between files i it, then in those other files we write only what related with each of those specific files.**\n\n- **Ensure you don't forget to add this line `docker-compose*` in `.dockerignore` to avoid all `docker-compose` files to be included in the containers that we gonna create.**\n\n- **When i had different `docker-compose` files and `mainComposeFile` like `docker-compose.yml` and i wanna run specific file and the main docker-compose : `docker-compose -f docker-compose.yml -f docker-compose.dev.yml up` and if you want it build again the command will be `docker-compose -f docker-compose.yml -f docker-compose.dev.yml up --build -d`.**\n\n- **After adding any new image you have to build the new image before create any container.**\n\n### _Common Docker Compose Commands_\n\n- **`docker compose up`: Build, (re)create, start, and attach to containers for a service.**\n- **`docker compose down`: Stop and remove containers, networks, images, and volumes.**\n- **`docker compose build`: Build or rebuild services.**\n- **`docker compose stop`: Stop services.**\n- **`docker compose start`: Start services.**\n- **`docker compose restart`: Restart services.**\n- **`docker compose logs`: View output from containers.**\n- **`docker compose ps`: List containers.**\n- **`docker compose exec \u003cservice_name\u003e \u003ccommand\u003e`: Execute a command in a running container.**\n\n---\n\n## _Difference Between Images \u0026 Containers_\n\n### _Docker Images_\n\n- **`Definition`: A Docker image is a lightweight, standalone, and immutable file that contains everything needed to run a piece of software, including the code, runtime, libraries, environment variables, and configuration files..**\n- **`Read-Only`: Docker images are read-only templates used to create Docker containers. They do not change once they are created..**\n- **`Layered Structure`: Docker images are made up of layers. Each layer represents a set of file changes (like an addition or modification), and layers are stacked on top of each other to form a single image. This layering allows Docker to reuse layers between images, which makes them more efficient in terms of storage and speed.**\n- **`Storage`: Images are stored in the Docker registry (such as Docker Hub) or locally on your machine. They can be shared and distributed, making them highly portable.**\n- **`Creation`: Docker images are typically built from a Dockerfile, which is a script that specifies the instructions needed to create the image.**\n\n\u003c!-- - **.** --\u003e\n\n### _Docker Containers_\n\n- **`Definition`: A Docker container is a running instance of a Docker image. It is an isolated, lightweight, and executable software package that includes everything needed to run an application.**\n\n- **`Mutable`: Unlike images, containers are mutable. When you run a container, it is created from an image and can be modified. Any changes made inside a container, such as modifying files or installing software, are specific to that container instance.**\n\n- **`Runtime`: Containers provide a runtime environment where the application specified in the Docker image can be executed. They have their own isolated filesystem, network interfaces, and processes.**\n\n- **`Lifecycle`: Containers have a lifecycle—they can be started, stopped, restarted, and removed. Once a container is stopped, it can be restarted or removed without affecting the original image.**\n\n- **`Ephemeral`: Containers are often designed to be ephemeral, meaning they are created, used, and then discarded. Changes made to a container are not reflected back in the image unless explicitly committed to create a new image.**\n\n### _Key Differences_\n\n#### _Immutability vs. Mutability:_\n\n- **Images are immutable and cannot be changed once created.**\n- **Containers are mutable, and you can make changes to a running container.**\n\n#### _Role:_\n\n- **Images serve as the blueprint or template for creating containers.**\n- **Containers are the actual running instances of images.**\n\n#### _Storage:_\n\n- **Images are stored as layers in the Docker registry or locally and can be reused.**\n- **Containers use the image as a base and have their own writable layer where changes are made.**\n\n#### _Creation_:\n\n- **Images are built from Dockerfiles or created by committing changes from a container.**\n- **Containers are created from images and run the software specified in the image.**\n\n#### _Persistence_:\n\n- **Images are persistent and can be stored and distributed.**\n- **Containers are ephemeral by default, and changes made to them do not persist unless committed to an image or saved in volumes.**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffakhranii%2Fdocker-with-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffakhranii%2Fdocker-with-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffakhranii%2Fdocker-with-nodejs/lists"}