Please follow below steps to Debug Docker container:
1. Check the logs of the MongoDB container:
docker logs mongodb
This command will display the logs generated by the MongoDB container. Check if there are any errors or warnings related to the MongoDB startup or connection.
2. Verify the MongoDB container’s network configuration:
Run the following command to inspect the MongoDB container’s network settings:
docker inspect mongodb
Look for the “Networks” section in the output. Ensure that the container is connected to a network, and note the network name.
3. Test connectivity to the MongoDB container:
Run the following command to start a temporary container in the same network as the MongoDB container:
docker run -it --rm --network= mongo mongo --host mongodb --eval "printjson(db.serverStatus()
<network-name> with the actual network name from the previous step.
If the command is successful, it means you can connect to the MongoDB container from within the same network.
or find network name by below command
docker network ls
If the issue persists, please provide the complete error message and the outputs of the commands
docker inspect mongodb, and
docker logs mongodb. This will help in further diagnosing the problem.