I have deployed a database using docker swarm
docker stack deploy -c docker-compose.yml app
docker-compose.yml
version: '3.1'
services:
database:
image: mongo:latest
I'd like to run a JavaScript file script.js
from my host in the deployed database
container:
docker exec \
app_database.1.$(docker service ps -f 'name=app_database.1' app_database -q) \
mongo script.js
However, the file script.js
does not exist in the container (only on my host). How can I run it without restarting the database
service?
A script can be sent on stdin to the mongo
client.
Create a script locally:
print('The mongodb version is: '+db.version())
Then run
$ cat script.js | docker exec $container mongo --quiet
The mongodb version is: 3.6.3