Pycharm docker run configuration do not accept environment variables

Viewed 742

I am trying to set up a docker run configuration in Pycharm, i am pretty new to this functionality in pycharm, and i can't get it working. In docker I would run the container with the following command

docker build -t test-container . && docker run --name container-pycharm -t -i --env-file .env -v $(pwd):/srv/app -p 8080:8080 --rm test-container ./serve-app

I set up this in pycharm, by adding the following line

--rm --env-file .env -i -t -p 8080:8080 -v $(pwd):/srv/app

to command line options section in the relevant docker Run/Debug Configuration Pycharm window. Unfortunately I get

Failed to deploy 'container-pycharm Dockerfile: Dockerfile': com.github.dockerjava.api.exception.BadRequestException: {"message":"create $(pwd): \"$(pwd)\" includes invalid characters for a local volume name, only \"[a-zA-Z0-9][a-zA-Z0-9_.-]\" are allowed. If you intended to pass a host directory, use absolute path"}

Clearly, I cant use $(pwd) in my command line options, any idea on how to solve this in pycharm?

1 Answers

Pycharm doesn't invoke docker directly via the command you see in the command preview, it goes through its custom parser, currently they haven't implemented the feature to read envs. Thus "If you intended to pass a host directory, use absolute path"

And -v is not officially supported as command line options in the current version. Ref

Use Bind mounts instead

enter image description here

Related