{"id":9304,"date":"2022-03-21T22:03:42","date_gmt":"2022-03-21T22:03:42","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=9304"},"modified":"2022-11-24T09:51:18","modified_gmt":"2022-11-24T09:51:18","slug":"visual-code-with-vscontainers","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/visual-code-with-vscontainers\/","title":{"rendered":"Visual Code with vscontainers"},"content":{"rendered":"<p><em>Note: It appears in Visual Studio Code 1.73.1 that the process for how to open a container has changed. I&#8217;ve added the changes to the post<\/em><\/p>\n<p>Visual Code supports vscontainers. Basically a way of running Visual Code, connecting to a docker image and working within that container. <\/p>\n<p>So for example we could run up a Go container with all the Go tooling within it, use Visual Code&#8217;s terminal to interact directly with the container and it also support volumes, so allows us to store data directly on our host machine.<\/p>\n<p><em>If you&#8217;re using Windows you&#8217;ll need the Docker Desktop and WSL2 installed.<\/em><\/p>\n<p>All we need to do is&#8230;<\/p>\n<p>Let&#8217;s say we wanted to work with a dotnet container. Create a folder to act as your code folder and then create a <del datetime=\"2022-11-24T09:37:04+00:00\">.vscontainer<\/del> .devcontainer folder and within that a <del datetime=\"2022-11-24T09:37:04+00:00\">vscontainer.json<\/del> devcontainer.json file. Add the following<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n{\r\n  &quot;image&quot;: &quot;mcr.microsoft.com\/vscode\/devcontainers\/dotnet&quot;,\r\n  &quot;forwardPorts&quot;: &#x5B;3000]\r\n}\r\n<\/pre>\n<p>Now use the View | Command Palette (or Ctrl+Shift+P) and run the command <del datetime=\"2022-11-24T09:37:04+00:00\"><em>>Remote-Containers: Reopen in Container<\/em><\/del> <em>Dev Containers: Reopen in Container<\/em>. This will restart VS Code and when it&#8217;s finished downloading the container image will be ready for you to start interacting with &#8211; if you haven&#8217;t already got the terminal window open then try opening one. In my case I have a <em>bash<\/em> terminal. You should now be within the container so just try and run the <em>dotnet<\/em> CLI command and you should see it&#8217;s help\/commands.<\/p>\n<p>Obviously if your system already has dotnet installed that probably won&#8217;t surprise you or interest you that much, but there&#8217;s a bunch of alternative containers, for example, how about a TypeScript Node container<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n{\r\n  &quot;image&quot;: &quot;mcr.microsoft.com\/vscode\/devcontainers\/typescript-node:0-12&quot;,\r\n  &quot;extensions&quot;: &#x5B;&quot;dbaeumer.vscode-eslint&quot;],\r\n  &quot;forwardPorts&quot;: &#x5B;3000]\r\n}\r\n<\/pre>\n<p>To see a list of Microsoft defined containers, take a look at <a href=\"https:\/\/hub.docker.com\/_\/microsoft-vscode-devcontainers\" rel=\"noopener\" target=\"_blank\">microsoft-vscode-devcontainers<\/a>. <\/p>\n<p>Here&#8217;s another one to try &#8211; so I have Swift set up on my Linux server but not on my Windows Box, so using the following will give me a Swift environment<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n{\r\n  &quot;image&quot;: &quot;swift&quot;,\r\n  &quot;forwardPorts&quot;: &#x5B;3000]\r\n}\r\n<\/pre>\n<p>Now from the terminal (as already stated) you&#8217;re within the container but you&#8217;ll want to store your code on the host machine &#8211; well magically works out of the box (so to speak) and I am able to create a folder in the terminal and see it in the host folder I created with .vscontainer within it.<\/p>\n<p><strong>References<\/strong><\/p>\n<p><a href=\"https:\/\/code.visualstudio.com\/docs\/remote\/containers\" rel=\"noopener\" target=\"_blank\">Developing inside a Container<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Note: It appears in Visual Studio Code 1.73.1 that the process for how to open a container has changed. I&#8217;ve added the changes to the post Visual Code supports vscontainers. Basically a way of running Visual Code, connecting to a docker image and working within that container. So for example we could run up a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[246],"tags":[],"class_list":["post-9304","post","type-post","status-publish","format-standard","hentry","category-visual-code"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9304","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=9304"}],"version-history":[{"count":5,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9304\/revisions"}],"predecessor-version":[{"id":9773,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/9304\/revisions\/9773"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=9304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=9304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=9304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}