Closed Chr15t0pher closed 7 months ago
I just tried this and I was able to connect. Maybe there is an issue with your docker networking. What do you get if you run docker ps
?
I just tried this and I was able to connect. Maybe there is an issue with your docker networking. What do you get if you run
docker ps
?
I tried to run docker ps
, it worked as i expected, i got the activated containers.
docker ps --filter 'name=postgres' --format '{{.ID}}'
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bdb2469f4a82 postgres "docker-entrypoint.s…" 4 minutes ago Up 4 minutes 0.0.0.0:5432->5432/tcp postgres_1698292090
I thought after running
docker run \ --name "postgres_$(date '+%s')" \ -e POSTGRES_USER=${DB_USER} \ -e POSTGRES_PASSWORD=${DB_PASSWORD} \ -e POSTGRES_DB=${DB_NAME} \ -p "${DB_PORT}":5432 \ -d \ postgres -N 1000
, i should manually set $DB_USER. Then, i tried to modify the script like this:
docker run \
--name "${RUNNING_POSTGRES_CONTAINER}" \
-e POSTGRES_USER=${DB_USER} \
-e POSTGRES_PASSWORD=${DB_PASSWORD} \
-e POSTGRES_DB=${DB_NAME} \
-p "${DB_PORT}":5432 \
-d \
postgres -N 1000
sleep 5
docker exec -it $RUNNING_POSTGRES_CONTAINER psql -U $DB_USER -d $DB_NAME -c "CREATE USER $DB_USER WITH PASSWORD '$DB_PASSWORD';"
However, it reports : ERROR: role "admin" already exists
.
I just tried this and I was able to connect. Maybe there is an issue with your docker networking. What do you get if you run
docker ps
?
According to https://stackoverflow.com/questions/11919391/postgresql-error-fatal-role-username-does-not-exist, maybe i must use the system user postgres
to init database?
The user is successfully created. Do you have postgres installed locally as well? I am wondering if your script isn't connecting to your container postgres but another one.
The user is successfully created. Do you have postgres installed locally as well? I am wondering if your script isn't connecting to your container postgres but another one.
Yes, i have installed locally. But i did not start local postgres, i just use the psql
as a tool to connect to the postgres container.
I'm a totally newbie, trying to using a shell script to run postgres image. Here is my code:
The errors I've been able to see are:
What am I missing and how can I fix this so I can actually proceed with Postgres? When i set DB_USER to the default value
postgres
, it is Ok. But i just don't know the reason.