I’ve made an Python+Django+git docker container.
Now, I would like to ‘Attach to a running container..’ with VSCode to develop, i.e. run and debug, a Python app inside.
Is it good idea? Or it is better only setting up VSCode to run app inside the container?
I don’t want VSCode make a docker container by itself.
Thanks.
I tried to ‘Attach to a running container..’ but have got ‘error xhr failed…’ etc.
3
Answers
I use such an environment to develop python app inside a container.
Examples:
image_dockerfile :
image_create.sh :
container_create.sh :
container_restart.sh :
container_stop.sh :
For VSCcode:
a) Prepare files (see above).
b) Run:
image_create.sh
container_create.sh
c) Open project folder in VSCode
d) Click on left bottom green / Attach to running container / select container name (python_find_a_job).
e) Clone repository.
f) Install extension 'Python'.
Now you can run and debug inside the container.
After work:
git push
container_stop.sh
Before work:
container_restart.sh
git pull
Visual Studio Code, and Docker Desktop each offer a feature called "Dev Containers" (VSCode) or "Dev Environments" (DD), or CodeSpaces (GitHub)
In this approach, a Docker container is created by scanning the source, and generating a container that contains the development toolchain. Visual Studio then attaches to the container, and allows you to develop even though you do not have node/python3/dotnet/etc. installed on your development PC.
The xhr error indicates something went wrong downloading a scanning image or something else is strange about your project.
There is an optional Dockerfile that can be created if scanning fails to find an image, that is normally kept in a
.devcontainers
/.devenvironments
folder depending on which of Docker / VSCode / GitHub / other you are using.Your project might also have one (or more) Dockerfile’s that are used to package the running app up as a docker image, so don’t be confused if you end up with 2. Thats not a problem and is expected really.
I have got good results with VSCode using docker compose with compose.yml. But in this case, docker compose will create a new container from image every time.
compose.yml example:
Before work:
VSCode / Attach to Running Container …
File / Open Folder (/opt/find_a_job from above example of compose.yml).
After work:
P.S. I have tried PyCharm community ed. But it can’t add Docker interpreter. Only PyCharm Professional ed. can do it.
So I use VSCode to run & debug (F5) inside a docker container. There was some minor problems with setting VSCode tasks, extensions etc. But main part about run & debug inside a container works perfect. Changes in a project can be saved locally or pushed to git by VSCode or manually.