<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: hamza Bou Issa</title>
    <description>The latest articles on DEV Community by hamza Bou Issa (@bouissihamza6).</description>
    <link>https://dev.to/bouissihamza6</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F427278%2F09e34947-be8c-42d7-929f-de13fbf944e6.jpg</url>
      <title>DEV Community: hamza Bou Issa</title>
      <link>https://dev.to/bouissihamza6</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bouissihamza6"/>
    <language>en</language>
    <item>
      <title>Debug A Django Container With VS Code</title>
      <dc:creator>hamza Bou Issa</dc:creator>
      <pubDate>Wed, 08 Jul 2020 21:47:56 +0000</pubDate>
      <link>https://dev.to/bouissihamza6/debug-a-django-container-with-vs-code-1bed</link>
      <guid>https://dev.to/bouissihamza6/debug-a-django-container-with-vs-code-1bed</guid>
      <description>&lt;h1&gt;
  
  
  I'm not a native speaker
&lt;/h1&gt;

&lt;p&gt;Well I get tired searching the internet for debugging my colleague's django container, I tried all sort of things:&lt;br&gt;
&lt;a href="https://www.jetbrains.com/help/pycharm/using-docker-compose-as-a-remote-interpreter.html"&gt;Pycharm Doc for docker-compose debugging&lt;/a&gt; &lt;br&gt;
&lt;a href="https://www.jetbrains.com/help/pycharm/remote-debugging-with-product.html"&gt;Pycharm Doc for remote debugging&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Microsoft/ptvsd"&gt;VS Code with ptvsd&lt;/a&gt;&lt;br&gt;
Until I Came into This &lt;a href="https://code.visualstudio.com/docs/remote/containers#_attaching-to-running-containers"&gt;article&lt;/a&gt; by microsoft About Developing inside a Container Using  VS Code &lt;br&gt;
After 10 min reading the article the steps to debug A container:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Attach to container&lt;/li&gt;
&lt;li&gt;Debugging As you usually do in VS Code&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Attach to container
&lt;/h1&gt;

&lt;p&gt;to attach to container it must be running . The problem if we run our container with &lt;strong&gt;python manage.py runserver&lt;/strong&gt; this will prevent us from running the debug mode inside the container so we need a hack , the solution here is to keep container running and execute &lt;strong&gt;python manage.py runserver&lt;/strong&gt; inside the container.&lt;br&gt;
Now we add this line to Django's Dockerfile :&lt;br&gt;
&lt;strong&gt;entrypoint ["tail","-f","/dev/null"]&lt;/strong&gt;&lt;br&gt;
this will keep our container running so we can attach VS Code to it&lt;br&gt;
now type ctrl+shift+P and write &lt;strong&gt;remote-containers:attach to running container&lt;/strong&gt; then choose the django container and vscode will install itself inside your container and open it up ...&lt;/p&gt;

&lt;h1&gt;
  
  
  Debugging As you usually do in VS Code
&lt;/h1&gt;

&lt;p&gt;Now let's add Django Debugging Configuration to &lt;strong&gt;launch.json&lt;/strong&gt; (exist inside .vscode folder)&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K9ysjvQA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/0zhDoqO.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K9ysjvQA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/0zhDoqO.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
(don't forget  0.0.0.0:8000 to map to the outside world of the container)&lt;br&gt;
of course if you have docker-entrypoint file you can replace "program": "${workspaceFolder}/docker-entrypoint.sh"&lt;br&gt;
and remove args&lt;/p&gt;

&lt;p&gt;happy coding :)&lt;/p&gt;

</description>
      <category>django</category>
      <category>docker</category>
      <category>vscode</category>
      <category>debug</category>
    </item>
  </channel>
</rss>
