Using Docker and MongoDB - mongodb

I have been using Docker and Kubernetes for a while now, and have set up a few databases(postgres and mysql) and services.
Now I was looking at adding a mongoDB, but it seems different when it comes to user management.
Take for example postgres:
https://hub.docker.com/_/postgres/
Immediately I can declare users with a password on setup and then connect using this. It seems the mongo image does not support this. Is there a way to simply declare users on startup and use them similar to the postgres setup? This is, without having to exec into the image, modify auth settings and restarting the mongo service.

Related

Docker problem - Springboot container can't retrieve data from PostgreSQL container

i have very strange truble with Docker containers communication, here what i did:
1)I configured a Docker bridge network
2)I created PostgreSQL image and started it in bridge network (same of step 1)
3)I connected and filled PostgreSQL container with data using DBeaver from the host.
4)I created and started SpringBoot app container inside the bridge network. The SprigBoot app container connects correctly with PostgreSQL container.
Here's the problem: i can retrieve all data i want from PostgreSQL container using Dbeaver on same host or using my not-conteinerized SpringBoot app. But i can't retrieve data from the same PostgreSQL container using SpringBoot app container (in the same bridge network described in step 1).
It looks like SpringBoot app container can access only table's structures but it can't access data.
-I tried to modify postgresql conf allowing access from all hosts
I solved the problem my own and here is the solution:
Even though I started the docker postgres:12 image the default postgres server that was being started was v15. I noticed this problem by doing "test connection" from DBeaver. For this reason i could see only table's structures but can't access data. I solved the problem uninstalling Postgres server v15 (I was not using it) so the default version became v12.

Move my hasura cloud schema, relations, tables etc. and put into my offline docker file using docker-compose

So basically I have my cloud hasura with existing schema, relations tables etc... and i want to offline it using docker and try using metadata export and import that seems not working how can I do it or is there other ways to do it?
this is the docker i want to offline
this is my cloud i want to get the schemas or metadata
OR MAYBE I JUST MANUALLY RECREATE THE TABLES AND RELATIONS??
When using the steps outlined in the Hasura Quickstart with Docker page then the following steps would help get all the table definitions, relationships etc., setup on the local instance just like it is set up on hasura cloud instance.
Migrate all the database schema and metadata using the steps mentioned in Setting up migrations
Since you want to migrate from hasura cloud use the URL of the cloud instance in step 2. Perform steps 3-6 as described in the above link.
Bring up the local docker environment. Ideally edit the docker-compose.yaml file to set HASURA_GRAPHQL_ENABLE_CONSOLE: "false" before running docker-compose up -d.
Resume the process of applying migrations from step 7. Use the endpoint from local instance. For example,
$ hasura metadata apply --endpoint http://localhost:8080
$ hasura migrate apply --endpoint http://localhost:8080

How to connect mongodb in contanier

I deploy a mongodb in a container. and I also successfully connected to mongodb when my backend runs in the local environment. However, when I tried to move the backend to a container as well, it cannot connect mongodb anymore. The connection string remains the same but it failed.
The error shows that mongodb cannot find the user. However, in my local environment, the same connection string works.
After my googling, most guys said I need to change authSource. I have tried to change authSource to admin, it doesn't work even in my local environment. And I am sure the user exists in my admin database. not in api_dev_db. One wired thing is I can connect to mongodb in my local environment but not work in docker.
Could you kindly help me out?
Here I post some pictures.
These are the env variables I defined in my local environment and they work
This is how I deploy backend service
This is my backend dockerfile
This is the error when I deploy backend in container
This is how I initial mongodb
The problem is I need to remove '' in env variable, which is MONGO_URL=mongodb://api_user:api1234#mongodb:27017/api_dev_db?authSource=api_dev_db

How do I connect to the Divio postgres database with local PgAdmin?

I am trying to connect with PgAdmin to the local Divio database in the container but PgAdmin 4 will not let me connect without a password. The Divio Postgres database seems to come without a password.
Has anyone got round this?
You don't need a password.
See Interact with the local database from your host environment in the official documentation.
The key things are:
expose the database’s port by editing the docker-compose.yml file
use the correct credentials
Both steps are described in more detail in the documentation. I haven't given more specific details here such as port numbers in case those details ever change in the future.

Setting up Heroku with mongodb without using MLAB

Most of the documentation Ive seen only covers using mLab as a service for mongodb on heroku,
I would like to use mongoDB locally on the heroku server is this possible?
Heroku dynos use an ephemeral filesystem. This means that you cannot run a database on a Heroku dyno. All of the data will be lost whenever your process restarts. Your process restarts at least once every day, whenever you deploy new code, whenever you change config variables, or whenever you update add-ons.
You can read more about Heroku's ephemeral filesystem here: https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem
You can read more about dyno restarts here: https://devcenter.heroku.com/articles/dynos#restarting
So you will have to use a Heroku Add-on or a third-party service to add persistence to your application.
This doesn't mean you have to use the mLab Add-on. If you have your own MongoDB database, you can still connect to that in your application. You can add the connection string as a config variable and connect to it in the same way you would connect to an mLab Add-on.