Reputation: 25
Following the steps mentioned in the official docs in Docker Hub for Mongo.
I am able to build everything as expected by first pulling the relevant images and then running docker-compose up command against following file.
It starts up without issues and also able to open the shell via the command below.
But in that shell, running something like show dbs which is a Mongo command is not recognized.
Am I missing any further setups for this? Please advice. Thank you.
My docker-compose.yml file
version: "3.1"
services:
mongo:
image: mongo
container_name: mongo-instance-1
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
volumes:
- ./data:/data/db
mongo-express:
image: mongo-express
container_name: mongo-express-instance-1
restart: always
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: example
I then open the shell via following command which opens the bash terminal.
docker exec -it mongo-instance-1 bash
But Mongo commands not recognized in there as follows.
Ran following command
show dbs
Error output
bash: show: command not found
Upvotes: 2
Views: 5109
Reputation: 1
Use this command in your terminal,
docker exec -it mongo-instance-1 mongosh -u root -p example
or after the bash terminal opens try
mongosh -u root -p example
for more info see this link https://www.mongodb.com/docs/mongodb-shell/
Upvotes: 0
Reputation: 519
mongo has been renamed to mongosh - this works for me
docker exec -it mongo-instance-1 mongosh
Upvotes: 14
Reputation: 10727
You need to run the mongo client from the container instead of the bash shell:
docker exec -it mongo-instance-1 mongo
And then the commands ...
Upvotes: 0
Reputation: 3651
You are in bash at this stage.
You need to enter mongo via following command.
mongo admin -u root -p example
Now try running your show dbs command which will work. Good luck.
show dbs
Upvotes: 0