I want to deploy ThingsBoard as a Docker container. I use this image and I try to overwrite some environment variables to get connection with an external Postgres database.
I simply have a Postgres running on localhost:5432 with (empty) database thingsboard, I create the Docker volumes mytb-data and mytb-logs and I launch:
docker run -it -p 9090:9090 -p 1883:1883 -p 5683:5683/udp -v mytb-data:/data -v mytb-logs:/var/log/thingsboard -e SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/thingsboard -e SPRING_DATASOURCE_USERNAME=postgres -e SPRING_DATASOURCE_PASSWORD=<MY_PASSWORD_HERE> --name mytb --restart=always thingsboard/tb-postgres
The container starts, but the logs report the following error:
2020-11-03 07:55:40,480 [main] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - ERROR: relation "admin_settings" does not exist
Position: 152
... [OMITTED]
Caused by: org.postgresql.util.PSQLException: ERROR: relation "admin_settings" does not exist
Position: 152
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2455)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2155)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:288)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:430)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:356)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:168)
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:116)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:57)
... 166 common frames omitted
pg_ctl: could not send stop signal (PID: 9): No such process
Any idea why this happens?
The environment variables shall be delimited with quotes '[...]' in Docker launch command.
This is not necessary in Docker Compose.
For Docker, launch
docker run -it -p 9090:9090 -p 1883:1883 -p 5683:5683/udp --name thingsboard --restart always -e SPRING_DATASOURCE_URL='<URL>' -e SPRING_DATASOURCE_USERNAME='<USERNAME>' -e SPRING_DATASOURCE_PASSWORD='<PASSWORD>' thingsboard/tb-postgres
Moreover, I was able to solve the issue using the following configuration (Docker Compose, similar for Docker):
thingsboard:
container_name: thingsboard
image: thingsboard/tb-postgres
restart: always
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://<HOSTNAME>:<PORT>/thingsboard
- SPRING_DATASOURCE_USERNAME=<USERNAME>
- SPRING_DATASOURCE_PASSWORD=<PASSWORD>
ports:
- '9090:9090'
- '1883:1883'
- '5683:5683/udp'
Inside mytb-data is created the postgres folder call db, or if you have the db postgres folder in another place do the next in that place.
I consider you have DB folder in the ...mytb-data/db you have to do the next:
chown -R postgres mytbpe-data/db
Because the folder db is created with another user and is the user postgres who is going to use that folder, with this most probably you will fix the problem, I had the same problem and with this I fixed it.
Related
I have created a network in order to host postgres db and sonarqube containers in same network:
docker network create sonarqube_network
And created a postgres container with following:
docker run --name postgres -e POSTGRES_USER=sonar -e POSTGRES_PASSWORD=sonar -p 5432:5432 --network sonarqube_network -d postgres
And created sonarqube container with following:
docker run -d --name sonarqube -p 9000:9000 -e sonar.jdbc.url=jdbc:postgresql://postgres/postgres -e sonar.jdbc.username=sonar -e sonar.jdbc.password=sonar --network sonarqube_network sonarqube:developer
It was working fine, but i am not sure what changed but now it can't connect to database:
2022.04.06 07:33:06 INFO web[][o.sonar.db.Database] Create JDBC data source for jdbc:postgresql://postgres/postgres
2022.04.06 07:33:16 ERROR web[][o.s.s.p.PlatformImpl] Web server startup failed
java.lang.IllegalStateException: Fail to connect to database
at org.sonar.db.DefaultDatabase.start(DefaultDatabase.java:86)
at org.sonar.core.platform.StartableCloseableSafeLifecyleStrategy.start(StartableCloseableSafeLifecyleStrategy.java:40)
at org.picocontainer.injectors.AbstractInjectionFactory$LifecycleAdapter.start(AbstractInjectionFactory.java:84)
at org.picocontainer.behaviors.AbstractBehavior.start(AbstractBehavior.java:169)
at org.picocontainer.behaviors.Stored$RealComponentLifecycle.start(Stored.java:132)
at org.picocontainer.behaviors.Stored.start(Stored.java:110)
at org.picocontainer.DefaultPicoContainer.potentiallyStartAdapter(DefaultPicoContainer.java:1016)
at org.picocontainer.DefaultPicoContainer.startAdapters(DefaultPicoContainer.java:1009)
at org.picocontainer.DefaultPicoContainer.start(DefaultPicoContainer.java:767)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.server.platform.platformlevel.PlatformLevel.start(PlatformLevel.java:90)
at org.sonar.server.platform.platformlevel.PlatformLevel1.start(PlatformLevel1.java:171)
at org.sonar.server.platform.PlatformImpl.start(PlatformImpl.java:213)
at org.sonar.server.platform.PlatformImpl.startLevel1Container(PlatformImpl.java:172)
at org.sonar.server.platform.PlatformImpl.init(PlatformImpl.java:86)
at org.sonar.server.platform.web.PlatformServletContextListener.contextInitialized(PlatformServletContextListener.java:43)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4763)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5232)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1427)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1417)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.IllegalStateException: Can not connect to database. Please check connectivity and settings (see the properties prefixed by 'sonar.jdbc.').
I can't create from initial step because i will lost developer license.
Hi I a using postgres docker-compose in my application. When I am trying to run it on my local machine (macOS Big Sur) I am getting below error and postgres container exited.
/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/postgres-ssl.sh
/usr/local/bin/docker-entrypoint.sh: /docker-entrypoint-initdb.d/postgres-ssl.sh: /bin/bash: bad interpreter: Permission denied
Below is my docker-compose
postgres:
build:
context: ./setup/postgres
dockerfile: ./Dockerfile
command:
-c ssl=on -c ssl_cert_file=/var/lib/postgresql/ssl/certs/server.crt
-c ssl_key_file=/var/lib/postgresql/ssl/certs/server.key
-c ssl_ca_file=/var/lib/postgresql/ssl/certs/root.crt
ports:
- '5432:5432'
volumes:
- ./setup/postgres/scripts:/docker-entrypoint-initdb.d
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
Am I missing any steps here?
I ended up running into this same issue. For anyone who faces this, you need to give execution permission to your script file, since Docker copies over permissions:
chmod +x your/script.sh
In my case the issue msg was:
/opt/bitnami/scripts/libpostgresql.sh: /docker-entrypoint-initdb.d/my-initdb.sh: /bin/bash: bad interpreter: Permission denied
Then I gave execution permission to my-initdb.sh and it worked nicely
I am triying to publish dockers using docker-compose remotely.
I have created a docker context, then I obtain "failed to open the raw stream connection: dial unix /var/run/docker.sock: connect: permission denie" when I make "docker-compose ... up".
docker context create remote223 --docker host=ssh://foo#192.168.0.223
docker context use remote223
docker-compose -f docker-compose.yml up -d
=> foo#192.168.0.223's password:
OK
failed to open the raw stream connection: **dial unix /var/run/docker.sock: connect: permission denied**
Traceback (most recent call last):
File "urllib3\connectionpool.py", line 670, in urlopen
File "urllib3\connectionpool.py", line 426, in _make_request
As context information, when I publish the docker container logger on host with my ssh client I need to do "sudo" to do the docker-compose.
Try checking your permissions for docker.sock
$ ls -last /var/run/docker.sock
$ whoami
$ cat /etc/group | grep docker
Then you if you don't want to restart docker daemon you can run this:
sudo setfacl --modify user:<user name or ID>:rw /var/run/docker.sock
$sudo addgroup --system docker
$sudo adduser $USER docker
$newgrp docker
Or if you don't mind restarting use this:
sudo chmod 777 /var/run/docker.sock
sudo reboot
When I try to run my mongoDB image called database with sudo docker run -p 27017:27017 I get exitCode 100. I looked at some info online and found this about exitCode 100: Returned by mongod when the process throws an uncaught exception. I've had this issue before and was able to fix it with docker system prune --force but when i do it now I get the same exitCode.
I have tried building the image again but when I do that I either get the same exitCode or exitCode 51, of which I can't find any info online.
Any idea how I can fix this?
EDIT: I am working on an Ubuntu server vm and it has worked before.
Content of my Dockerfile:
From mongo:latest
COPY usertoevoegen.js /docker-entrypoint-initdb.d/
RUN mongod --fork --logpath /var/log/mongodb.log --dbpath /data/db
Content of usertoevoegen.js:
db=db.getSiblingDB('admin');
db.createUser({user: "admin",pwd: "admin123",roles: [{ role: "root", db: "admin" }]});
db.createCollection("gebruiker");
db.gebruiker.insert([{"naam" : "Toon"}]);
Apparently I didn't have enough storage left on my server which caused the error.
I am trying to create test container with DockerComposeContainer.
DockerComposeContainer container =
new DockerComposeContainer(
new File("src/integrationTest/resources/mycompose-file.yml"))
.withLocalCompose(true)
.withExposedService("mongodb", 27017, Wait.forListeningPort());
container.start();
return container;
mycopose-file.yml has following:
version: '3'
services:
mongodb:
image: mongo:3.6
environment:
MONGO_INITDB_ROOT_USERNAME: uname
MONGO_INITDB_ROOT_PASSWORD: upass
My test dependency include: testcontainers-1.12.3.jar
I am getting error during application context startup:
java.lang.IllegalStateException: Failed to load ApplicationContext
with root cause:
Caused by: org.testcontainers.containers.ContainerLaunchException: Local Docker Compose exited abnormally with code 1 whilst running command: up -d
at org.testcontainers.containers.LocalDockerCompose.invoke(DockerComposeContainer.java:711)
....
In my case I got this error because network in docker had exhausted. Given docker has limited network that we can have. We have to do the cleanup, for that I ran command:
docker network prune
this fixed my problem