This is a test app created while learning docker
147
This Docker image includes a Node.js app that connects to MongoDB, along with a mongodb.yaml file for setting up the database.
docker pull akash26052005/docker-testapp:latest
mongodb.yaml FileSince 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.
Now, use the extracted mongodb.yaml to run MongoDB:
docker-compose -f mongodb.yaml up -d
This will:
mongo service) on port 27017mongo-express service) on port 8081Now, start the Node.js container:
docker run -p 5050:5050 --name testapp --network app-network -d akash26052005/docker-testapp:latest
Why --network app-network?
--network app-network ensures that the app can find MongoDB at mongo:27017.http://localhost:5050http://localhost:8081Retrieve all users from MongoDB.
curl http://localhost:5050/getUsers
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
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
Check running containers:
docker ps
View logs for the Node.js App:
docker logs testapp
View logs for MongoDB:
docker logs mongodb
If you update the app, rebuild and push the image:
docker build -t akash26052005/docker-testapp:<tag> .
docker push akash26052005/docker-testapp:<tag>
This project is open-source and available for use.
Content type
Image
Digest
sha256:c627293e2…
Size
393 MB
Last updated
over 1 year ago
docker pull akash26052005/docker-testapp