I'm trying to use these instructions to try to run the mongodb docker image in a container.
I'm able to run the image:
(virtual) anonymous@anonymous:~/PycharmProjects/PostDekko/climbticks-flaskmongoangul$ sudo docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
431a9d693f48 mongo:bionic "docker-entrypoint.s…" 24 minutes ago Up 24 minutes 27017/tcp climbticks-mongodb
f12d227dcdd8 climbticks-flaskmongoangul_web_dev "python3.8 index.py" 3 hours ago Up 3 hours 0.0.0.0:4000->4000/tcp climbticks-flaskmongoangul_web_dev_1
My project is in the 2nd container, and the mongodb image is container_id 431a9d693f48. I can also access the logs, so I know it runs.
From their instructions:
The MongoDB server in the image listens on the standard MongoDB port, 27017, so connecting via Docker networks will be the same as connecting to a remote mongod. The following example starts another MongoDB container instance and runs the mongo command line client against the original MongoDB container from the example above, allowing you to execute MongoDB statements against your database instance:
> $ docker run -it --network some-network --rm mongo mongo --host
> some-mongo test
... where some-mongo is the name of your original mongo container.
However.... I don't understand what my "network" is supposed to be. I think that the network argument, from docker's perspective, means a network id. If I run:
(virtual) anonymous@anonymous:~/PycharmProjects/PostDekko/climbticks-flaskmongoangul$ sudo docker network ls
NETWORK ID NAME DRIVER SCOPE
7fbed634dbdf bridge bridge local
0843e5ae6173 host host local
6b3c8eb4b216 none null local
cc3d76f1f109 web_dev bridge local
I get 4 network ids. web_dev is my project's (webserver) container. If I try any of the 4, I get:
(virtual) anonymous@anonymous:~/PycharmProjects/PostDekko/climbticks-flaskmongoangul$ sudo docker run -it --network cc3d76f1f109 --rm mongo mongo --host climbticks-mongodb test
MongoDB shell version v4.2.7
connecting to: mongodb://climbticks-mongodb:27017/test?compressors=disabled&gssapiServiceName=mongodb
2020-05-31T01:55:08.771+0000 E QUERY [js] Error: couldn't connect to server climbticks-mongodb:27017, connection attempt failed: HostNotFound: Could not find address for climbticks-mongodb:27017: SocketException: Host not found (authoritative) :
connect@src/mongo/shell/mongo.js:341:17
@(connect):2:6
2020-05-31T01:55:08.779+0000 F - [main] exception: connect failed
2020-05-31T01:55:08.779+0000 E - [main] exiting with code 1
I also tried various expressions for localhost (0.0.0.0, localhost, etc.) even though that didn't make sense to me.
So.... how do I find what the network is supposed to be?
EDIT: although if I connect to my DB in the shell:
sudo docker exec -it climbticksmongodb bash
then I can talk to it. So the DB is live. I really just need to figure the network issue, it seems.
docker runcommand, or the relevant part of yourdocker-compose.ymlfile?)