{"id":22341780,"url":"https://github.com/weaponsforge/nodeapp","last_synced_at":"2025-09-01T20:07:30.325Z","repository":{"id":126828540,"uuid":"317105735","full_name":"weaponsforge/nodeapp","owner":"weaponsforge","description":"Basic nodejs webapp for Docker testing.","archived":false,"fork":false,"pushed_at":"2020-11-30T20:11:29.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-01T20:07:22.448Z","etag":null,"topics":["devops","docker"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/weaponsforge.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":"2020-11-30T03:57:33.000Z","updated_at":"2020-11-30T20:11:31.000Z","dependencies_parsed_at":"2023-06-18T06:00:26.818Z","dependency_job_id":null,"html_url":"https://github.com/weaponsforge/nodeapp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/weaponsforge/nodeapp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weaponsforge%2Fnodeapp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weaponsforge%2Fnodeapp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weaponsforge%2Fnodeapp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weaponsforge%2Fnodeapp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weaponsforge","download_url":"https://codeload.github.com/weaponsforge/nodeapp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weaponsforge%2Fnodeapp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273183228,"owners_count":25059812,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-01T02:00:09.058Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["devops","docker"],"created_at":"2024-12-04T08:08:12.707Z","updated_at":"2025-09-01T20:07:30.296Z","avatar_url":"https://github.com/weaponsforge.png","language":"JavaScript","readme":"## Information\r\n\r\nThe following notes describe how to install **docker** on CentOS 8 running on a VM (Virtual Box), which can be optional. It also discusses how to dockerize a nodejs webapp.\r\n\r\n## Content\r\n\r\n- [Prerequisites](#prerequisites)\r\n- [Docker Installation](#docker-installation)\r\n- [Docker Post Installation](#post-installation)\r\n- [Install Docker Compose (Optional)](#install-docker-compose-optional)\r\n- [Dockerize a NodeJS Web App](#dockerize-a-nodejs-web-app)\r\n- [Run a NodeJS Web App Inside a Docker Container](#run-a-nodejs-web-app-inside-a-docker-container)\r\n- [Common Docker Commands](#common-docker-commands)\r\n\t- [Images](#images)\r\n\t- [Containers](#containers)\r\n- [References](#references)\r\n\r\n## Prerequisites\r\n\r\n\u003e See the related tutorials on [**Virtual Box - CentOS 8**](https://trello.com/c/yj4wPomj) for more information on setting up CentOS on VirtualBox.\r\n\r\n1. (Optional) Virtual Box 6.14\r\n2. CentOS 8.1\r\n\r\n## Docker Installation\r\n\r\n1. Update your system.  \r\n`sudo dnf update -y`\r\n2. Add Docker CE yum repository using dnf command.  \r\n`sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo`\r\n3. Build cache for Docker yum repository.  \r\n`sudo dnf makecache`\r\n4. Docker CE requires containerd.io-1.2.2-3 (or later) package, which is blocked in CentOS 8. Therefore, we have to use an earlier version of containerd.io package. Install docker-ce with an earlier version of containerd.io using following command.  \r\n`sudo dnf -y install --nobest docker-ce --alowerasing`\r\n5. Enable and start Docker service.  \r\n`systemctl enable --now docker.service`\r\n6. Check status of Docker service.  \r\n`systemctl status docker.service`\r\n7. Check Docker version.  \r\n`docker version`\r\n8. Verify that docker runs.  \r\n`docker run hello-world`\r\n9. View the list of docker containers.  \r\n`docker container ls -a`\r\n10. Stop and remove a docker container.\r\n   - Get its `CONTAINER ID/s` from step #8.\r\n   - Run: `docker container rm \u003cCONTAINER_ID\u003e \u003cCONTAINER_ID_2\u003e ...`\r\n\r\n## Docker Post Installation\r\n\r\n1. Add your user to the docker group.  \r\n\r\n\t\tsudo usermod -aG docker $USER\r\n\t\tid $USER\r\n\r\n2. Disable firewalld on CentOS 8  \r\n`sudo systemctl disable firewalld`\r\n3. Reboot system.  \r\n`sudo shutdown -r now`\r\n4. Test: Pull the Alpine Linux image from Docker Hub.  \r\n\r\n\t\tdocker search alpine --filter is-official=true\r\n\t\tdocker pull alpine\r\n\r\n4. List the locally available docker images.  \r\n`docker images`\r\n5. Create and run a container using Alpine Linux image.  \r\n\r\n\t\tdocker run -it --rm alpine /bin/sh\r\n\t\tapk update\r\n\r\n\r\n## Install Docker Compose (Optional)\r\n\r\n1. Download and install the latest **docker-compose** from Github. Refer to the list of latest releases [here](https://github.com/docker/compose/releases).\r\n\r\n\t\tsudo curl -L https://github.com/docker/compose/releases/download/1.25.1-rc1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose\r\n\r\n2. Grant execute permissions to **docker-compose**.  \r\n`chmod +x /usr/local/bin/docker-compose`\r\n3. Check **docker-compose** version.  \r\n`docker-compose version`\r\n\r\n\r\n## Dockerize a NodeJS Web App\r\n\r\n1. Create a basic express nodejs app. For reference, use the [**nodeapp**](https://github.com/weaponsforge/nodeapp) repository. The demo project has a folder structure as follows:  \r\n\r\n\t\t[+] nodeapp\r\n\t\t  [+] app\r\n\t\t     [+] public\r\n\t\t         [-] index.html\r\n\t\t     [-] server.js\r\n\t\t  [-] Dockerfile\r\n\t\t  [-] .dockerignore\r\n\t\t  [-] package.json\r\n\t\t  [-] package-lock.json\r\n\r\n2. Create a `Dockerfile` file inside the project repository with the following content.  \r\n\r\n\t\tFROM node:12\r\n\t\t# app directory\r\n\t\tWORKDIR /usr/src/app\r\n\t\t# Install dependencies\r\n\t\tCOPY package*.json ./\r\n\t\tRUN npm install\r\n\t\t# Bundle app source\r\n\t\tCOPY ./app ./app\r\n\t\tEXPOSE 3000\r\n\t\tCMD [\"node\", \"app/server.js\"]\r\n\r\n3. Create a `.dockerignore` file inside the project repository with the following content.  \r\n\r\n\t\tnode_modules\r\n\t\tnpm-debug.log\r\n\r\n\r\n## Run a NodeJS Web App Inside a Docker Container\r\n\r\n1. Clone this git repository, or create a working [nodejs web app directory set-up for Docker](#dockerize-a-nodejs-web-app).  \r\n`git clone https://github.com/weaponsforge/nodeapp.git`\r\n2. **cd** into the directory.  \r\n`cd nodeapp`\r\n3. Build the docker image locally.  \r\n`docker build -t nodeapp .`\r\n4. Confirm that the image is listed by docker.  \r\n`docker images`\r\n5. Run the image in detached mode using any of the (2) options. The 1st one is the most recommended option. \r\n   - The following command maps the app's src directory from the host to the container's WORKDIR. This allows editing of the app's source files without needing to rebuild the nodeapp image.  \r\n\r\n\t\t\t# docker run -it -v \u003cAPP_ROOT_DIR\u003e:/\u003cCONTAINER_WORKDIR\u003e\r\n\t\t\t# APP_ROOT_DIR=project's root dir on the HOST machine, i.e. /home/ubuntu/nodeapp\r\n\t\t\t# CONTAINER_WORKDIR=WORKDIR defined in the Dockerfile, where the app's source codes will be deployed in the container\r\n\t\t\tdocker run -it -v $(pwd):/usr/src/app -p 49160:3000 -d nodeapp\r\n\r\n\t- The following command makes the container's local port **3000** accessible to the host machine as port **49160**.  \r\n`docker run -p 49160:3000 -d nodeapp`\r\n6. Print the output of your app.\r\n   - Get the container id: `docker ps`\r\n   - Print the app output: `docker logs \u003cCONTAINER_ID\u003e`\r\n7. Go inside the running container from another terminal.  \r\n`docker exec -it \u003cCONTAINER_ID\u003e /bin/bash`\r\n8. Verify the port mapping from inside the container (3000) to your machine's port (49160).  \r\n`docker ps`\r\n9. Test if the app can be called outside using **curl**, or load the website from a web browser.  \r\n`curl -i localhost:49160`\r\n10. Stop the running container/s.\r\n\t- (stop 1) `docker container stop \u003cCONTAINER_ID\u003e`\r\n\t- (stop all) `docker container stop $(docker container ls -aq)`\r\n11. Remove a container. Note: The container should first be stopped before it is removed. \r\n\t- `docker container rm \u003cCONTAINER_ID\u003e`\r\n\t- `docker container rm \u003cCONTAINER_ID#1\u003e \u003cCONTAINER_ID#2\u003e ...`\r\n\r\n## Common Docker Commands\r\n\r\n### `Images`\r\n\r\n- **show the list of all installed docker images**  \r\n`docker images`\r\n- **delete docker image/s**  \r\n`docker image rm \u003cIMG_NAME#1\u003e \u003cIMG_NAME#2\u003e ...`\r\n\r\n\r\n### `Containers`\r\n\r\n- **show the list, status and CONTAINER ID of all installed docker containers**  \r\n`docker container ls -a`  \r\n- **show the list of active running containers**  \r\n`docker ps`\r\n- **create and run a docker container for an app** (with reference to a nodejs web app)  \r\n`docker run -it -v $(pwd):/usr/src/app -p 49160:3000 -d nodeapp`\r\n- **create and run a docker container for most apps**  \r\n\t- NOTE: Appropriate Dockerfile is required.\r\n\t- `docker run \u003cAPP_NAME\u003e`\r\n- **stop a running container**\r\n\t- get the target container's CONTAINER ID\r\n\t- `docker container stop \u003cCONTAINER_ID\u003e`\r\n- **stop all running containers**  \r\n`docker container stop $(docker container ls -aq)`\r\n- **remove a docker container**\r\n\t- first, stop the target container from running\r\n\t- `docker container rm \u003cCONTAINER_ID\u003e`\r\n- **remove all docker containers**\r\n\t- first, stop the target containers from running\r\n\t- get the target containers' CONTAINER ID's\r\n\t- `docker container rm \u003cCONTAINER_ID#1\u003e \u003cCONTAINER_ID#2\u003e ...)`\r\n\r\n## References\r\n\r\n[[1]](https://www.alibabacloud.com/blog/how-to-install-docker-ce-and-docker-compose-on-centos-8_595741) - install docker ce and docker-compose on centos 8  \r\n[[2]](https://phoenixnap.com/kb/how-to-install-docker-on-centos-8) - install docker on centos 8  \r\n[[3]](https://docs.docker.com/engine/install/centos/) - official docker installation on centos  \r\n[[4]](https://github.com/nodejs/docker-node/blob/master/docs/BestPractices.md) - docker and nodejs best practices  \r\n[[5]](https://hub.docker.com/_/node/) - nodejs official docker images  \r\n[[6]](https://trello.com/c/7WiCI60n) - trello notes\r\n\r\n@weaponsforge  \r\n20201130","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweaponsforge%2Fnodeapp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweaponsforge%2Fnodeapp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweaponsforge%2Fnodeapp/lists"}