how to change Postgresql docker image password - postgresql

I have created a Postgresql docker image using the following command on Windows:
docker run --name airdb-postgres -e POSTGRES_PASSWORD=post1234 -d -p 5432:5432 postgres:alpine
is it possible to change the password I assigned to it, or I should create a new one by disposing this image?

You should be able to do that by logging into the container
docker exec -it <container_id> bash
then use psql cli to change the password.
See How to change PostgreSQL user password? for the latter part.

Related

psql command from official page on dockerhub

I am learning Docker. I have practiced a lot, including testing commands from the official Postgres page on dockerhub.
I ran this command:
docker run -it --rm --network some-network postgres psql -h some-postgres -U postgres
Could someone give a complete and concrete example to make this command work (i mean with a real existing container). I can't see how it could work.
docker run create a docker container
-it create a connection to said container (kinda like TTY) taking in what we write into interactive bash in the container
--rm delete the container when it exit
--network some-network assign some-network network to the container
postgres name of the image
psql -h some-postgres -U postgres connect to PostgreSQL at some-postgres address using postgres user.
Combine the entire command and flags: create a PostgreSQL container and the use the psql command from inside the container to connect to some-postgres using postgres user
For more flags and usage, you can learning from the doc here
Probably, in the Docker hub page is not perfectly clear but your command is used to connect to an already existing Postgres instance.
So, for example, you first create a container with the command:
docker run -it --rm --name postgresql -p 5432:5432 -e POSTGRES_USER=admin -e POSTGRES_PASSWORD=admin -d postgres:latest
then you can execute your command to connet to it
docker run -it --rm postgres psql -h <your_ip> -U postgres
If your container is running locally, you can get the ip from the bash command ip address
The network attibute is related to the container you first startup so you can decide to leave or remove from the command in relation to the container deploy.

Attempt to connect from SpringBoot to docker-postgres failed

I have created a docker container based on a postgres image.
Which I try to connect to from a Spring Boot application with no success.
The user is 'postgres', and the password 'password'.
(I don't have anything from Docker Compose, nor do I know if it's necessary.)
I would appreciate any help
Finally solved:
Remove all previous containers.
Create new container. This time using port 5433 and expecifying the postgres user.
docker run --name container-postgres-1 -p 5433:5432 -v "C:\volumen-docker-1:/var/lib/postgresql/data" -e POSTGRES_PASSWORD=password -e POSTGRES_USER=postgres -d postgres:13.9-alpine3.17
Create the database bootifyone.
docker exec -it container-postgres-1 bash
psql -h localhost -p 5432 -U postgres
CREATE DATABASE bootifyone;
Using this connection URL in the application.properties:
spring.datasource.url=jdbc:postgresql://localhost:5433/bootifyone

Install Postgis in docker container

I created a database with docker using the postgres image as usual
docker run -d \
--name some-postgres \
-e POSTGRES_PASSWORD=mypassword \
-v ${HOME}/postgres-data/:/var/lib/postgresql/data \
-p 5432:5432 \
postgres
now I decided to add a new column in one of the tables to store coordinates using postgis, however when I do
CREATE EXTENSION postgis;
or something similar I get this error message:
ERROR: could not open extension control file "/usr/share/postgresql/12/extension/postgis.control": No such file or directory
is there an additional step one has to take before running the docker container in order to install postgis?
thanks a lot
The postgis extension does not come with vanilla postgres, which does ship with a whole bunch of more general purpose extensions, though nothing notable for geospatial. Take a look at this instead: https://registry.hub.docker.com/r/postgis/postgis/
I know that there is already a response but this could help someone
Firstly you should already have a Postgres image and after a postgres docker container running .
link 2
After you should have the POSTGIS DOCKER IMAGE
[voir ici] : https://hub.docker.com/r/kartoza/postgis/
The image below shows my config after all these steps
After you should stop the running container of postgres which was running at port 5432 for me
this could help: https://blog.eduonix.com/software-development/learn-stop-kill-clean-docker-containers/#:~:text=To%20stop%20a%20container%20you,the%20killing%20is%2010%20seconds.
Now we can create the container that is going to link our postgres container with our postgis Extension
sudo docker run -d --name postgis_postgres -e POSTGRES_PASSWORD=postgrespassword -e POSTGRES_USER=postgres -v /home/judith/Documents/postgres/db-data/:/var/lib/postgresql/data -p 8000:8000 kartoza/postgis:9.6-2.4
Here /home/judith/Documents/postgres/db-data/ is the path to the database data of postgres container
Now we can enter in the running container created at the step 5 with the command
judith#jlas:~$ sudo docker exec -it postgis_postgres bash
root#544c89fadeda:/# //you will be there
Write the command that is going to link to the postgres console admin , here
the 5432 is port where my postgres container was running and postgres is the admin of my postgres in my config , you will config the database admin in the step 1 do not worry .
root#544c89fadeda:/# psql -h localhost -p 5432 -U postgres
After you can create you POSTGIS EXTENSION
postgres=# CREATE EXTENSION postgis;
CREATE EXTENSION
postgres=#

Docker postgres container

I have a bare bones postgres container that I can launch no problem using:
docker run -it --rm -v /home/ec2-user/secrets:/mnt/secrets -v demo-postgres:/var/lib/postgresql/data demo-postgres
How do I get to an interactive psql prompt such that i can create a db, add table, values, ect?
I usually separate running container in detached mode and execing into it using psql:
docker run -d -e POSTGRES_PASSWORD=your_password --name pgl postgres:latest
docker exec -it -u postgres pgl psql

can't run docker image of jhipster webapp

I have a jhipster monolithic web app with postgress database. I built a docker image using
./gradlew bootRepackage -Pprod buildDocker
Now when I try to run the image using docker run , it fails with following error.
Caused by: org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:247)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:65)
I tried few things like, but still get the same error:
docker create -v /var/lib/postgresql/data --name spring_app_data postgres:9.5.1
docker run --volumes-from spring_app_data --name spring_app_pg -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -d -P postgres:9.5.1
docker run -it --link spring_app_pg:postgres --rm postgres sh -c 'exec psql -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres'
docker run --name spring_app_container --link spring_app_pg:spring_app_pg -p 8080:8080 -d wmd_server_pg
Any suggestions on how to run the docker image for a webapp with PostgreSQL. BTW I get same kind of error when I use mongodb.
Going by your example commands your database won't be accessible as localhost from the app, it will be via the named container. Configure your apps database connection to use spring_app_pg:5432.
Also, don't use links. Use a user defined network, most likely a bridge is all you will need.
docker network create my_app
docker run --net=my_app --name=spring_app_pg <dbimage>
docker run --net=my_app --name=spring_app_container <appimage>
That should give you the same result as your linked setup.