1

I've created a Docker Image in order to be able to run a Docker Container with some services like gcloud datastore. If I run my application using my local packages I can connect to that container without any problem and access to the service.

However, if a try to use docker as an interpreter in Pycharm I cannot access to the service. The application works fine but Pycharm creates a new container that I'm not able to link with the one I created before. Is there any way of avoiding Pycharm creating a new container and using mine instead? If not, is there a way of modifying the container that Pycharm creates in order to be able to link it?

The whole point is to achieve to have a complete development environment included in a container and be able to run it without further installation.

anmarlea
  • 370
  • 1
  • 3
  • 11
  • I am not sure about what you want to link the container with. Can you explain more about that ? Also, could you run the `docker inspect` command on the container created by PyCharm ? It might be a network thing. – Faeeria Mar 25 '21 at 14:06
  • When using docker as an interpreter Pycharm creates a new container and runs the application on it. However, as this new container is not linked with mine, the application cannot connect to the service. After running `docker inspect` it pops up a lot of info, it does have NetworSettings but also python/pycharm environment variables and a lot more of stuff. – anmarlea Mar 25 '21 at 14:32
  • Okay. So you are trying to connect to an external gcloud datastore, correct ? – Faeeria Mar 25 '21 at 14:36
  • Exactly. I can connect using my local environment setup but I cannot do so if I try using a docker (with all the required packages) as an interpreter. – anmarlea Mar 25 '21 at 14:43
  • I see. What kind of error do you get in your app ? – Faeeria Mar 25 '21 at 14:48
  • The application works fine but it cannot connect to the gcloud. When trying to access to the port where it is working it says "This site can’t be reached, localhost refused to connect". – anmarlea Mar 25 '21 at 14:53
  • So, you are trying to reach the app running in your container, but it does not work. That is because you should link your container's port to you host port, if you want to connect to your container by using `localhost` – Faeeria Mar 25 '21 at 14:55
  • Yes, the problem is that Pycharm creates the app's container on its own and I don't find any way to modify the configuration of it. Otherwise I could link them :( – anmarlea Mar 25 '21 at 14:57
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/230371/discussion-between-faeeria-and-anmarlea). – Faeeria Mar 25 '21 at 15:02

2 Answers2

0

The answer should be to use Docker as a test environment and not only as an interpreter, which will allow to use port bindings

Faeeria
  • 786
  • 2
  • 13
0

Finally I found how to do it with Pycharm:

Instead of using the Docker Image as an interpreter a new Python configuration should be created.

enter image description here

New arguments can be added in Docker container settings so that Pycharm uses them when creating the container that runs the application. This way --link option can be specified and the user can work with several containers at the same time.

anmarlea
  • 370
  • 1
  • 3
  • 11