containers icon indicating copy to clipboard operation
containers copied to clipboard

[bitnami/postgresql-repmgr] executing commands within the container does not work

Open esanya opened this issue 3 years ago • 12 comments

Name and Version

bitnami/postgresql-repmgr:14

What steps will reproduce the bug?

start the standard docker-compose.yml as: curl -sSL https://raw.githubusercontent.com/bitnami/containers/main/bitnami/pgpool/docker-compose.yml > docker-compose.yml docker-compose up -d log in into the postgres node by I get "could not get current user name":

docker exec -ti bitnami_orig_pg-0_1 /bin/bash I have no name!@cdeb06c71cd0:/$ /opt/bitnami/repmgr/bin/repmgr node status could not get current user name: Success I have no name!@cdeb06c71cd0:/$

If I try to add the user: root attribute to the config, the container does not start.

What is the expected behavior?

The commands within the container are usable to learn, interact, monitor the SW.

What do you see instead?

The commands within the container are not usable:

I have no name!@cdeb06c71cd0:/$ psql psql: error: local user with ID 1001 does not exist

Additional information

No response

esanya avatar Jan 16 '23 14:01 esanya

Ok, by logging in into the container by:

docker exec -ti -u root bitnami_orig_pg-0_1 /bin/bash I'm at least root, and can create other users...

esanya avatar Jan 16 '23 14:01 esanya

By executing the commands:

  • useradd -m -G root postgres
  • chmod -R g+r /bitnami/postgresql/data/
  • chmod -R g+x /bitnami/postgresql/data/

The /opt/bitnami/repmgr/bin/repmgr node status commands works

esanya avatar Jan 16 '23 14:01 esanya

Hi @esanya,

Sorry for the delay. Unfortunately, this is a bug, but it is cosmetic. You can connect to the database like this:

$ docker-compose exec -- pg-0 bash
I have no name!@17ff42f5556b:/$ psql -U customuser -d customdatabase
Password for user customuser: 
psql (14.6)
Type "help" for help.

customdatabase=> \l
                                       List of databases
      Name      |   Owner    | Encoding |   Collate   |    Ctype    |     Access privileges     
----------------+------------+----------+-------------+-------------+---------------------------
 customdatabase | customuser | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/customuser           +
                |            |          |             |             | customuser=CTc/customuser
 postgres       | postgres   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 repmgr         | postgres   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0      | postgres   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres              +
                |            |          |             |             | postgres=CTc/postgres
 template1      | postgres   | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres              +
                |            |          |             |             | postgres=CTc/postgres
(5 rows)

If you have solved the problem, please let me know. Feedback is appreciated. Thanks for your report.

CeliaGMqrz avatar Feb 01 '23 15:02 CeliaGMqrz

This Issue has been automatically marked as "stale" because it has not had recent activity (for 15 days). It will be closed if no further activity occurs. Thanks for the feedback.

github-actions[bot] avatar Feb 17 '23 01:02 github-actions[bot]

Due to the lack of activity in the last 5 days since it was marked as "stale", we proceed to close this Issue. Do not hesitate to reopen it later if necessary.

github-actions[bot] avatar Feb 22 '23 01:02 github-actions[bot]

this issue still seems to be open and unsolved. i just deployed fresh containers and have the same issue - you cannot exec "repmgr" due to the uid 1001 being used but no system entry for that user present. a temporary workaround is, like @esanya wrote, to create such a user inside the container:

root@id1:~/active/pgtest# docker compose exec -uroot pg-1 bash
root@5e2dfd4c19b4:/# useradd -u 1001 -m -G root postgres
root@5e2dfd4c19b4:/# exit

this will let you exec repmgr like so: root@id1:~/active/pgtest# docker compose exec pg-1 repmgr -f /opt/bitnami/repmgr/conf/repmgr.conf node status

that, or a similar, useradd should definitely be part of the Dockerfile that creates the image....... please fix :) thanks & regards, Markus

mrambossek avatar Mar 20 '23 19:03 mrambossek

Hi,

What we currently do in the container is to enable nss_wrapper to allow this kind of operations.

. /opt/bitnami/scripts/postgresql-env.sh
. /opt/bitnami/scripts/libpostgresql.sh
postgresql_enable_nss_wrapper

With that you should be able to execute the commands without issues.

javsalgar avatar Mar 21 '23 08:03 javsalgar

this issue definitely isn't solved. i just re-deployed stuff and am exactly in the same position as last time. as a workaround i implemented what @javsalgar wrote.. like this

file "wrapper-repmgr" - make sure to chmod +x:

#!/bin/bash

. /opt/bitnami/scripts/postgresql-env.sh
. /opt/bitnami/scripts/libpostgresql.sh
postgresql_enable_nss_wrapper
repmgr -f /opt/bitnami/repmgr/conf/repmgr.conf $*

in docker-compose.yml, for all relevant services, add the script as a file-volume:

volumes:
  - ./wrapper-repmgr:/opt/bitnami/repmgr/bin/wrapper-repmgr

now you can use a "launcher script" like "repmgr_node1":

#!/bin/bash

docker compose exec node1 wrapper-repmgr $*

.. not great. would be better to have it fixed in the container - as it is clearly a bug.

mrambossek avatar Jun 28 '23 09:06 mrambossek

Hi @mrambossek,

Thanks for your comments.

Unfortunately, this behavior is expected because the container is designed to work with any possible user ID. So it does not save the information of a specific user. For that particular use case you would need that additional configuration that my colleague mentioned because repmgr reads user information and NSS_WRAPPER solves this problem. Anyway you can always customize the image from the Dockerfile, adding the user you need in this specific case.

CeliaGMqrz avatar Jul 19 '23 11:07 CeliaGMqrz

This Issue has been automatically marked as "stale" because it has not had recent activity (for 15 days). It will be closed if no further activity occurs. Thanks for the feedback.

github-actions[bot] avatar Aug 04 '23 01:08 github-actions[bot]

Due to the lack of activity in the last 5 days since it was marked as "stale", we proceed to close this Issue. Do not hesitate to reopen it later if necessary.

github-actions[bot] avatar Aug 09 '23 01:08 github-actions[bot]

executing a command directly does not load the nss_wrapper configuratino. try with the following command that will load the nss_wrapper configuration:

kubectl exec -it <pod-name> /opt/bitnami/scripts/postgresql-repmgr/entrypoint.sh repmgr --help

see : [bitnami/postgresql-ha] Cannot run repmgr CLI successfully #3558

CodeRusher avatar Mar 06 '25 09:03 CodeRusher