How to Run and Debug Python Inside Docker Containers Using VSCode

แชร์
ฝัง
  • เผยแพร่เมื่อ 31 ม.ค. 2025

ความคิดเห็น • 78

  • @Morten_Jaeger
    @Morten_Jaeger 2 หลายเดือนก่อน +2

    Note: The extension "Remote - Containers" is what nowadays is called "dev containers". They renamed it, that's all.

    • @codevev
      @codevev  2 หลายเดือนก่อน

      Thanks for the update!

  • @julianfernandez8117
    @julianfernandez8117 8 วันที่ผ่านมา

    Thanks from Colombia!

    • @codevev
      @codevev  8 วันที่ผ่านมา

      You're welcome! I play soccer with plenty of Colombians here in Vegas haha

  • @mahmoudelzouka5689
    @mahmoudelzouka5689 3 ปีที่แล้ว +3

    Thanks, Evgeny for the demo! this is what I was looking for.

    • @codevev
      @codevev  3 ปีที่แล้ว

      You're very welcome! Glad it helped!

  • @bluesdog88
    @bluesdog88 ปีที่แล้ว

    Thanks for the run through, just what I was looking for!

    • @codevev
      @codevev  ปีที่แล้ว

      Glad I could help!

  • @farmingbyfaith4210
    @farmingbyfaith4210 3 ปีที่แล้ว +2

    Awesome Video. Im busy with a project to use Python Data Science tools inside docker, but the tools then control metatrader inside wine. So I can have many algorithms running at once. I like the fact that I can debug line by line the Python code as it controls metatrader

    • @codevev
      @codevev  3 ปีที่แล้ว

      Sounds complicated :)

  • @TechWazza
    @TechWazza 3 ปีที่แล้ว +1

    Thanks for the this Evgeny...this was very simple, short and great help.

    • @codevev
      @codevev  3 ปีที่แล้ว

      You're welcome! Glad it helped!

  • @JanM-u5r
    @JanM-u5r 4 หลายเดือนก่อน

    Mesjac stojal na meste poka nenašol eto video.
    Spasibo.

  • @irongranca
    @irongranca 2 ปีที่แล้ว +2

    Thanks from canary islands :)

    • @codevev
      @codevev  2 ปีที่แล้ว

      Awesome, you're welcome!

  • @basicmachines
    @basicmachines ปีที่แล้ว +3

    Thanks. I couldn't find the 'Remote - Containers' extension in VS Code but I found something called 'Dev Containers' by Microsoft which sounds like the same thing. Has the name changed maybe?

    • @codevev
      @codevev  ปีที่แล้ว +2

      Just checked, Dev Containers from Microsoft extension does look correct!

    • @codevev
      @codevev  ปีที่แล้ว

      Correction. Dev Containers will probably work on its own but it's included in the Remote Development extension, which is a pack that not only lets you connect to Docker containers from VSCode but also ssh into other hosts

  • @chennahoom
    @chennahoom ปีที่แล้ว +2

    Hey! Awesome video!
    Just a quick question, when I reach the part after I click "Reopen in Container" ... I'm not getting the option to open "From Dockerfile" (7:22 in your video) , I get a list of configuration template. Do you know why maybe?

    • @codevev
      @codevev  ปีที่แล้ว

      Thanks! It looks like the option to open from dockerfile is only available when there's a Dockerfile that already exists in your workspace

  • @jiangpengli86
    @jiangpengli86 8 หลายเดือนก่อน

    Thank you for this great tutorial.❤

    • @codevev
      @codevev  8 หลายเดือนก่อน

      Glad it was helpful!

  • @jarorkwong8042
    @jarorkwong8042 3 ปีที่แล้ว +1

    Thank you bro, nice and easy!

    • @codevev
      @codevev  3 ปีที่แล้ว

      Great! Glad it helped!

  • @ahmedshawky9845
    @ahmedshawky9845 ปีที่แล้ว

    Thanks mate, really appreciate it

    • @codevev
      @codevev  ปีที่แล้ว

      Anytime!

  • @davidvc4560
    @davidvc4560 2 ปีที่แล้ว +1

    Thanks! Could you clarify if the VSCode actually created the container itself or connected to an existing container? @7:16. It looks like VSCode created a container to me, because it didn't ask for container name or id.

    • @codevev
      @codevev  2 ปีที่แล้ว

      It should have created a new container on its own

    • @davidvc4560
      @davidvc4560 2 ปีที่แล้ว

      @@codevev thank you!

  • @sg22r
    @sg22r ปีที่แล้ว

    Pure GOLD!

    • @codevev
      @codevev  ปีที่แล้ว

      Thanks!

  • @IFinging
    @IFinging 2 ปีที่แล้ว

    Fantastic video, Thank you

    • @codevev
      @codevev  2 ปีที่แล้ว

      Glad it helped!

  • @alchemication
    @alchemication ปีที่แล้ว +1

    This is nice, thank you, I just wonder if it could somehow work with K8s, so when your container dies, VS Code still works (as container would just simply restart) ... Also would be great to see version control integrated into this.

    • @codevev
      @codevev  ปีที่แล้ว

      Thanks! I haven't done much with K8s but let me know if you decide to try it out

  • @emanueol
    @emanueol ปีที่แล้ว +1

    uou manually installed python extension in the container, i wonder if its possible docker file to also do that ?

    • @codevev
      @codevev  ปีที่แล้ว +1

      Great question! You would do that in the devcontainer.json file rather than the Dockerfile

    • @codevev
      @codevev  ปีที่แล้ว +1

      Check this link out:
      code.visualstudio.com/docs/devcontainers/containers#_adding-an-extension-to-devcontainerjson

    • @emanueol
      @emanueol ปีที่แล้ว

      @@codevev thanks 👍

  • @devashishnigam5971
    @devashishnigam5971 3 ปีที่แล้ว +1

    How do we handle venv and requirements.txt. It would be great if you can cover that

    • @codevev
      @codevev  3 ปีที่แล้ว +1

      That's really the beauty of running Python inside the Docker container! You actually don't need venv because a container is an isolated environment. Hence, no special treatment of requirements.txt is needed but of course it depends on what exactly you're doing

  • @ammadkhan4687
    @ammadkhan4687 10 หลายเดือนก่อน

    Nice explanation. Thanks . Do you some some video to map network drive in docker container?

    • @codevev
      @codevev  10 หลายเดือนก่อน

      Thanks! I don't have a video about mapping network drive to a container yet. I haven't used Docker much lately. Good luck!

  • @danieltala9586
    @danieltala9586 2 ปีที่แล้ว +1

    Thanks! much better than debugpy :)

    • @codevev
      @codevev  2 ปีที่แล้ว

      I don't even know what debugpy is 😃

  • @damircicic
    @damircicic 11 หลายเดือนก่อน

    Hi when I click on the icon in the lower left corner and then click on any option in the list I get the message that current user does not have permission to run docker (I wanted to attach to the running container). Does anyone know how to solve this problem?

    • @codevev
      @codevev  11 หลายเดือนก่อน

      Are you on windows? Try opening VSCode as administrator

    • @damircicic
      @damircicic 11 หลายเดือนก่อน +1

      @@codevev I am on Ubuntu. Sounds promising. Thanks! I'll give it a try.

    • @codevev
      @codevev  11 หลายเดือนก่อน +1

      I see. Probably opening VSCode with 'sudo' could work. But maybe it's something else. I don't think I ever did it on Linux, just Windows or Mac

    • @nedkapinill
      @nedkapinill 10 หลายเดือนก่อน +2

      @@damircicic ​ I had same problem. I can open container with rootless in VS code. You can google "Run the Docker daemon as a non-root user (Rootless mode)" to fix permission problem.

  • @3MandMatt
    @3MandMatt 10 หลายเดือนก่อน

    would you add a video for docker compose?

    • @codevev
      @codevev  10 หลายเดือนก่อน

      Anything in particular about it?

  • @weishanlei8682
    @weishanlei8682 5 หลายเดือนก่อน

    There is no Remote-Containers extension. Please help!

    • @codevev
      @codevev  5 หลายเดือนก่อน

      it should be Dev containers now I think

  • @christiangunther650
    @christiangunther650 3 ปีที่แล้ว

    Hej Thx Evgeny! But could you explain the next steps on e.g. launch.json and how to configure properly? I have my problems there ... Cheers

    • @codevev
      @codevev  3 ปีที่แล้ว

      Christian, do you run into any specific problems? Mind sharing an error message or what is going on exactly?

  • @pranitpawar2200
    @pranitpawar2200 2 ปีที่แล้ว

    after running build command getting below error:
    failed to compute cache key: "/main.py" not found: not found

    • @codevev
      @codevev  2 ปีที่แล้ว

      You may have a typo in your Dockerfile. Sounds like it's not finding the path to the main.py file.

  • @f0l1v31r4
    @f0l1v31r4 ปีที่แล้ว

    And does it work for framesworks like fastAPI, Flask and Django?

  • @sergeyasdf2677
    @sergeyasdf2677 2 ปีที่แล้ว

    Hi there! How could I remote debugging on docker container?

    • @codevev
      @codevev  2 ปีที่แล้ว

      Did you watch the video?

  • @UpToTheSkyAgain
    @UpToTheSkyAgain ปีที่แล้ว

    I appreciate your explanations. Very clear and the step by step procedure is very nice. However I don't manage to do the last part. I get and error reopening the project in the container :
    [7105 ms] Start: Check Docker is running
    [7105 ms] Start: Run in Host: docker version --format {{.Server.APIVersion}}
    [7177 ms] Server API version: 1.41
    [7178 ms] Start: Run in Host: docker volume ls -q
    [7225 ms] Host server: Error: spawn docker ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:476:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
    [7270 ms] Host server: (node:11049) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 1)
    (Use `node --trace-warnings ...` to show where the warning was created)
    [7274 ms] Error: spawn docker ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:476:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
    The only difference with you is that I did the first part already in a remote access, in SSH. However "reopen in container" is supposed to work. Any idea, welcome. :-)

    • @codevev
      @codevev  ปีที่แล้ว

      I think when you reopen in container, it just looks for Docker running on your local host. So if you hadn't installed it there, it can't find the running instance of Docker and is throwing an error. I'm actually not sure if what you're trying to do is supported, might be a good thing for me to try figuring out. But at my new job we aren't currently using docker containers and I do all of my development on an ec2 instance via remote ssh through VSCode😂

  • @codevev
    @codevev  ปีที่แล้ว +3

    If you want to learn how to connect from VSCode to a remote server via SSH, watch th-cam.com/video/titbwVSLCws/w-d-xo.html next

  • @brunaguterres1817
    @brunaguterres1817 2 ปีที่แล้ว

    Unfortunatly there is no Remote - Containers extension on my VS code :(

    • @codevev
      @codevev  2 ปีที่แล้ว

      Bruna, you will need to install it first. You can follow this link: marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack

    • @brunaguterres1817
      @brunaguterres1817 2 ปีที่แล้ว +1

      @@codevev Thank you so much. Nice tutorial. One of the most useful in TH-cam lately.

    • @codevev
      @codevev  2 ปีที่แล้ว

      Thanks for the kind words :)

  • @mohasinsultan
    @mohasinsultan 3 ปีที่แล้ว +1

    Thanks

  • @bramjanssen8865
    @bramjanssen8865 5 หลายเดือนก่อน

    This extension is now called: Dev Containers

    • @codevev
      @codevev  5 หลายเดือนก่อน

      Thanks for the update!

  • @codevev
    @codevev  5 หลายเดือนก่อน

    And to learn how to use VSCode on any other device, including your phone, watch th-cam.com/video/XcovoZWAdxE/w-d-xo.html

  • @MentoriadeSoftware
    @MentoriadeSoftware 2 ปีที่แล้ว

    Hi codeEV,
    Thanks for your video, I've done a test like you showed and everything works fine with the remote, but when I want to run my .py file I get an error:
    Se produjo una excepción: ModuleNotFoundError
    No module named 'matplotlib'
    File "/workspaces/python/consulta.py", line 3, in
    import matplotlib.pyplot as plt
    This is my Dockerfile
    FROM python:3.7.13
    WORKDIR /home/tips/python
    RUN pip install surprise
    RUN pip install d2l==0.17.5
    RUN pip install -U mxnet-cu101==1.9.1
    RUN pip install seaborn
    RUN pip install gluon
    COPY . .
    CMD [ "python", "./consulta.py" ]
    This is the consulta.py file
    import matplotlib.pyplot as plt #

    • @codevev
      @codevev  2 ปีที่แล้ว

      Hi! If I'm reading it correctly, the pip command to install matplotlib is missing from your dockerfile

  • @julioalvia3619
    @julioalvia3619 ปีที่แล้ว

    Thanks

    • @codevev
      @codevev  ปีที่แล้ว

      You're welcome!