I launch a container running PostgreSQL with the command:
docker run -p 5432:5432 -d -it -e POSTGRES_USER='postgres' -e POSTGRES_PASSWORD='postgres' -e POSTGRES_DB='thingsboard' --name postgres postgres
Then, I launch ThingsBoard providing some environment variables to use the PostgreSQL database:
docker run -it -p 9090:9090 -p 1883:1883 -p 5683:5683/udp -v ~/.mytb-data:/data -v ~/.mytb-logs:/var/logs/thingsboard --name thingsboard --restart always -e SPRING_DATASOURCE_URL=jdbc:postgresql://<MY_LOCAL_IP>:5432/thingsboard -e SPRING_DATASOURCE_USERNAME=postgres -e SPRING_DATASOURCE_PASSWORD=postgres thingsboard/tb-postgres
where <MY_LOCAL_IP> is my IP address on the local network. I checked PostgreSQL, which actually binds to <MY_LOCAL_IP>:5432 (verified through PGAdmin).
The thingsboard container returns an error:
I expect ThingsBoard itself to create the tables in the thingsboard database, but it seems that it doesn't appen so. Any guess on the possible cause of this error? Thanks.
It seems that the problem is given by the volumes: mytb-data and mytb-logs have been created before and are not empty. The containers work as long as we launch thingsboard with:
docker run -it -p 9090:9090 -p 1883:1883 -p 5683:5683/udp --name thingsboard --restart always -e SPRING_DATASOURCE_URL=jdbc:postgresql://<MY_LOCAL_IP>:5432/thingsboard -e SPRING_DATASOURCE_USERNAME=postgres -e SPRING_DATASOURCE_PASSWORD=postgres thingsboard/tb-postgres
Related
I am trying to carry out some experiments with Docker, MongoDB, and mongo-express.
Here was what I did:
docker network create my-network
docker run -d -p 27017:27017 --network my-network --name my-mongo -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=pass mongo
docker run -d -p 8081:8081 --network my-network --name my-mongo-express -e ME_CONFIG_OPTIONS_EDITORTHEME="ambiance" -e ME_CONFIG_MONGODB_SERVER="my-mongo" -e ME_CONFIG_BASICAUTH_USERNAME="admin" -e ME_CONFIG_BASICAUTH_PASSWORD="pass" mongo-express
No error message was received apparently.
However, when I entered the address "localhost:8081" on Chrome, the page displayed an error message saying:
This page isn’t working
localhost didn’t send any data.
ERR_EMPTY_RESPONSE
How can I fix this?
You set the admin username and password on the database, but then you use the 'normal' user environment variables to try to log on. Instead of ME_CONFIG_BASICAUTH_USERNAME and ME_CONFIG_BASICAUTH_PASSWORD, you should use ME_CONFIG_MONGODB_ADMINUSERNAME and ME_CONFIG_MONGODB_ADMINPASSWORD, like this
docker run -d -p 8081:8081 --network my-network --name my-mongo-express -e ME_CONFIG_OPTIONS_EDITORTHEME="ambiance" -e ME_CONFIG_MONGODB_SERVER="my-mongo" -e ME_CONFIG_MONGODB_ADMINUSERNAME="admin" -e ME_CONFIG_MONGODB_ADMINPASSWORD="pass" mongo-express
I am executing the following command from the postgres doc
docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword
-d postgres
Now out of curiosity I run the following:
docker run -it --name some-postgres -e
POSTGRES_PASSWORD=mysecretpassword -d postgres bash
and I don't end up with an interactive bash shell.
Also trying:
docker run -it --name some-postgres --entrypoint bash -e
POSTGRES_PASSWORD=mysecretpassword -d postgres
does not work either.
How come I am not able to override the default command?
The command is working properly, but since you are using the -d flag the container is being started in the background.
Remove that flag and you'll be in an interactive bash session:
docker run -it --name some-postgres --entrypoint bash -e POSTGRES_PASSWORD=mysecretpassword postgres
I am trying to connect Odoo to a Postgres database instance which is running in Docker, but having trouble figuring out how to connect them. I created my instance like so:
$ docker run -d -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo -e POSTGRES_DB=postgres --name mydb postgres:10
Only Postgres is running in Docker, not Odoo. How would I connect the Postgres running inside Docker to the outside Odoo?
Shortly:
You have to open the port of your docker instance
-p 5432:5432
Example:
docker run -d -p 5432:5432 -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo -e POSTGRES_DB=postgres --name mydb postgres:10
Description
Because when you run a container with docker, it is not exposed by default to the host network. So when you run Postgres, it is not accessible outside of the container. In order to make it accessible, you could :
Export a specific port : docker run -d -p 5432:5432 ...
Use the host network: docker run --network=host ...
Bonus:
If you wish to run odoo within a container in the future, you might need to create a docker network docker network create odooNetwork and use it for your Postgres and Odoo instances :
docker run -d --network=odooNetwork ...
More details about docker network in the documentation
I run a Postgresql Docker container database in my server with the exposed port 5432. After a heavy load from users this container became unresponsive by the port.
docker run -d --env POSTGRES_PASSWORD=postgres --env POSTGRES_USER=user --env POSTGRES_DB=database -p 5432:5432 password
To resolve this I need to enter to the container, make a backup, restart the container and import the backup.
$ docker exec -it [id] sh
# pg_dump -U user dbname > dbexport.pgsql
# exit
$ docker cp [id]:/backup.pgsql ~/backup.pgsql
$ docker stop [id]
$ docker run -d --env POSTGRES_PASSWORD=postgres --env POSTGRES_USER=user --env POSTGRES_DB=database -p 5432:5432 password
$ docker exec -it [id] sh
# psql -U user database < backup.pgsql
# exit
And everything back to work until other heavy load.
Why this happens?
Im getting errors trying to run my docker containers. I need the postgres and redis connected to my server application.
docker pull postgres
docker rm -f syda-postgres
docker run -p 30203:5432 --name syda-postgres -e POSTGRES_PASSWORD=password POSTGRES_USER=root POSTGRES_DB=syda postgres
docker pull redis
docker rm -f syda-inmemory
docker run -d -p 30204:6379 --name syda-inmemory redis redis-server --appendonly yes
docker pull docker.url.ee/syda/server:latest
docker rm -f syda-server
docker run -d -p 30202:8080 --name syda-server --link syda-postgres:postgres --link syda-inmemory:redis \docker.url.ee/syda/server:latest
This is the error im getting:
Error: No such container: syda-postgres
docker: invalid reference format: repository name must be lowercase.
See 'docker run --help'.
Error: No such container: syda-server
docker: Error response from daemon: could not get container for syda-postgres: No such container: syda-postgres.
See 'docker run --help'.
docker run -p 30203:5432 --name syda-postgres -e POSTGRES_PASSWORD=password POSTGRES_USER=root POSTGRES_DB=syda postgres
That tries to run a container from the image named POSTGRES_USER=root with the command/arguments to the entrypoint POSTGRES_DB=syda postgres. You need to pass the -e for each variable like:
docker run -p 30203:5432 --name syda-postgres \
-e POSTGRES_PASSWORD=password -e POSTGRES_USER=root -e POSTGRES_DB=syda \
postgres
Also, note that links are deprecated, you should use a shared network for communicating between containers. This is often done with a compose file. If you need to do it from a script, you could run:
docker pull postgres
docker pull redis
docker pull docker.url.ee/syda/server:latest
docker rm -f syda-postgres
docker rm -f syda-inmemory
docker rm -f syda-server
docker network rm syda-net
docker network create syda-net
docker run -p 30203:5432 --net syda-net --name syda-postgres \
-e POSTGRES_PASSWORD=password -e POSTGRES_USER=root -e POSTGRES_DB=syda \
postgres
docker run -d -p 30204:6379 --net syda-net --name syda-inmemory \
redis redis-server --appendonly yes
docker run -d -p 30202:8080 --net syda-net --name syda-server \
docker.url.ee/syda/server:latest