Configuring PyCharm with Docker for Remote Python Development
This tutorial explains how to set up PyCharm Professional with a Docker container on a remote server, enabling Python code editing, debugging, and synchronization via SSH/SFTP, and includes prerequisite checks, container creation, SSH configuration, deployment settings, and common troubleshooting tips.
This guide shows deep‑learning practitioners how to configure PyCharm Professional to use a remote Docker container as the Python interpreter, allowing seamless development and debugging on a server.
Prerequisites: PyCharm Professional, Docker and nvidia‑docker installed on the remote machine.
1. Create a Docker container using a command such as sudo nvidia-docker run -it -p 8022:8022 --name="liuzhen_tf" -v ~/workspace/liuzhen:/workspace/tf_workspace tensorflow/tensorflow:latest-gpu /bin/bash . Adjust ports, container name, image, and volume mappings as needed.
2. Configure SSH inside the container :
apt update<br/>apt install -y openssh-server<br/>mkdir /var/run/sshd<br/>echo 'root:passwd' | chpasswd<br/>sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config<br/>sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd<br/>echo "export VISIBLE=now" >> /etc/profile<br/>service ssh restart
Verify the host‑to‑container port mapping with sudo docker port <your_container_name> 22 (e.g., 0.0.0.0:8022) and test the SSH connection using ssh root@<host_ip> -p 8022 .
3. Set up PyCharm deployment : In Tools → Deployment → Configuration add a new SFTP server, enter the host IP, the mapped port (e.g., 8022), and the root path inside the container; test the connection.
4. Configure the remote interpreter : Open File → Settings → Project → Project Interpreter , add a new Docker‑based interpreter pointing to the container, and select the appropriate Python executable.
After these steps, PyCharm synchronizes local files with the remote container, allowing you to edit locally and run/debug remotely. Use the Deployment → Upload action to push changes, and avoid editing directly inside the container to prevent version‑control conflicts.
Common issues : The SSH service stops when the container stops—restart it with service ssh restart or add --restart=always to the Docker run command. Apt‑update may hang; install apt-transport-https matching the container’s apt version.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.