I am trying out PyCharm and my mind is blown at how good an IDE it is. I have never used an IDE for the last 3 years of my professional career, having stuck to vim and tmux for my coding workflow.
I recently decided to give PyCharm a try and it was really worth giving it a shot. I am happy with the test-driven development support, the git merge tool and the autocomplete/refactor features in PyCharm.
The one thing that I am not able to get to work till now is the Docker build and run.
I have an existing project that has a Dockerfile. The docker image is built from the docker file and then the container is run. Here is my Dockerfile:
RUN apk --update add bash
SHELL ["/bin/bash", "-c"]
RUN pip install pipenv
RUN pip install gunicorn
RUN mkdir /app
COPY ./module1 /app/module1
COPY ./module2 /app/module2
RUN pip install -e module1
RUN pip install -e module2
My docker build command is as follows, which I run from the root of my project directory. It's important that I run the docker build command from that directory.
docker build -t test:0.1 -f test/resources/Dockerfile .
And then I run the container as follows:
docker container run -t -d -p 80:8080 -e "SERVER_HOST=0.0.0.0" -e "SERVER_PORT=8080" --name "test_container" test:0.1
I tried to configure the docker run configuration in PyCharm which is similar to the two commands above. Here is a screenshot:
Here is the command preview with the complete command generated by PyCharm:
docker build -t test:0.1 .
&& docker run
So the Dockerfile starts to bootstrap an image from python-alpine and copies the code from host to guest. But the copy never works in PyCharm as it fails with the following error:
Step 7/13 : COPY ./shared /app/shared
Error: ResponseItem.ErrorDetail[code=<null>,message=COPY failed: stat /var/lib/docker/tmp/docker-builder134533513/module1: no such file or directory]
Failed to deploy 'test Dockerfile: test/resources/Dockerfile': COPY failed: stat /var/lib/docker/tmp/docker-builder134533513/module1: no such file or directory
I believe that there is no way we can change the location for the docker build command, which causes the COPY command to fail. Can I fix this? Is there something that I am doing fundamentally wrong?
I tried to find a solution online but couldn't find anything specific to my issue. It's worth mentioning that I am not trying to use a python environment inside a Docker container.