Can't run docker image with MongoDB - mongodb

I'm using Docker+MongoDB to run a Personal Project (tutorial i'm learning from). It worked flawlessly yesterday, but i had to restart my computer today.
Now i can't get it up & running again. I'm always having the error (according to the logs):
EDIT: The same error happens when i try to run it locally also (just compiling and checking on Postman if i can run any query). Its the same error message.
EDIT2: After running:
docker run -d --rm --name mongo -p 27017:27017 -v mongodbdata:/data/db
mongo
I got it working locally. However, i still can't get it running using the docker image.
Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HML25FGS5AM1", Request id "0HML25FGS5AM1:00000002": An unhandled exception was thrown by the
application.
System.TimeoutException: A timeout occurred after 30000ms selecting a server using CompositeServerSelector{ Selectors =
MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector,
LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000
}, OperationsCountServerSelector }. Client view of cluster state is {
ClusterId : "1", Type : "Unknown", State : "Disconnected", Servers :
[{ ServerId: "{ ClusterId : 1, EndPoint : "Unspecified/mongo:27017"
}", EndPoint: "Unspecified/mongo:27017", ReasonChanged: "Heartbeat",
State: "Disconnected", ServerVersion: , TopologyVersion: , Type:
"Unknown", HeartbeatException:
"MongoDB.Driver.MongoConnectionException: An exception occurred while
opening a connection to the server.
Here's what i can tell:
MongoDB is running. On Visual Studio using Mongo Extension, i can see that my mongo database is connected.
When i open docker for windows, i can see my image there as well. And if i hover the mouse under docker icon on notification tray, it says that docker is running.
My connection string seems to be okay. I couldn't figure out any problem with that, since its the same that was working yesterday.
I'm a bit of lost here, i don't know what else to do. It would be really really painful to restart the entire tutorial because of this docker error.
Here is my connection string:
$"mongodb://{User}:{Password}#{Host}:{Port}";
The command i'm using under the cli to run my docker image is:
docker run -it --rm -p 8080:80 -e MongoDbSettings:Host=mongo -e
MongoDbSettings:Password=Pass#word1 --network=net5tutorial
pablobhz/catalog:v1
Any input is appreciated. Thanks a lot!

Well, i fixed the problem myself. Here's what i did:
Followed the suggestion from user barrypicker . It didn't worked out but gave me an clean start.
Created a new docker file and changed it accordingly (only minor changes).
Created the mongodb container again. Here's what i did:
docker run -d --rm --name mongo -p 27017:27017 -v mongodbdata:/data/db mongo
Fine. Now i have the mongo container running again.
Built my docker image again:
docker build -t catalog:v1 .
Tried to create the docker network again. Since it already existed, just received a message saying it exists. So far so good.
Started the mongo container again. I understood that i had to start in order to my docker image works. It can't connect to an database if there's none running.
docker run -d --rm --name mongo -p 27017:27017 -v mongodbdata:/data/db
/e MONGO_INITDB_ROOT_USERNAME=mongoadmin -e
MONGO_INITDB_ROOT_PASSWORD=Pass#word1 --network=net5tutorial mongo
Started the main container again:
docker run --it --rm -p 8080:80 -e MongoDbSettings:Host=mongo -e
MongoDbSettings:Password=Pass#word1 --network=net5tutorial catalog:v1
Hope this helps someone in the future! Sorry fot eh explanation not being great, its my first time with Docker and i've been into a lot of trial and error to get it working.
Thanks everyone!

Related

Docker Postgres shutting down immediately with (4294967295) exited code

I am using Docker for Windows which is up to date (v 4.16.2). I also switched to Windows Containers. I wanted to use postgres using this prompt:
docker run --name MyPostgresSQL -p 5432:5432 -e POSTGRES_PASSWORD=12345 -d postgres
Then the log of this MyPostgresSQL is here:
I couldn't even find any question about this error. I tried restarting docker, switching to Linux containers then switching back to Windows containers, purging docker data but any of them didn't work at all.

Can't connect to MongoDB docker from Compass

I created a MongoDB docker instance as follows:
sudo docker run --name mongo -d -p 27000:27000 mongo
I confirmed that the instance is running by using command sudo docker ps --all :
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f509276287eb mongo "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 0.0.0.0:27000->27000/tcp, :::27000->27000/tcp, 27017/tcp mongo
Then I tried to connect to it using Compass GUI tool with the following connection string:
mongodb://localhost:27000/
I get a screen the following screen:
and after waiting for a while, the screen disappears with the following error message
connection <monitor> to 127.0.0.1:27000 closed
My goal is to use this docker image to run tests, but I cannot connect to it.
I tried using 0.0.0.0 instead of localhost but it didn't work.
My Question: How do I connect to MongoDB docker image?
Environment info:
OS is Ubuntu 22.04
Docker version 20.10.14, build a224086349 (snap package)
Compass version 1.33.1 (deb package)
I figured it out. I made a silly mistake when picking the port, I should have used:
sudo docker run --name mongo -d -p 27000:27017 mongo
Because Mongo will always be on port 27017 inside the image.

Unable to run docker container for mongodb 2.6.12

I need mongodb specific version and when I run the following command, it runs the container but exit quickly
docker run --name some-mongo -d mongo:2.6.12
4bbe88021ad919ba9680a2a4710e664a87e8620d4cd9802567029fec131534a3
If I list the containers docker ps -a, I can see following output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4bbe88021ad9 mongo:2.6.12 "/entrypoint.sh mong…" 4 seconds ago Exited (139) 3 seconds ago some-mongo
I am not sure why its existing and hence tried the logs
docker logs 4bbe88021ad9 but the is result empty (no result at all)
Please note the lates version works fine
docker run -p 27031:27017 --name kongoLatest -d mongo
I need to investiage why its not working for specific version? The main process must be failing and throwing some error which I am not able to see it.

Running a Chainlink Node - Remote DATABASE_URL Config PostgreSQL problem

I have been trying since yesterday to connect to a ChainLink node and I was not able to.
I followed the steps at this website
I am having a problem with "Set the Remote DATABASE_URL Config" (I think that this is my only error because of the [ERROR] listed below, I do not know if I am doing something else wrong since every command was executed without error)
I am using the Docker option to create the database listed here.
I am always having this error:
"[ERROR] unable to lock ORM: failed to connect to host=localhost user=some-postgres database=postgres: dial error (dial tcp [::1]:5432: connect: cannot assign requested address) logger/default.go:155 stacktrace=github.com/smartcontractkit/chainlink/core/logger.Errorf
/chainlink/core/logger/default.go:155"
After writing in my Ubuntu Terminal (ON WINDOWS 10):
"cd ~/.chainlink-kovan && docker run -p 6688:6688 -v ~/.chainlink-kovan:/chainlink -it --env-file=.env smartcontract/chainlink:0.10.1 local n"
I do not know how to connect to the database and what to write as attributes. All of the other steps and installs I have accomplished successfully.
I just want to know how to create a database on PostgreSQL and connect it to Docker as explained on the ChainLink website and write the appropriate command in the Ubunto terminal (for the "Remote DATABASE_URL Config PostgreSQL" step) so that I can run my node.
Thanks! (PS: I am a beginner and your help is much appreciated, and if I forgot to mention any important information please let me know so that I add it)
A comprehensive 101 for docker-postgres can be found here: https://hackernoon.com/dont-install-postgres-docker-pull-postgres-bee20e200198
Basically, you need to deploy a postgres db with docker
Pre-Reqs:
Create a dir for you docker/postgres:
mkdir -p $HOME/docker/volumes/postgres
Example:
docker run --rm --name pg-docker -e POSTGRES_USER=<any_desired_name> -e POSTGRES_PASSWORD=docker -e POSTGRES_DB=<any_db_name> -d -p 5432:5432 -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data postgres
For postgres username, it can be anything like "super_chain" or etc.
For postgres db, it can be "chainlink"
After, docker is up and running. Just follow up the docs tut, where you need to write the DB URL to the .env file
Cheers

Docker Postgres Image not accessible

So, I pulled the postgres image down from docker. I followed a tutorial which explained what's going with the command below and the the whole docker pull. I can log in to the instance fine. But when I restart my computer or shutdown docker I end up goign through similar setup steps and am not able to access the postgres instance anymore. Can someone explain what's going on here:
Run this command
docker run --rm --name pg-docker -e POSTGRES_PASSWORD=docker -d postgres -p 5432:5432 -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data postgres
log in via PG admin.
Nothing, instance not available.
So, I feel like I am missing a step at one point I had executed a command like this:
docker exec -it c5b8bdd0820b35a01ea153a44e82458a6285cf484b701b2b2d6d4210266fb4f8 bash
which gave me acess to the shell for the image, after doing that I was able then to use PGAdmin, however, I feel like that may have been coincidence? As this does not work currently.
So, what am I doing wrong? What's an easier way to do this?
The --rm causes Docker to automatically remove the container when it exits. Remove it.
You can also add --restart always and your container will be up after restart.