IntelliJ IDEA 2018.2 Help

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

  1. In the Docker tool window, right-click the Images node, and then click Pull image.
  2. In the Pull Image dialog, select the default Docker Hub registry and specify the PostgreSQL server image repository name and tag (postgres and latest).
  3. Click OK and wait until the image is pulled.

Run a container from the PostgreSQL server image

  1. In the Docker tool window, right-click the PostgreSQL server image and then click Create container.
  2. In the Create container popup, click Create.
  3. 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

  1. Open the Database tool window (View | Tool Windows | Database).
  2. Click New (The New button), point to Data Source, and then click PostgreSQL.
  3. Set the host name to localhost, port to 5432, default database and user to postgres. No password is required by default.
  4. If necessary, download the driver and test the connection.
  5. 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: 14 June 2018