How to run MongoDB Docker container and verify the process?

To get started with a MongoDB Docker container, run the docker run towards MongoDB. Here is an example

sudo docker run --name codetryout-mongo -d mongo
  • sudo – if you are using a non-root user (which is recommended)
  • the docker run command
  • –name followed by your preferred name label for the container
  • Finally the image name -d mongo

Demo – docker runs MongoDB container

docker run mongodb

How to verify whether your docker MongoDB container is running?

Here is the command to check the container status

sudo docker ps

Typical output:

[email protected]:~$ sudo docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS       NAMES
ffc3701f3a5a   mongo     "docker-entrypoint.s…"   10 minutes ago   Up 10 minutes   27017/tcp   codetryout-mongo