How To Use The Docker Extension For Visual Studio Code To Run Containers With Docker Compose

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 docker-compose.yml 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 new docker-compose.yml files using the available snippets and IntelliSense provided by the Docker extension. Once the YML file has been created, Matt will show you how to run a docker-compose up and docker-compose down commands from within VS code without having to use the command line.

Prerequisites include: Docker Visual Studio Code Docker Extension: https://marketplace.visualstudio.com/items?itemName=PeterJausovec.vscode-docker

Docker extension for VS code provides a rich experience for generating yaml files used by Docker compose to define an run containers in my current workspace. I have a simple dockerfile that I created to define a container. I would like to build now. I want to use Docker compose to build and run my container. So I need to create a yaml file to define my new service. I'm going to call this file Docker compose dot yaml inside my Yaml file. I can hit CTRL space to use intellisense to help me configure valid compose directives. I'm going to go ahead and paste the rest of my definitions into this file. One thing to note is that you can hover over various compose directives to see a description of that directive now that my service has been defined when we want to save this. Yaml file in the Explorer pane when I right click on the Yaml file. I'm given a few options specific to Docker compose. Let's go ahead and click compose up this will run the Docker Compose Command with the necessary parameters to build and run the web container. When I go to the Docker icon in the activity bar on the left hand side. I now see a web container image under images in a new container running under containers. Let's right click that container and attach a shell so we can get the IP address now copy that IP address and paste it into my web browser. You can see that it will display the simple. HTML page that I specified to copy to my new container image in my dockerfile. Now let's go back to my workspace and right click on the yaml file again. This time, let's choose compose down this will run the Docker Compose Down Command, which will stop and remove the running container. We can verify this by going back to the Docker icon to see that the container is no longer running now you see how easy it is to work with Docker compose in the Docker extension for VS code thanks for watching.