I am a newbie with docker and trying my hands onto it. I am facing a minor problem, your help in any way would be appreciated!
I have a ruby script in which I am connecting to my localhost port which is assigned to my mongodb database. I am using MongoClient to connect to the database from the script:
clientDB = Mongo::Client.new(["localhost:37017"], :database => 'Database', :user => 'user', :password => 'password')
or
clientDB = Mongo::Client.new(["127.0.0.1:37017"], :database => 'Database', :user => 'user', :password => 'password')
If I run the script using ruby monthly_count_script.rb command, it works perfectly but as I am exploring Docker, I want to run that script into a container. So to run a container I am using following command
docker run -it --rm --name my-running-script -v "$PWD":/usr/src/app -v "$PWD"/../gems:/usr/local/bundle -w /usr/src/app --net=host ruby ruby monthly_count_script.rb
Unfortunately I am keep getting following error and I don't know why it is not able to connect to the localhost 37017 port even though my database is working properly and I am able to connect to the database using Robomongo or mongodb console.
This is the error log:
D, [2018-06-04T14:15:11.527381 #1] DEBUG -- : MONGODB | Topology type 'single' initializing.
D, [2018-06-04T14:15:11.527639 #1] DEBUG -- : MONGODB | Server 127.0.0.1:37017 initializing.
D, [2018-06-04T14:15:11.529252 #1] DEBUG -- : MONGODB | Connection refused - connect(2) for 127.0.0.1:37017
D, [2018-06-04T14:15:11.530774 #1] DEBUG -- : MONGODB | Topology type 'single' initializing.
D, [2018-06-04T14:15:11.531058 #1] DEBUG -- : MONGODB | Server 127.0.0.1:37017 initializing.
D, [2018-06-04T14:15:11.532518 #1] DEBUG -- : MONGODB | Connection refused - connect(2) for 127.0.0.1:37017
D, [2018-06-04T14:15:12.032037 #1] DEBUG -- : MONGODB | Connection refused - connect(2) for 127.0.0.1:37017
D, [2018-06-04T14:15:12.533348 #1] DEBUG -- : MONGODB | Connection refused - connect(2) for 127.0.0.1:37017
D, [2018-06-04T14:15:13.036087 #1] DEBUG -- : MONGODB | Connection refused - connect(2) for 127.0.0.1:37017
Looking forward to your help/guidance.
FYI I was following this documentation for running a ruby script in docker: https://docs.docker.com/samples/library/ruby/