Last active
January 4, 2026 20:00
-
-
Save jligerofleitas/a6055f6881fec487f8efc9791acc2282 to your computer and use it in GitHub Desktop.
Import SQL file to PostgreSQL in container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Single quotes are relevant to delay expansion to be executed in container shell session | |
| # 1. using docker exec: | |
| cat /path/to/file.sql | docker exec -i <running postgres container name> \ | |
| bash -c 'PGPASSWORD=${POSTGRES_PASSWORD} psql -U ${POSTGRES_USER} -d ${POSTGRES_DB}' | |
| # 2. using docker compose exec | |
| cat /path/to/file.sql | docker compose exec -i <service name in docker-compose.yml> \ | |
| bash -c 'PGPASSWORD=${POSTGRES_PASSWORD} psql -U ${POSTGRES_USER} -d ${POSTGRES_DB}' | |
| # You can also use `docker compose exec`: | |
| # docker compose exec -i <service name in docker-compose.yml> bash -c '...' < /path/to/file.sql |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment