PyCharm 2022.1 docker.errors.InvalidArgument: "host" network_mode is incompatible with port_bindings

My docker-compose file

version: "3"

image: python:3.9-slim
container_name: python
network_mode: "host"

My operating system is Ubuntu 22.04

I am using VPN to connect to AWS RDS service and I want to share host network with the container. I am getting an error when I wan to use PyCharm debugger.

How can I solve this issue?




A bit more information about your environment would help to reproduce/identify the issue. Where is the docker daemon located? How do you connect to it?



Thanks for your effort, I really need a help. If you need any kind of information, just say it and will send to you ;)

The output of docker info command is below:

 Context:    default
 Debug Mode: false
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Docker Buildx (Docker Inc., v0.8.2-docker)
  compose: Docker Compose (Docker Inc., v2.6.0)
  scan: Docker Scan (Docker Inc., v0.17.0)

 Containers: 5
  Running: 2
  Paused: 0
  Stopped: 3
 Images: 52
 Server Version: 20.10.17
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc version: v1.1.2-0-ga916309
 init version: de40ad0
 Security Options:
   Profile: default
 Kernel Version: 5.15.0-43-generic
 Operating System: Ubuntu 22.04.1 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 30.59GiB
 Name: CN-PC26L5MH
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
 Live Restore Enabled: false

Setting an interpreter in PyCharm

File --> Settings




When I add a local compose interpreter using your Dockerfile...

image: python:3.9-slim
container_name: python
network_mode: "host"

... and run a simple for loop for the test...

from time import sleep

for i in range(10):
print(i) # BREAKPOINT

The debugger is working and I can stop at the breakpoint.

Could you please try this simple test as well? Does the issue reproduce? If so, please provide a screenshot of your Docker settings from [Preferences | Build, Execution, Deployment | Docker]

Also, please test this in the latest Release Candidate build.


Thanks, It works! :) 

I would like to ask a little bit about running a python code as the module using a python interpreter. I'm getting an error and I want to ask how can I set up my environment without the script path? ;) 





You can specify module name instead of script path, see the first parameter in 


Thanks, it helped. The error message disappeared but breakpoint doesn't work. When I tried to run my module using the debugger, the PyCharm didn't stop at the specified breakpoint. 


Is it possible to create a minimal project sample to reproduce the issue? Either way, I suggest reporting this issue to with the following information:

-  Minimal project sample, if possible

- Please add `PYCHARM_DEBUG=True` environment variable to your run/debug configuration, reproduce the issue and provide the full debug console output

- Logs from **Help | Collect Logs and Diagnostic Data** 


Please sign in to leave a comment.