Skip to content

Instantly share code, notes, and snippets.

@FernandoCutire
Last active January 27, 2022 16:22
Show Gist options
  • Save FernandoCutire/9ae919683a0b2c8b54108259961c46c2 to your computer and use it in GitHub Desktop.
Save FernandoCutire/9ae919683a0b2c8b54108259961c46c2 to your computer and use it in GitHub Desktop.

Run a docker container

Run the container with volume and network

Remember to create the network first

docker network create db

Then create the postgres

docker run --name db \ -p 5432:5432 --network=db \ -v "$PWD:/var/lib/postgresql/data" \ -e POSTGRES_PASSWORD=password \ -d postgres:alpine

Easy copy directly to the terminal

docker run --name srna-db -p 5432:5432 --network=db -v "$PWD:/var/lib/postgresql/data" -e POSTGRES_PASSWORD=password -d postgres:alpine

Running psql

This one is good for checking our database from the terminal, remember to change the network for the name of your network also the name db for the name of your postgres database container.

docker run -it --rm --network=db postgres:alpine \ psql -h db -U postgres

Easy copy directly to the terminal

docker run -it --rm --network=db postgres:alpine psql -h db -U postgres

Check the map

$ docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment