DEV Community

Samuel Lubliner
Samuel Lubliner

Posted on

Docker

Why Docker?

When collaborating on a repository shared by multiple people, Docker enables the team to share a consistent development environment. This ensures that everything runs the same and predictably across all machines. Additionally, Docker can help save resources on CodeSpaces and allows for offline development. VS Code Dev Containers offer a local alternative to GitHub CodeSpaces, providing a seamless development experience.

I recently acquired a Lenovo laptop with Windows. The hardware is an upgrade from my 2013 MacBook Pro, although my MacBook is more portable. With Docker and Windows Subsystem for Linux (WSL), I can work on the same code reliably across different machines, enjoying a Linux environment on Windows.

  • It's crucial to create your repositories within WSL rather than on the Windows file system. This improves performance and resolves some bugs. For instance, I discovered that live reloading became possible after storing files in WSL.

  • You know you're in Windows if the terminal looks like:

PS C:\Users\user-name>
Enter fullscreen mode Exit fullscreen mode
  • Open the terminal and run:
wsl --distribution Ubuntu
Enter fullscreen mode Exit fullscreen mode
  • Next, your terminal may look something like:
name@DESKTOP:/mnt/c/Users/name$
Enter fullscreen mode Exit fullscreen mode
  • Be careful, you are still in the Windows file system. Run cd to get back to the home directory. You should see:
name@DESKTOP:~$
Enter fullscreen mode Exit fullscreen mode
  • Now you can clone repositories and open them in a Dev Container from within the WSL file system for increased performance. The performance is improved because WSL offers better integration with Docker.
  • Alternatively, you can configure the WSL configuration file to open directly to the Linux home directory.

What is a Container?

Docker containers allow you to run code in a defined, isolated environment. This ensures consistency and reliability, as the environment remains the same regardless of where the container is run.

Up Next

Next time, we'll cover running a container. We'll create an image using a Dockerfile and a sample application.

Useful resources

You can download docker here:

https://www.docker.com/

Download the VS Code extensions:

https://code.visualstudio.com/docs/devcontainers/containers

Developing inside a Container:

https://code.visualstudio.com/docs/devcontainers/containers

Try out with different development environments:

https://github.com/search?q=org%3Amicrosoft+vscode-remote-try-&type=Repositories

https://github.com/Microsoft/vscode-remote-try-node

Top comments (0)