docker-entrypoint-initdb.d bad interpreter: Permission denied - postgresql

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

Related

mlflow error on an EC2 instance with postgreSQL backend database

I am trying to run this command:
mlflow server --backend-store-uri postgresql://aagmlflow:mlflow-#aagmlflow.cbh3397nepzq.us-east-1.rds.amazonaws.com/mlflow --default-artifact-root file:/root/mlruns -h 0.0.0.0 -p8000
Error is below here:
/usr/local/lib/python3.7/dist-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
""")
2022/10/27 16:16:03 WARNING mlflow.store.db.utils: SQLAlchemy engine could not be created. The following exception is caught.
(psycopg2.OperationalError) FATAL: password authentication failed for user "aagmlflow"
FATAL: password authentication failed for user "aagmlflow"
(Background on this error at: https://sqlalche.me/e/14/e3q8)
Operation will be retried in 0.1 seconds
2022/10/27 16:16:03 WARNING mlflow.store.db.utils: SQLAlchemy engine could not be created. The following exception is caught.
(psycopg2.OperationalError) FATAL: password authentication failed for user "aagmlflow"
FATAL: password authentication failed for user "aagmlflow"
(Background on this error at: https://sqlalche.me/e/14/e3q8)
Operation will be retried in 0.3 seconds
2022/10/27 16:16:04 WARNING mlflow.store.db.utils: SQLAlchemy engine could not be created. The following exception is caught.
(psycopg2.OperationalError) FATAL: password authentication failed for user "aagmlflow"
FATAL: password authentication failed for user "aagmlflow"
(Background on this error at: https://sqlalche.me/e/14/e3q8)
what could i be doing wrong here?
Is there any way i could troubleshoot this? Please i need help from the community.
this actually helped me resolved this issue.
mlflow server --backend-store-uri postgresql \
--default-artifact-root file:/tmp \
--host 0.0.0.0 \
--port 8000
I also ran a docker container with this too.
# Docker multistage build to reduce image size
FROM python:3.10 AS build
RUN python -m venv /opt/venv
# Make sure we use the virtualenv:
ENV PATH="/opt/venv/bin:$PATH"
RUN pip install mlflow
FROM python:3.10-slim
COPY --from=build /opt/venv /opt/venv
COPY --from=build /usr/lib /usr/lib
# Make sure we use the virtualenv:
ENV PATH="/opt/venv/bin:$PATH"
EXPOSE 8000/tcp
ENTRYPOINT [ "mlflow", "server", "--host", "0.0.0.0"]
CMD [ "--backend-store-uri", "/tmp"]
then build & run the container
docker build -t mlflow-tracking . && docker run -dp 80:8000 mlflow-tracking

Docker run returning exit code 100 or 51

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.

ThingsBoard Docker container deploy resulting in `PSQLException`

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.

Gitlab CI services are stopped after bizzar psql call

I am trying to use services in gitlab ci, namely, postgres. Anyway, postgres service doesn't seem to be running, although I just copied what is there in Gitlab CI docs. In logs, after service logs that it started, some psql command (I don't know where it came from) gives an name resolution error. If I am doing something wrong here, what is the way to run postgres service in gitlab-ci?
Below are .gitlab-ci.yml file and logs:
.gitlab-ci.yml
image: ubuntu
services:
- name: postgres:12.2-alpine
alias: postgres
variables:
POSTGRES_DB: badr
POSTGRES_USER: badr
POSTGRES_PASSWORD: badr
PGHOST: postgres
POSTGRES_HOST_AUTH_METHOD: trust
stages:
- test
test db:
stage: test
before_script:
- until (echo > /dev/tcp/postgres/5432) >/dev/null 2>&1;do >&2 echo "service not ready...sleeping";sleep 5;done
script:
- echo "connected to...$PGHOST"
- sleep 10
logs
Running with gitlab-runner 13.2.0-rc2 (45f2b4ec)
on docker-auto-scale fa6cab46
Preparing the "docker+machine" executor
00:55
Using Docker executor with image ubuntu ...
Starting service postgres:12.2-alpine ...
Pulling docker image postgres:12.2-alpine ...
Using docker image sha256:ae192c4d3adaebbbf2f023e1e50eaadfabccb6b08c855ac13d6ce2232381a58a for postgres:12.2-alpine ...
WARNING: Service postgres:12.2-alpine is already created. Ignoring.
Waiting for services to be up and running...
*** WARNING: Service runner-fa6cab46-project-14794655-concurrent-0-f52b350b86ad38db-postgres-0 probably didn't start properly.
Health check error:
service "runner-fa6cab46-project-14794655-concurrent-0-f52b350b86ad38db-postgres-0-wait-for-service" timeout
Health check container logs:
Service container logs:
2020-07-31T09:15:00.377204181Z ********************************************************************************
2020-07-31T09:15:00.377254629Z WARNING: POSTGRES_HOST_AUTH_METHOD has been set to "trust". This will allow
2020-07-31T09:15:00.377259167Z anyone with access to the Postgres port to access your database without
2020-07-31T09:15:00.377262471Z a password, even if POSTGRES_PASSWORD is set. See PostgreSQL
2020-07-31T09:15:00.377265670Z documentation about "trust":
2020-07-31T09:15:00.377269181Z https://www.postgresql.org/docs/current/auth-trust.html
2020-07-31T09:15:00.377272282Z In Docker's default configuration, this is effectively any other
2020-07-31T09:15:00.377276152Z container on the same system.
2020-07-31T09:15:00.377295876Z
2020-07-31T09:15:00.377299453Z It is not recommended to use POSTGRES_HOST_AUTH_METHOD=trust. Replace
2020-07-31T09:15:00.377302412Z it with "-e POSTGRES_PASSWORD=password" instead to set a password in
2020-07-31T09:15:00.377305641Z "docker run".
2020-07-31T09:15:00.377308656Z ********************************************************************************
2020-07-31T09:15:00.404620899Z The files belonging to this database system will be owned by user "postgres".
2020-07-31T09:15:00.406021814Z This user must also own the server process.
2020-07-31T09:15:00.406074886Z
2020-07-31T09:15:00.406083517Z The database cluster will be initialized with locale "en_US.utf8".
2020-07-31T09:15:00.406087263Z The default database encoding has accordingly been set to "UTF8".
2020-07-31T09:15:00.406090884Z The default text search configuration will be set to "english".
2020-07-31T09:15:00.406094281Z
2020-07-31T09:15:00.406097490Z Data page checksums are disabled.
2020-07-31T09:15:00.406101511Z
2020-07-31T09:15:00.406197662Z fixing permissions on existing directory /var/lib/postgresql/data ... ok
2020-07-31T09:15:00.406858429Z creating subdirectories ... ok
2020-07-31T09:15:00.407274720Z selecting dynamic shared memory implementation ... posix
2020-07-31T09:15:00.428414929Z selecting default max_connections ... 100
2020-07-31T09:15:00.506801199Z selecting default shared_buffers ... 128MB
2020-07-31T09:15:00.689382376Z selecting default time zone ... UTC
2020-07-31T09:15:00.695744690Z creating configuration files ... ok
2020-07-31T09:15:01.009439741Z running bootstrap script ... ok
2020-07-31T09:15:01.355673765Z sh: locale: not found
2020-07-31T09:15:01.355836607Z 2020-07-31 09:15:01.355 UTC [30] WARNING: no usable system locales were found
2020-07-31T09:15:01.784080826Z performing post-bootstrap initialization ... ok
2020-07-31T09:15:02.416545146Z syncing data to disk ... ok
2020-07-31T09:15:02.416652656Z
2020-07-31T09:15:02.416854775Z initdb: warning: enabling "trust" authentication for local connections
2020-07-31T09:15:02.416911707Z You can change this by editing pg_hba.conf or using the option -A, or
2020-07-31T09:15:02.416917642Z --auth-local and --auth-host, the next time you run initdb.
2020-07-31T09:15:02.416962149Z
2020-07-31T09:15:02.416967325Z Success. You can now start the database server using:
2020-07-31T09:15:02.416970415Z
2020-07-31T09:15:02.416990907Z pg_ctl -D /var/lib/postgresql/data -l logfile start
2020-07-31T09:15:02.416995097Z
2020-07-31T09:15:02.440378884Z waiting for server to start....2020-07-31 09:15:02.440 UTC [35] LOG: starting PostgreSQL 12.2 on x86_64-pc-linux-musl, compiled by gcc (Alpine 9.2.0) 9.2.0, 64-bit
2020-07-31T09:15:02.442773414Z 2020-07-31 09:15:02.442 UTC [35] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2020-07-31T09:15:02.461804500Z 2020-07-31 09:15:02.461 UTC [36] LOG: database system was shut down at 2020-07-31 09:15:01 UTC
2020-07-31T09:15:02.465323529Z 2020-07-31 09:15:02.465 UTC [35] LOG: database system is ready to accept connections
2020-07-31T09:15:02.524643142Z done
2020-07-31T09:15:02.524766601Z server started
2020-07-31T09:15:02.537508874Z psql: error: could not connect to server: could not translate host name "postgres" to address: Name does not resolve
*********
Pulling docker image ubuntu ...
Using docker image sha256:1e4467b07108685c38297025797890f0492c4ec509212e2e4b4822d367fe6bc8 for ubuntu ...
Preparing environment
00:02
Getting source from Git repository
00:01
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/badrmoh/cicdtest/.git/
Created fresh repository.
Checking out 604433de as master...
Skipping Git submodules setup
Executing "step_script" stage of the job script
$ until (echo > /dev/tcp/postgres/5432) >/dev/null 2>&1;do >&2 echo "service not ready...sleeping";sleep 5;done
service not ready...sleeping
service not ready...sleeping
service not ready...sleeping
service not ready...sleeping
service not ready...sleeping
service not ready...sleeping
gitlab-runner
The problem was in PGHOST variable. It seems it is used internally by postgres container that is why it fails to start.
The solution is to set PGHOST in script directive:
image: ubuntu
services:
- name: postgres:9
alias: postgres
variables:
POSTGRES_DB: badr
POSTGRES_USER: badr
POSTGRES_PASSWORD: badr
POSTGRES_HOST_AUTH_METHOD: trust
stages:
- test
test db:
stage: test
before_script:
- export PGHOST=postgres
- until (echo > /dev/tcp/$PGHOST/5432) >/dev/null 2>&1;do >&2 echo "service $PGHOST not ready...sleeping";sleep 5;done
script:
- echo "connected to...$PGHOST"
- sleep 10
Note: You can't use variables directive within jobs in this case since it seems to be populated before even starting services itself.

Passing URL as an environment variable in docker run

My docker container needs to connect to other system via http. so , I have export an REST_BASE_URL in environment variable and pass it on docker run using -e parameter . Unfortunately, I am ending up with below error . Can anybody help me out ?
docker: Error response from daemon: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"-eREST_BASE_URL=https://some.server.url\": stat -eREST_BASE_URL=https://some.server.url: no such file or directory": unknown.
Solved it using docker-compose.
Below is the sample :
version: '3.1'
services:
receiving:
build: .
restart: always
environment:
- "REST_BASE_URL=http://some.server.url"
ports:
- 8080:8080