Reputation: 106
Is there a way to use the psql command from docker on my terminal host? I am using a postgresql 11 container, but to access psql I have to install a postgres on the host machine.
My docker file has just one line:
FROM postgres:11
How can I use the command above without install postgresql on host machine:
psql -c "CREATE DATABASE test_db WITH encoding 'UTF-8'" -h localhost -U postgres
I will use this command on bash scripts
Upvotes: 0
Views: 72
Reputation: 5547
psql
is already in the container, so you don't need to install it. You can use following command to invoke psql
docker exec <<container name>> psql -c "CREATE DATABASE test_db WITH encoding 'UTF-8'" -h localhost -d <<database>> -U <<user>>
The database and user will depend on the environment variables POSTGRES_DB
and POSTGRES_USER
that you had configured when you ware starting the container
Upvotes: 1