DataGrip 2025.1 Help

Run the PostgreSQL Sakila database in a Docker container

Install the Docker plugin

This functionality relies on the Docker plugin, which you need to install and enable.

  1. Press Ctrl+Alt+S to open settings and then select Plugins.

  2. Open the Marketplace tab, find the Docker plugin, and click Install (restart the IDE if prompted).

Starting a project

Create a Go project

  1. Select File | New | New Project.

    Alternatively, click New Project in the Welcome to DataGrip dialog.

  2. In the New Project dialog, select New project from the list of available project types.

    Ensure that Go is selected as the project language in the Language list.

  3. In the GOROOT field, specify the location of your Go installation. DataGrip usually detects this location automatically.

    To change or install a new Go SDK version, click Add SDK (Add SDK icon) and choose one of the following options:

    • Local: to use an existing SDK from your local system.

    • Download: to download a Go SDK version from the official repository.

  4. Click Create to create the project.

Create a Go file

  1. To create a Go file, use one of the following options:

    • In the Project tool window, right-click the parent folder of your project and select New | Go FileGo File.

    • Click the parent folder of your project, press Alt+Insert, and select Go File.

    • Click the parent folder of your project, then go to File | New | Go File.

  2. In the New Go File dialog, enter a file name and choose the file type:

    • Empty file — creates an empty Go file.

    • Simple application — creates a Go file with a predefined main function.

Clone files from repositories

For this example, we will use the following two repositories: the Sakila dump files (https://github.com/DataGrip/dumps) and a Docker Compose file (https://github.com/DataGrip/datagrip-documentation). The Sakila repository includes SQL scripts to create and populate the Sakila sample database. The Docker repository contains YAML files that define services, networks, and volumes.

Clone repositories

  1. Select View | Tool Windows | Terminal or press Alt+F12.

  2. In the terminal, run the following commands:

    git clone https://github.com/DataGrip/dumps.git
    git clone https://github.com/DataGrip/datagrip-documentation.git

    Two new folders for the cloned repositories will appear in the Project tool window.

Run a Docker container

In this tutorial, we will run a PostgreSQL container using Docker, based on the datagrip-documentation repository. Inside the repository's Docker directory, you will find the .env and docker-compose.yml files. The .env file contains credentials for the PostgreSQL service. The docker-compose.yml file defines how the service is created and configured.

The service name appears on the first line of the service definition, above the JDBC URL. In our example, the service name is postgresql_12, and the JDBC URL is: jdbc:postgresql://localhost:54333/guest?user=guest&password=guest

postgresql_12: # jdbc:postgresql://localhost:54333/guest?user=guest&password=guest container_name: postgresql_12 ports: - "54333:5432" image: postgres:12-alpine env_file: .env healthcheck: test: "exit 0"

To run the container from the command line, use the following command:

docker-compose up -d postgresql_12

Make sure to navigate to the directory that contains the docker-compose.yml file before running the command.

Alternatively, you can enable and use the Docker plugin in DataGrip.

Connect to the Docker daemon

  1. Press Ctrl+Alt+S to open settings and then select Tools | Build | Docker.

  2. Click The Add button to add a Docker configuration and specify how to connect to the Docker daemon.

    The connection settings depend on your Docker version and operating system.

    The Connection successful message should appear at the bottom of the dialog.

    The Docker connection settings

    For more information about mapping local paths to the virtual machine running the Docker daemon when using Docker on Windows or macOS, refer to Virtual machine path mappings for Windows and macOS hosts. You will not be able to use volumes and bind mounts for directories outside of the mapped local path.

    This table is not available on a Linux host, where Docker runs natively and you can mount any directory to the container.

  3. Open the Services tool window (View | Tool Windows | Services or Alt+8), select the configured Docker connection node Docker node and click The Connect button, or select Connect from the context menu.

    The Services tool window, connected to Docker

    To edit the Docker connection settings, select the Docker node and click The Edit Configuration button on the toolbar, or select Edit Configuration from the context menu.

    You can also click the Add Service menu and select Docker Connection to add a Docker connection directly from the Services tool window. If you have Docker contexts configured, you can select Docker Connections from Docker Contexts to add the corresponding connections.

Create the Docker compose run configuration

  1. (Optional) Right-click the main toolbar and select Add to Main Toolbar | Run Widget. For more information about adding widgets to the main toolbar, refer to Quickly add actions to the toolbar.

  2. Open the Run/Debug Configurations dialog by doing one of the following:

    • Go to Run | Edit Configurations. Alternatively, press Alt+Shift+F10, then 0.

    • Click the Run Widget on the main toolbar and select Edit Configurations.

  3. In the Run/Debug Configurations dialog, click the Add New Configuration icon (the Add New Configuration icon) and select Docker | Docker Compose.

  4. In the Name field, type the name of your configuration.

  5. Click the Browse icon of the Compose files field.

  6. In the Docker Compose Configuration Files dialog, click the Add button and navigate to the compose file. The Compose YAML file defines services, networks, and volumes. In our case, it is docker-compose.yml

  7. In the Docker Compose Configuration Files dialog, click OK.

  8. Click Modify in the docker compose up separator and select Recreate containers | None.

  9. In the Services field, type postgresql_12.

  10. Click Run.

    Create the Docker compose configuration

As a result, you can see the postgresql_12 running container in the Services tool window.

The Docker compose configuration in Services tool window

Connect to a data source

Depending on the database vendor (MySQL, PostgreSQL, Oracle), you need to create a corresponding data source connection. In this tutorial, we will create a PostgreSQL connection. If you want to connect to a different database management system (DBMS), refer to Create a data source.

  1. Open data source properties. You can open data source properties by using one of the following options:

    • Navigate to File | Data Sources....

    • Press Ctrl+Alt+Shift+S.

    • In the Database Explorer ⌘ 1 (View | Tool Windows | Database Explorer), click the Data Source Properties icon (The Data Source Properties icon).

    Add new data source
  2. In the Data Sources and Drivers dialog, click the Add icon (The Add icon) and select PostgreSQL.

  3. Check if there is a Download missing driver files link at the bottom of the connection settings area. Click this link to download drivers that are required to interact with a database. For a direct download link, refer to the JetBrains JDBC drivers page.

    The Download missing driver files link

    Location for the downloaded JDBC drivers is the DataGrip configuration directory.

    You can also use your drivers for the database instead of the provided ones. For more information about connecting to a database with your driver, refer to Add a user driver to an existing connection.

    If there is no Download missing driver files link, then you already have the required drivers.

  4. In the URL field, paste the following JDBC URL:

    jdbc:postgresql://localhost:54333/guest?user=guest&password=guest

    You can find JDBC URLs for other DBMSs in the docker-compose.yml file. Open the file in a text editor to review available connection details.

  5. (Optional) In the Name field, enter a custom name for the connection (for example, PostgreSQL).

  6. Ensure that the database connection can be established using the provided details. To do this, click the Test Connection link at the bottom of the connection details section.

    Test Connection link

    If you encounter any connection issues, refer to the Cannot connect to a database page.

  7. (Optional) By default, only the default database and schema are introspected and available to work with. If you also want to work with other databases and schemas, in the Schemas tab, select them for the introspection.

    Schemas tab of the Data Sources and Drivers dialog
  8. Click OK to create the data source.

Successful test connection to the PostgreSQL data source

Attach a directory to the project

To run dump files from the project in DataGrip, attach a directory with dump files.

  1. You can open the Files tool window by doing one of the following:

    • In the main menu, go to View | Tool Windows | Files.

    • On the right tool window bar, click Files tool window icon Files.

    • Press Alt+2.

  2. In the Files tool window , click the Attach Directory to Project button (Attach Directory to Project) in the toolbar.

    Alternatively, right-click in the area of the Files tool window and select Attach Directory to Project.

  3. In the file browser, navigate to the directory that you want to attach. In our case, it is the dumps directory.

  4. Click Open.

Directory with dump files is attached to the DataGrip project

Run the dump files

Create the database structure

  1. In the Files (View | Tool Windows | Project) tool window, navigate to dump/postgres-sakila-db/postgres-sakila-schema.sql.

  2. Right-click postgres-sakila-schema.sql and select Run postgres-sakila-schema.sql. Alternatively, open the file and press Ctrl+Shift+F10.

  3. In the Edit Configuration dialog, click the Add button in the Target data source/schema pane and select PostgreSQL.

  4. Click Run to execute the script.

    Database structure dump file run configuration

Load sample data into the database

  1. In the Files (View | Tool Windows | Project) tool window, navigate to the dump/postgres-sakila-db directory.

  2. Expand the postgres-sakila-db directory.

  3. Right-click postgres-sakila-insert-data.sql and select Run postgres-sakila-insert-data.sql. Alternatively, open the file and press Ctrl+Shift+F10.

  4. In the Edit Configuration dialog, click the Add button and select PostgreSQL.

  5. Click Run to execute the script.

Insert data dump file run configuration

Work with your database

Once the structure is imported and the database is populated with data, you can start working with it.

  • For more information about working with database objects in DataGrip, refer to Database objects.

  • To write and run queries, open the default query console by clicking the data source and pressing F4.

  • To view and edit data of a database object, open Data editor and viewer by double-clicking the object.

PostgreSQL database is running in Docker container
Last modified: 15 April 2025