Access Your Dev Container With Visual Studio Code

Having a running dev container is a good start, but only when we can write code is it useful. Let’s look how we can use Visual Studio Code to develop inside our container.

 

Open your code in VS Code

Open your code in VS Code as you do with all your other projects. At the bottom left corner, you find the quick actions status bar item:

The quick action item is in the left bottom corner.

If you click on it, the command pallet opens and offers you a list of options for container development:

The command pallet allows you to connect to a running container or to create a new one for the current folder.

If you have a running dev container as we created last week, you can use (1) to connect VS Code to work with it. If you only have a docker-compose file, you can use (2), and VS Code creates the container for you.

Whatever you chose, VS Code opens up a new window that is running the code inside your (new) container. The first time you do that VS Code asks for additional plugins. If this happens, say yes to all questions and VS Code ensures that everything works.

 

Develop inside your container

If you take a closer look, VS Code changed the status bar and added a description to the Workspace entry:

The status bar shows an indicator that you run VS Code in a container

If you open a terminal, you see a prompt like this one that runs inside your container:

The terminal uses our /workspace folder in the container

You can now start developing your application in the container. Be aware, if you choose the new development container you may need to install the dependencies of your application first.

Do not forget to commit your changes and push them to your remote repository. VS Code should be able to do that directly from within the container. If not, use your regular Git tool outside the container to push those changes.

 

Additional resources

The official documentation for VS Code offers a lot of additional information on working with containers. You get a detailed explanation on how all that works and how you can optimize your workflow. Should you run into any problems you most likely will find a solution there.

 

Next

Next week we look how we can put PostgreSQL into a dev container.

1 thought on “Access Your Dev Container With Visual Studio Code”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.