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.

 

14 comments
Comment actions Permalink

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.

0
Comment actions Permalink

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:

FROM python:2.7
WORKDIR /app
COPY ./requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 5000
CMD ["python", "/app/web/app.py"]

 

Docker Compose: 

version: "3.0"
services:
app:
container_name: app
build:
context: .
ports:
- 5000:5000
volumes:
- "./:/app"

 

Pycharm configuration:

 

 

 

 

0
Comment actions Permalink

What happens if you rebuild and run the container in terminal outside of PyCharm. Do you get the same bindings?

0
Comment actions Permalink

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

 

0
Comment actions Permalink

Please try to delete and recreate the docker interpreter. Does it help?

0
Comment actions Permalink

No, it still happens.

1
Comment actions Permalink

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

0
Comment actions Permalink

Unfortunately, the full path to the project root displays the same as <Project root> literal ( This is slightly confusing

0
Comment actions Permalink

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.

1
Comment actions Permalink

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

3
Comment actions Permalink

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.

0
Comment actions Permalink

I've created https://youtrack.jetbrains.com/issue/PY-53434 to try and get some traction in this area.

0
Comment actions Permalink

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? 

0
Comment actions Permalink

Mohammad69h94

I think it may be code-related. Any chance you could provide a project sample to reproduce the issue?

0

Please sign in to leave a comment.