How To Use The Docker Extension For Visual Studio Code To Build A DockerFile

Microsoft’s Docker extension for Visual Studio Code makes it easy to manage and run Docker images and containers. The extension also helps in the authoring of Dockerfile files within VS Code by offering automatic file generation, syntax highlighting, hover tips and IntelliSense.

In this video, Matt will demonstrate how to use the Docker extension to generate a new Dockerfile taking advantage of the snippets that the Docker extension makes available in VS code. Once the Dockerfile is complete, we can then build and run the new container image thanks to the Docker extension without having to type anything at the command line.

Prerequisites include: Docker Visual Studio Code Docker Extension:

Docker extension for VS code by Microsoft has a lot of handy features when it comes to generating the files necessary for building and deploying docker containers. Let's go ahead and create a dockerfile that we can use to build a new container image. First, we'll create a new file in my workspace called Dockerfile. Inside my dockerfile I'll hit CTRL space to bring up a list of snippets that are available with the Docker Extension first thing I need to do is specify the image that I'm going to be building from. Here, I'll specify the latest Microsoft ISO 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 WWW root 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 WWW root folder on the container as the destination. Finally, I'm going to expose port 80 and then save this. Dockerfile 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 Docker file then click on build image will be prompted to tag. The new image. I'm going to use the default tag and hit enter 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 and we can see the new container image listed under images. Let's go ahead and right click that and run this container now that it's running. I want to attach a shell so they can get this containers IP address. When I take that IP address and put it in my web browser. You can see that the website is running on the new container thanks to the Docker extension for VS code. We were able to easily author deploy and run a new container in very little time thanks for watching.