postgresqlHow can I use PostgreSQL in a Docker container?
PostgreSQL can be used in a Docker container by following the steps below:
- Pull the PostgreSQL Docker image from Docker Hub:
docker pull postgres
- Run the Docker container using the image:
docker run --name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
- Connect to the PostgreSQL instance:
docker exec -it some-postgres psql -U postgres
- Create a database:
CREATE DATABASE mydb;
- Create a user:
CREATE USER myuser WITH ENCRYPTED PASSWORD 'mypassword';
- Grant privileges to the user to access the database:
GRANT ALL PRIVILEGES ON DATABASE mydb TO myuser;
- Finally, exit the PostgreSQL instance:
\q
Helpful links
More of Postgresql
- How can Zalando use PostgreSQL to improve its software development?
- How can I monitor PostgreSQL performance using Zabbix?
- How can I use PostgreSQL with YAML?
- How can I use PostgreSQL with Zabbix?
- How can I retrieve data from PostgreSQL for yesterday's date?
- How do I use PostgreSQL's XMIN and XMAX features?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can I use PostgreSQL's "zero if null" feature?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
See more codes...