Skip to content

Use Docker with CLion

Julian Menzler edited this page Apr 26, 2020 · 5 revisions

Developing with Docker and CLion

For performance reasons, we do not recommend you to develop with Docker containers. However, you might run into trouble with unsupported OS versions. Also, some of you might want to avoid installing dependencies on their systems. In these cases, a Docker development setup can make sense.

Supported hosts

Currently, we can assure this tutorial works for Linux-based hosts. (e.g. Ubuntu 20.04 w/ Clion 2020.1) Although it should work, we experienced compilation errors when using a macOS host system. In terms of Windows-based hosts, we have not experience yet. So please tell us about your results, if you try it yourself.

Using CLion

CLion offers several remote development capabilities, which can be used to interact with Docker containers. Although running on the same host, the Docker container is treated as a remote instance. CLion controls it using the ssh protocol.

Setup guide

  1. Create a working directory which to hold the project.
  2. Clone Hyrise into it using git clone.
  3. cd into it and use git submodule update --init --recursive to fetch the project's dependencies.
  4. Build a Docker image using docker build . -t hyrise (in project root)
  5. Run a container from the image using docker run -itd --cap-add sys_ptrace -p 2222:22 --name hyrise_dev_env hyrise sleep infinity

Now that we have a basic container for compiling Hyrise running (with the name hyrise_dev_env), we have to set up SSH. Type in the following commands:

docker exec -it hyrise_dev_env mkdir /root/.ssh
docker exec -it hyrise_dev_env bash -c "echo $(cat ~/.ssh/id_rsa.pub) > /root/.ssh/authorized_keys"
docker exec -it hyrise_dev_env service ssh start

Start CLion and import the project from your working directory. In the following steps, we prepare CLion to interact with our Docker container.

  1. Go to File | Settings | Build, Execution, Deployment | Toolchains
  2. Click + Add and Remote Host
  3. Configure Credentials in the right pane (click the little gear icon) and enter the following details:
  • Host: localhost
  • Port: 2222
  • User name: root
  • Authentication type: OpenSSH config and authentication agent
  1. Click Test connection to ensure CLion is able to connect to the container. Click OK to close the SSH configurations-dialog.
  2. In the right pane, under CMake, a "Not found" message should show up. In this case, click the button with the three dots to locate the correct CMake binary. In our case it was located at /cmake-3.16.0/bin/cmake.

Next, we want to create a CMake profile to use our Docker-toolchain.

  1. Click CMake in the left sidebar of the preferences window.
  2. Create a new profile or change an existing one to use the Remote Host or Docker toolchain we created earlier.
  3. Add CMake options as required. For example, add -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
  4. Under Build options, you may want to add -j <number of cores> to speed up the compilation process later on.
  5. Close the settings by clicking OK

CLion should now transfer all the source code into the Docker container using rsync. Wait for the file transfer and the build files to be written. In the following, you should be able to select the CMake configuration in the toolbar at the top. Choose a build target, like for instance hyriseTest. Click the hammer icon or use the Build menu to initiate the compile process.

Restarting your system or Docker

In case the Docker container is stopped (check via docker ps -a), restart it using docker start hyrise_dev_env. You may want to automate the process using a different restart policy.

After restarting your container, you have to restart the SSH service as well. For this, use docker exec -it service ssh start. Feel free to automate this.


Credits to @ramboldio for bringing up this tutorial with #2081.

Clone this wiki locally