Run Visual Studio Code In Docker



  1. Run Visual Studio Code In Docker Windows 10
  2. Using Docker In Visual Studio
  3. Visual Studio Code Docker Extension

In addition to snippets for authoring your Dockerfile, Visual Studio Code will provide you with a description of any Docker command you hover over with the mouse. For example, when hovering over WORKDIR you will see the following. For more information on Dockerfiles, check out Dockerfile best practices on docker.com. By the end of this module, you'll be able to: Install the Visual Studio Code Remote - Containers extension. Load and connect to a project in a Docker container. Access ports in the container from your local machine. Customize settings while working with your container. Add software to the container environment.

The Docker extension for Visual Studio Code by Microsoft has a lot of handy features when it comes to generating the files necessary for building and deploying Docker containers. In this post, we’ll create a Dockerfile that we can use to build a new container image.

First, I’ll create a new file in my workspace called Dockerfile.
Inside my Dockerfile, I’ll hit Control-Space to bring up a list of snippets that are available with the Docker extension.
First I need to specify the image that I’m going to be building from. Below, I’ll specify the latest Microsoft IIS image, which I have already downloaded —

Now let’s copy some files to the new container image by using the copy snippet. I’m going to specify the wwwroot folder that is currently in my workspace as the source. Then I’ll hit Tab to move to the next field in the snippet, where I’ll specify my wwwroot folder on the container as the destination.


COPY wwwroot c:/inetpub/wwwroot

Finally, I’m going to expose port 80 and then save this Dockerfile.

Run Visual Studio Code In Docker Windows 10

Now that I’m finished, I can actually build my container image right from VS Code instead of using the command line. Simply right-click on the Dockerfile, then click on Build Image.
You’ll be prompted to tag the new image. I’m going to use the default tag and hit Enter.

Run


You’ll see the Docker build command running in the terminal below.


Once that’s done, I’m going to click on the Docker icon in the activity bar on the left-hand side.

Docker

And we can see the new container image listed under Images.

Let’s go ahead and right-click that and run this container.

Using Docker In Visual Studio

Now that it’s running, I want to attach a shell so that I can get this container’s IP address.


When I take the IP address and put it in my web browser, it’s possible to see the website is running on the new container.

Visual Studio Code Docker Extension

Thanks to the Docker extension for VS Code, we were able to easily author, deploy, and run a new container in very little time!