How to avoid create /opt/project
I am trying to configure a simple python project using Docker and docker-compose.
Dockerfile:
FROM python:2.7
WORKDIR /app
COPY ./requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY ./web web/
COPY ./crawler crawler/
EXPOSE 5000
CMD ["python", "/app/web/app.py"]
Docker-compose:
version: "3.0"
services:
app:
container_name: app
build:
context: .
ports:
- 5000:5000
volumes:
- "./web:/app/web"
- "./crawler:/app/crawler"
The pycharm configuration:
I follow the steps and when I inspect my container, it contains my whole project duplicated, in /app and in /opt/project. There is another volume from my root project to /opt/project.
How could I avoid that?
I am looking for the right way to be able to debug my project with docker using pycharm.
请先登录再写评论。
Hi,
You COPY your project files to the container using Dockerfile, and on top of that you're using volume bindings to mount your project root to the container.
You probably should choose only one of those methods of delivering your code to the container.
Check your path mappings. If you're using Dockerfile's COPY instruction, you don't need volume bindings and path mappings in PyCharm.
That's right! I do not have to COPY ./web web/ and ./crawler crawler/, but it does not solve the problem.
Now, I have made a few changes and I only have one volume, but when I inspect my container I still have one volume duplicated in /opt/project and I would like not to have it.
Dockerfile:
Docker Compose:
Pycharm configuration:
What happens if you rebuild and run the container in terminal outside of PyCharm. Do you get the same bindings?
No, when I run thorugh docker-compose up -d I only have my volume and it works fine.
I want to use PyCharm with Run/Debug Configuration
Please try to delete and recreate the docker interpreter. Does it help?
No, it still happens.
Path mapping should be not literal <Project root> but the full path to the project root. This helped me
My case
Local path: /Users/.../directory_with_dot_idea ; Remote path: /app
Unfortunately, the full path to the project root displays the same as <Project root> literal ( This is slightly confusing
I have the same issue and it's actually really annoying as it messes up some stuff for me. Seems like pycharm does these mappings behind the scenes.
pycharm generates extra compose yml with new volume additionally ty pycharm_helpers volume
volumes:
- "PROJECT_HOST_PATH:/opt/project:rw"
so the question is, how to configure BOTH generated paths:
1) PROJECT_HOST_PATH
2) /opt/project
i need something else at both paths as topicstarter @Alearngon
Late to the thread with my two cents.
It appears that the /opt/project is somewhat the 'default' folder that the PyCharm uploads the code before debugging if interpreter path mappings are not set. See here https://intellij-support.jetbrains.com/hc/en-us/community/posts/360003286639-DOCKER-container-opt-project-missing-PYTHONPATH-
Cheers.
I've created https://youtrack.jetbrains.com/issue/PY-53434 to try and get some traction in this area.
I have the same problem. after set Path mappings: (<Project root>→/app) in debugging mode I take following error:
Traceback (most recent call last):
File "/opt/.pycharm_helpers/pydev/pydevd.py", line 1491, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "/opt/.pycharm_helpers/pydev/_pydev_imps/_pydev_execfile.py", line 11, in execfile
stream = tokenize.open(file) # @UndefinedVariable
File "/usr/local/lib/python3.8/tokenize.py", line 392, in open
buffer = _builtin_open(filename, 'rb')
IsADirectoryError: [Errno 21] Is a directory: '/app'
Does any solution for this?
Mohammad69h94
I think it may be code-related. Any chance you could provide a project sample to reproduce the issue?
Any working solution for this issue? I have the same
I have the same issue.
In earlier Pycharm versions (2021) we never had the problem. We are paying customers expecting some response and solutions for this show-stopping issue.
Jakob Vinther Hi, are you talking about project located in `/opt/project`?
Could you please specify why this issue is a show-stopper for you?
I have a similar issue. I don't found a solution. When I creating and launching the Django debug server, another volume is created in the container at opt/project. Is there a solution to this problem or bypass path to exclude the creation of this volume?
Hi Ivan_Prigulnov,
/opt/project
is a direct mapping of the project root to a Docker container. Unfortunately, there is no option to disable it. Here is a related usability issue: PY-55824. Please vote for it and feel free to comment. See this article if you are not familiar with YouTrack.