This guide explains how to connect CLion directly to your Docker development container using SSH.
- Docker container running with SSH server (port 2222)
- CLion installed on your local machine
# Build the container if you haven't already
./build.sh
# Start the container in daemon mode
./run.sh --daemon
This will:
- Start the container in the background
- Start the SSH server inside the container
- Map port 2222 on your host to port 22 in the container
- Clone the repository inside the container
- Open CLion
- Go to File > Settings > Build, Execution, Deployment > Toolchains
- Click the + button to add a new toolchain
- Select Remote Host
- Configure the connection:
- Name: Docker Container (or any name you prefer)
- Credentials: Click New
- Host: localhost
- Port: 2222
- Username: root
- Password: root
- Authentication type: Password
- Click Test Connection to verify it works
- Click OK
- Wait for CLion to detect tools in the remote environment
- Make sure CMake, GDB, Compiler, etc. are detected
- Go to File > Settings > Build, Execution, Deployment > Bazel Settings
- Enable the Bazel plugin if it's not already enabled
- Configure Bazel:
- Bazel binary location: /usr/local/bin/bazel
- Bazel sync on project open: Enabled
- Use project view file: Disabled (or configure if needed)
- Go to File > Open
- In the dialog that appears, select Open from Remote Host
- Select the SSH connection you created
- Navigate to
/workspace/test-dev-bazel
- Click OK
CLion will sync the project files and configure Bazel. Once it's done, you should be able to build and run the project directly from CLion.
If you have trouble connecting via SSH:
-
Verify the container is running:
docker ps | grep test-dev-container
-
Check if SSH server is running inside the container:
docker exec test-dev-container service ssh status
-
Test SSH connection from terminal:
ssh -p 2222 root@localhost
If CLion doesn't properly detect Bazel:
-
Make sure the Bazel binary exists in the container:
docker exec test-dev-container which bazel
-
Verify Bazel works in the container:
docker exec test-dev-container bazel version
-
Manually set the Bazel binary path in CLion settings to
/usr/local/bin/bazel