There have been many times in my career or when working on personal projects, that I have needed some open-source executables to help me complete my task. I have used things like  Weasyprint,  WKHTMLTOPDF,  Exiftool,  Ghostscript, the list goes on and on (these are just some of the more recent ones). These are all fantastic tools, and I’m sure there are hundreds more out there. They have saved me countless hours of work by providing amazing functionality that I either don’t have to write or just don’t know where I would even begin if I had to! I am thankful for these tools and the many more that are free and open-source.

However, I do not want to install them on my local machine. I am 100% against installing extra software on my personal machine that is needed for a project, not in pursuit of helping me on a daily basis. If you happen to work for a company that locks down their machines, it may be impossible to install this software locally. Thankfully, we have Docker and all its gloriousness to help us. Utilizing Docker, I can install all this software easily and use it without abandon. Even if my machine is locked down, Docker can come to the rescue.

I have used Docker so many times in these scenarios and it’s been great. However, the debugging experience in this situation is not great. Since I don’t have this software installed locally, to truly see if my code is working properly I need to run it in a Docker container. This isn’t horrible, but it tends to lead to a lot of log statements and extra time consumed needlessly. Fortunately, Microsoft has an amazing extension for Visual Studio Code called  Remote Containers. From their page:

The Visual Studio Code Remote — Containers extension lets you use a Docker container as a full-featured development environment. It allows you to open any folder inside (or mounted into) a container and take advantage of Visual Studio Code’s full feature set. A devcontainer.json file in your project tells VS Code how to access (or create) a development container with a well-defined tool and runtime stack. This container can be used to run an application or to sandbox tools, libraries, or runtimes needed for working with a codebase.

In this post, we’ll write a very simple Go application that will utilize Exiftool to pull and display metadata from a PDF. Using the Remote Containers extension, we’ll install Exiftool only in our Docker container, and debug the application inside the container. Let’s get going!

The Setup

The application is quite simple, all it does is run Exiftool against a PDF that is stored on the container. The goal of this post is to explore using the Remote Container extension, so nothing too complex is needed. Here is our code:

#golang #docker #visual-studio-code #debugging

Debugging Go Inside Docker, Using Visual Studio Code and Remote Containers
15.05 GEEK