Entrypoint not found when running tests with docker-compose interpreter

Answered

I have an application that I've set up to run with docker-compose, so I've set up a Project Interpreter in PyCharm to be the interpreter of a service that I'm running with docker-compose. I have an entrypoint in my Dockerfile at `./bin/docker-entrypoint.sh`. When running a unit test, I get the following error indicating that the entrypoint cannot be found. 

ERROR: for 9f851185904f_REDACTED  Cannot start service REDACTED: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"./bin/docker-entrypoint.sh\": stat ./bin/docker-entrypoint.sh: no such file or directory": unknown

I notice that PyCharm runs the following docker-compose command, which indicates it starts my service by using both my docker-compose.yml and its own docker-compose.override.yml

/usr/local/bin/docker-compose -f REDACTED/docker-compose.yml -f REDACTED/Library/Caches/PyCharm2018.2/tmp/docker-compose.override.168.yml up --exit-code-from REDACTED --abort-on-container-exit REDACTED

I looked in the docker-compose.override, and it includes the following:

working_dir: "/opt/project/tests/unit"

This would explain why my entrypoint wasn't found -- my entrypoint is defined as a relative path but PyCharm changes the working directory. If I delete the definition of my entrypoint within my Dockerfile and my docker-compose.yml, then the tests run successfully.

My question is, what's the best practice in configuring docker-compose.yml, Dockerfiles and entrypoints to get tests running in PyCharm?

3 comments

Hi Greg,

I may add that when starting Python Run Configurations from PyCharm using Docker Compose interpreter we try to follow the semantics of the Run Configuration if it the script would be started using local interpreter. This includes including the environment variables from the Run Configuration, building the command line (e.g. for debugger we have the wrapper script that should be used) and also setting the working directory.

When running locally the working directory for PyCharm tests Run Configuration is set to the directory of the test script by default. So it is done for Docker Compose interpreter as well.

> My question is, what's the best practice in configuring docker-compose.yml, Dockerfiles and entrypoints to get tests running in PyCharm?

In my humble opinion the entrypoint is better to set using absolute path to the script because changing working directory would not affect it in this case.

1

Sergey, thanks for linking to the relevant ticket. I gather that if I wanted to be able to run my entrypoint script with my tests, it's currently not supported.

Alexander, yes it's certainly very reasonable to set the entrypoint as the absolute path. From our perspective, it's not ideal though because our code is built on top of Docker base images, like python:3.7-slim-stretch, and we don't want our code to be dependent on the directory structure that the maintainers of these images so happened to define.

Designing the Docker compose interpreter to follow the same semantics as the local interpreter does seem like a reasonable design choice. I understand now why it would make sense for the working directory to be set there.

0

Please sign in to leave a comment.