Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access mongo shell running in docker container in linux script

I want to create a bash script that removes a user from a mongodb database that is running inside a docker container.

Normally through the terminal I would execute docker exec -it mycontainername bash

and then once I'm in the container I execute mongo mydbname --eval "db.users.remove({"firstname":"Bob"})"

I just have no idea how to do it in a linux bash script.

After I execute script that contains the docker exec command, it leaves the script and opens the docker container's terminal and prompts me to enter a command.

Would using the detached -d flag work?

like image 835
Kingamere Avatar asked Oct 21 '15 17:10

Kingamere


1 Answers

Found out you can replace bash with the name of the shell you want to open, so in this case mongo.

like image 165
Kingamere Avatar answered Sep 20 '22 00:09

Kingamere