Sign inSign up

akash26052005/docker-testapp

By akash26052005

•Updated over 1 year ago
Archived

This is a test app created while learning docker

Image
2

147

akash26052005/docker-testapp repository overview

⁠Docker Test App

This Docker image includes a Node.js app that connects to MongoDB, along with a mongodb.yaml file for setting up the database.


⁠🚀 How to Use This Image (With MongoDB)

⁠Step 1: Pull the Docker Image
docker pull akash26052005/docker-testapp:latest
⁠Step 2: Copy the mongodb.yaml File

Since mongodb.yaml is inside the container, you need to extract it to your local machine:

docker create --name temp-container akash26052005/docker-testapp:latest
docker cp temp-container:/testapp/mongodb.yaml ./mongodb.yaml
docker rm temp-container

This copies mongodb.yaml from the image to your local machine.

⁠Step 3: Start MongoDB Services

Now, use the extracted mongodb.yaml to run MongoDB:

docker-compose -f mongodb.yaml up -d

This will:

  • Start MongoDB (mongo service) on port 27017
  • Start Mongo Express (mongo-express service) on port 8081
⁠Step 4: Run the Node.js App

Now, start the Node.js container:

docker run -p 5050:5050 --name testapp --network app-network -d akash26052005/docker-testapp:latest

Why --network app-network?

  • The Node.js app must communicate with MongoDB, which is running in Docker Compose’s network.
  • Using --network app-network ensures that the app can find MongoDB at mongo:27017.

⁠📡 Access the Services

  • Node.js API → http://localhost:5050
  • Mongo Express UI → http://localhost:8081

⁠📌 API Endpoints

⁠GET All Users

Retrieve all users from MongoDB.

curl http://localhost:5050/getUsers
⁠POST New User

Add a new user to MongoDB.

curl -X POST -d "name=Akash&[email protected]" -H "Content-Type: application/x-www-form-urlencoded" http://localhost:5050/addUser

⁠🛑 Stopping & Removing Containers

To stop all services:

docker-compose -f mongodb.yaml down
docker stop testapp
docker rm testapp

To remove containers, volumes, and networks:

docker-compose -f mongodb.yaml down -v

⁠🛠️ Debugging & Logs

Check running containers:

docker ps

View logs for the Node.js App:

docker logs testapp

View logs for MongoDB:

docker logs mongodb

⁠📦 Building & Pushing a New Version (Collab)

If you update the app, rebuild and push the image:

docker build -t akash26052005/docker-testapp:<tag> .
docker push akash26052005/docker-testapp:<tag>

⁠📜 License

This project is open-source and available for use.

Tag summary

Content type

Image

Digest

sha256:c627293e2…

Size

393 MB

Last updated

over 1 year ago

docker pull akash26052005/docker-testapp