VS Code Docker extension

A quick review of the Microsoft Visual Studio Code (VS Code) extension for Docker. How best to use the Docker extension and how it will save time and energy developing your next Docker project.

A quick review of the Microsoft Visual Studio Code (VS Code) extension for Docker. How best to use the Docker extension and how it will save time and energy developing your next Docker project.

Microsoft VS Code - https://code.visualstudio.com/
VS Code Docker extension - https://marketplace.visualstudio.com/items?itemName=PeterJausovec.vscode-docker

Episode Transcription

This episode we are going to talk about Microsoft Visual Studio Code and working with Docker. I took a short survey of some of my colleagues and people using Visual Studio Code, and I asked them first, do you have the Docker extension installed? Yes or no? And most people had the extension installed, which is not a surprise. But the next question is, Are people using an extension to its fullest capabilities? And surprisingly, most people were not using it nearly as it was intended. Most people use it for Docker syntax checking etcetera. But even then, they weren't using some of the features to validate or pull it the commands of Dockerfile, etcetera.

So in this podcast, we're going to shortly describe the Docker extension and what you can do with the Docker extension. Besides just doing normally. Syntax checking. So, first and foremost, we could do Dockerfile. So in the Docker file, we can create a normal Docker file, as we have in the past. But then we can bring up like the command snippet, and we can actually bring up every different command file available within the Docker files.

For example, the first line in the Docker file is from You can see the exact argument. So you can see the whole list of all the possibilities of Docker file of composes files. So you don't have to constantly be searching the Docker docs for the different possibilities. It's all right there within your editor. So when you do in the Mac, it's, ah, control space. I would imagine Windows would be controlled space as well, and it brings up the list of all the possibilities for the doctor file.

Now, the next is who has generated a Docker file using visual studio code. Now, this is something new to me because I was actually investigating an issue that I found with visual studio code and Docker and it was just driving me nuts and I came across some documentation. Now, in visual studio code, you can actually generate a Docker file, and it does it automatically and, for example, a Microsoft Dot Tet application.

It will actually create multi-stage builds for you automatically. I mean, the amount of time you spend trying to do this by yourself is, you know, a few hours where visual studio code generated on the fly for you. So to do this, to generate our own Docker file, you just use command p in Mac or Windows P. It brings up the command in the command palette, we can just do Docker Add Docker Files from the workspace and then you can choose which programming framework you want to use. And it takes everything in your local directory and it actually builds the Dockerfile. Then it prompts you for what language do you want to use? This is going Java, Dot Net, Python, etc. And then what court were application would be listening on. And once you hit, enter it actually generates a docker-compose file, a Dockerfile and a debug file all for you.

Now, obviously, is final production ready, but it's a good starting point. It's a good basis to get up and running with your doctor files. So next time you start a project from scratch. I reckon visual studio code actually generate your Dockerfile Doctor composed file directly for you. Give it a try. I mean, I'm really surprised at the success of this. And like I said, I've written some multi-stage files in the past, and I've compared it to the Docker extension, and it does a very good job.

The next thing you can do within Visual Studio Code is actually to perform Docker Commands directly within the Visual Studio Code. So again, command P and Mac or windows p in Windows and he could do type, Docker. Just think of all the different Docker commands, and it actually generates the command directly in the terminal and Visual Studio Code, and you can run it right there. I mean, this is quite cool. The next thing you could do is in actual the Docker Explorer. So if you click on the Docker extension on the left-hand side of the menu bar, you can see images, containers, etc.

You could see the containers that are running and you can interact with these containers. Now it's really cool. If you right click on one of containers you can attach to the console. So then it generates exactly the console Command to connect to it figures out what kind of container it is and consoles right into it. So you don't have to do a Docker ps to find out what name it is. So it's a bit quicker to do it this way.

Additionally, you can look at the logs for a container, right click on the container logs, and again it generates the command that puts the command there. What I found quite helpful is when I'm writing within the Visual Studio, doing compose whatever. And I want to test what I'm doing. And I do like a Docker compose build. So then I do command p Docker and type Docker composed build, and it builds it. It completes command for me and it builds right there in my terminal and the advantage of using visual studio codes.

You're not context switching. You're not switching between your editor and your terminal time, so it's actually really helping with my workflow. I would really encourage everyone to give it a try. I mean, maybe it won't use all the features within it but just give some of these new ones to try because of myself, I was pleasantly surprised how good it is. I'm going to explore some other extensions and let you know. But so far I'm very impressed with the doctor extension. So that's the time for today, Thank you very much. And we'll see you in the next episode. Have a great day.

Brian Christner