Run a database in a Docker container
You can use Docker to run a database container and test how your application interacts with it. This tutorial describes how to run a Docker container with a PostgeSQL server and connect to it using IntelliJ IDEA.
Pull a PostgreSQL server image
- In the Docker tool window, right-click the Images node, and then click Pull image.
- In the Pull Image dialog, select the default Docker Hub registry and specify the PostgreSQL server image repository name and tag (
- Click OK and wait until the image is pulled.
Run a container from the PostgreSQL server image
- In the Docker tool window, right-click the PostgreSQL server image and then click Create container.
- In the Create container popup, click Create.
- In the Create Docker Configuration dialog, specify the name of the container, select All to publish all exposed container ports to the host interfaces, and click Run.
Connect to the PostgreSQL server
- Open the Database tool window ( ).
- Click New (), point to Data Source, and then click PostgreSQL.
- Set the host name to
localhost, port to
5432, default database and user to
postgres. No password is required by default.
- If necessary, download the driver and test the connection.
- Click OK to add the PostgreSQL server as a data source
For more information about working with database sources in IntelliJ IDEA, see Databases and SQL.