IntelliJ IDEA 2018.1 Help

Run a database in a 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.

  1. Pull 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 (postgres and latest).
    • Click OK and wait until the image is pulled.
  2. Run 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.
  3. Connect to the PostgreSQL server
    • Open the Database tool window (View | Tool Windows | Database.
    • Click New (The New button), point to Data Source, and then click PostgreSQL.
    • Set the host name to localhost, port to 5432, default database and user names 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.

Last modified: 24 July 2018