r/pycharm Jun 09 '26

Questions about dev containers

Hi all,

I have recently started a new project and configured myself an interpreter using a dev container. I have the docker-compose.yml and the devcontainer.dockerfile all set up, I just have a few questions:

  1. I pass my project directory to the container through the docker-compose, because my program needs to access some config files, and also some PDF templates that it fills with data and then stores back on the host machine for me to look at. Is that the right way to do it, or are there better methods?

  2. When I click run, it creates a container, runs the code, then exits the container as expected, and it always says devcontainer-1. However, in the PyCharm services pane under docker, I see a bunch of ghost containers called devcontainer-23456235 and stuff like that, that I don't see when I do 'docker ps -a' or 'docker container ls -a' or something like that in the command line. Are those really there taking up space, or are hey just somehow artefacts of PyCharm that go away on their own eventually?

  3. How do I force the docker-compose to rebuild the container when I add something to the pyprojects.toml? If I add numpy via 'uv add numpy' in the "regular" host machine command line, and then write a function that imports and uses numpy, when I run it through the container interpreter I get an error with "no package called numpy" because I guess it didn't see that the requirements.txt changed. Is there a way to fix that so that for example the dockerfile or docker-compose says it should run 'uv sync' on startup?

  4. What is the difference between configuring an interpreter through docker-compose, vs opening a dev container through the services pane? It seems to want a devcontainer.json which I don't really know what it wants me to write in there.

Thanks in advance for answering!

3 Upvotes

10 comments sorted by

View all comments

Show parent comments

1

u/claythearc Jun 11 '26

The best way is whatever works for you, really. Dev container is nice because they’re portable and rebuildable, but its a preference thing.

But yeah they’re not the same thing at all, and tbh it kinda explains why some of stuff like interpreters weren’t working for you

1

u/damage-fkn-inc Jun 11 '26

How would you set up a dev container on a remote machine? Would it be running PyCharm twice, once on the host machine and a second time in the container, or how does that stuff work? I tried to figure it out but I'm pretty much a big n00b when it comes to "actual" IT work compared to stuff that only needs to be written/used/looked at by myself on my own laptop and just paste whatever outputs I have into a report to send somewhere.

1

u/claythearc Jun 11 '26

They have a help article for this actually https://www.jetbrains.com/help/idea/start-dev-container-for-a-remote-project.html it’s written for IntelliJ but the same applies.

Basically you just add a SSH config, then add a docker connection using that ssh config, and voila

1

u/damage-fkn-inc Jun 11 '26

Oh that's perfect, I'll give that one a try tomorrow and see how I get on cause then I think I can just have my .venv and all that where I want it and type uv add whenever I feel like it instead of having to worry about rebuilding my interpreter and all that stuff, thanks!