How To Use The Docker Extension For Visual Studio Code To Manage Containers And Container Images
Microsoft’s Docker extension for Visual Studio Code makes it easy to manage and run Docker images and containers.
In this video, Matt will demonstrate how to use the new Docker icon on the activity bar which gets installed with the Docker extension to view, inspect, run, tag and remove container images. He will then start up a new container from a container image from the Docker explorer in VS Code. Once a new container is running, he will then walk through attaching a shell to a running container to run PowerShell commands from inside the container. Then he will demonstrate how to start, stop, restart and remove containers without having to touch a command prompt. Finally, Matt will show you how to connect to Docker hub to browse or push container images.
Prerequisites include: - Docker - A Docker image - Visual Studio Code - Docker Extension for Visual Studio Code
Today I'm going to show you how to manage containers and container images with the Docker extension for Visual Studio code by Microsoft. When you install the Docker Extension. You'll notice a new docker icon in the activity bar. Let's go ahead and click on that. In the Docker Explorer. We have a few different dropdowns images containers and registries. Let's start with images. When I expand images you can see that I have 3 container images available. When I right click a container it gives me a set of actions that I can perform against that image. For example, if I click inspect image. It will give me the same. JSON output that would get returned if I ran the Docker inspect command. I can also run the container image from here as well. I have the option to run the container in the background or run it interactively. Let's go ahead and click on run to run this container in the background. In the powershell terminal you can see that the docker extension is simply running the Docker Run Command for us and passing in the appropriate parameters. Now, if I expand containers you can see my running and stopped containers. I'm going to go ahead and right click on my running container and see what my available options are first let's click on attach shell. This is going to put me in a powershell prompt inside the running container. When I run the host name command, you can see that it returns. The idea that Docker has assigned to this container. I can also choose to restart or stop this running container. When I stop the container you'll notice that it goes away. That's because, as you can see here in the powershell terminal. The container was started using the RM flag, which tells Docker to remove the container once it stops if I have a stop container that hasn't been removed. I can also right click on that container and click remove container. Now let's move on the registries. Under registries I can either connect to docker hub or a private registry. I don't have any private registries right now to connect to but if I did. I could just right click on private registries and click on connect to a private registry. This will then prompt me for the URL of the private registry that I would like to connect to. To connect to a docker hub account. I'm going to click on Docker hub and VS code is going to prompt me for my docker hub credentials. After I enter my credentials. I can now see my docker hub repository as well as any container images that I've already uploaded. Right clicking on one of my container images gives me the option to browse to it in Docker hub. Now, what, if I want to push one of my container images to my docker hub account. I'm going to right click on my container one image that I'm going to click push. I'm going to get a warning here because I first need to tag my image with my repository name. So let's go ahead and right click on container one again and click tag image. VS code will automatically append my default repository name to the beginning of my image name. If that looks good, I can hit enter. Now I have a container one image tagged with my repository name, so if I right click that image and click push it will ask me if I want to save that repository name as my default registry path. I'm going to click, yes here. Now the docker push command will run OK great now that the push command has finished let's refresh. The Docker Explorer. I can now see my new container image out on Docker hub and that was how to manage containers and container images with the Docker Extension in Visual Studio Code.