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.
2
Answers
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
assignsome-network
network to the containerpostgres
name of the imagepsql -h some-postgres -U postgres
connect to PostgreSQL atsome-postgres
address usingpostgres
user.Combine the entire command and flags: create a PostgreSQL container and the use the
psql
command from inside the container to connect tosome-postgres
usingpostgres
userFor 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:
then you can execute your command to connet to it
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.