Docker container: Next Big Thing in Software Development 2/4

This post is the second of a series of four. I recommend you read the first one since we explain what Docker, docker container,  WSL is, how to install it, and all benefits we can get from having a flexible and versatile software development environment.

Let’s get started!

If you reached the end of the previous post, you might have got Docker Desktop up and running in your tray icon.

docker running

If Docker is not running yet, start Docker Desktop from the Windows Start menu, wait a couple of seconds until it loads completely, right-click at the whale icon and do the following:

    1. Make sure that the “Switch to Windows containers…” option is showing up; go to step 2; if it’s not, select “Switch to Linux containers…” wait a couple of seconds and then go to step 2.
    2. Select SettingsDocker container - Docker Desktop settings
    3. Select General on the left panel, click the Use WSL 2 based engine checkbox. If you have installed Docker Desktop on a system that supports WSL 2, this option will be enabled by default.Docker Desktop
    4. Click Apply & Restart.
    5. Ensure the distribution runs in WSL 2 mode. WSL can run distributions in both v1 or v2 manner. To check the WSL mode, go to Powershell or Windows Terminal and run: wsl -l -vIf needed, to upgrade your existing Linux distro to v2, run:  wsl --set-version distro name 2, here the distro name is Ubuntu-20.04.
      To set v2 as the default version for future installations, run:  wsl --set-default-version 2
    6. Go to Settings > Resources > WSL Integration, select any additional distributions you would like to enable WSL 2. Docker Desktop wsl2- choose distro for linux docker containerFor more information about installing Linux distros go to my first post and see the Install your Linux distribution of choice section for details.
    7. Click Apply & Restart.

Why WSL 2 for your software development environment?

To explain what we just did, we unveiled the WSL 2 powerful feature, which is predominantly a developer tool — mainly for but not limited to web developers and those who work on or for open source projects. WSL facilitates those who want or need to use Bash, popular Linux tools (sed, awk, etc.) and various Linux-first tools (Ruby, Python, etc.) to use their Windows development environment.

WSL provides an application named Bash.exe that opens a Windows console running the Bash shell when it is installed. Using Bash, you can run Linux software and applications on the command-line, but, as I said in the previous post, I recommend using Windows Terminal due to its numerous useful features. Use the down arrow on the right of the plus sign to open a bash terminal. Type cat /etc/*release and hit enter, for example; you will see details of the currently running Linux distro:Linux Distro - Release Info

Bash is a very popular and vastly used text-based shell and command-language. It is the default shell included within Ubuntu and other Linux distributions and in macOS. Users usually type commands into a shell to execute scripts and run commands and tools for many tasks the same way we use Powershell.

You can also access the filesystem of your machine from inside the shell of Linux Bash – you can find your local drives mounted under the folder /mnt. Your C: drive, for instance, is installed under /mnt/cSharing Windows Filesystem

Mount points for hard drives on your machine are automatically created and provide easy access to the Windows filesystem (e.g. /mnt/<drive letter>/).

The CI/CD pipeline can exemplify a typical development workflow that incorporates WSL2. Let’s say that I want to test it first on a local machine before deploying it to the cloud. I can enable WSL2 and then use a genuine Linux Ubuntu instance locally (on my laptop) with whatever Bash commands and tools I prefer. Once the development pipeline is verified locally, I can then push that CI/CD pipeline up to the cloud (e.g. Azure) by making it into a docker container and moving it to a cloud instance where it runs on a production-ready Ubuntu virtual machine.

Installing Visual Studio Code on Windows 10 – VSCode for short

Note: .NET Framework 4.5.2 or higher is a requirement for VSCode. You can check your version of .NET Framework using this command: reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\full" /v version from a command prompt..Net Framework version

    1. Download the Visual Studio Code installer for Windows.
    2. Once it is downloaded, run the installer (VSCodeUserSetup-{version}.exe). It will only take a minute.
    3. By default, VS Code is installed under C:\users\{username}\AppData\Local\Programs\Microsoft VS Code.

Develop using docker container and WSL2

This section will describe how to start your software development environment with Docker and WSL 2. We always recommend that you have your code residing in your default Linux distribution for a better development experience using Docker and WSL2. After enabled WSL2 on Docker Desktop, you can start working with your code inside the Linux distro and ideally with your IDE still in Windows. This workflow can be pretty straightforward if you are using VSCode.

    1. Open VSCode and install the Remote – WSL extension. It will take you to Visual Studio Marketplace. Click on install.VSCode Marketplace It will take you to VSCode already installed. Click on the green Install button right beside the penguin.Remote WSL - VSCode The extension allows you to work with a remote server in the Linux distribution and your IDE client on Windows.
    2. Now, let’s start working in VSCode remotely. To do so, open your Windows Terminal and type:wsl and press Enter.
      Type code . and press Enter. It will take a couple of seconds until VSCode shows up.download vscode from linux
      It will open a new VSCode connected remotely to your default Linux distro, which you can check in the bottom left corner of the screen.Rich software development with VSCode
      Alternatively, you can type the name of your default Linux distro in your Start menu, open it, and then run.: code .
    3. When you are in VSCode, you can use the terminal in VSCode to pull your code and start working natively from your Windows machine.

Congratulations, you have accomplished the second step of a series of four. You will soon experiment with a great software development environment using Windows and Linux to host parts of an application using the docker container concept and the Visual Studio Code. We will install Oracle and SQL Server Databases, IIS Application Server, Reverse Proxy with the very popular Nginx, NodeJS platform and some other useful tools and tips to help us to improve your productivity.

Do you want to know more about us and our mission? Click here, and don’t forget to subscribe!

We also have pro bono projects just in case you are interested in learning more about them.

Be aware of why we started this project by clicking here.

Learn more about other posts here.

Contact us for any suggestions. And follow us on FacebookInstagram and Twitter.

If you are a good reader like myself, I recommend the following readings:

  1. Docker Quick Start Guide: Learn Docker like a boss, and finally own your applicationsDocker Quick Start Guide: Learn Docker like a boss, and finally own your applications
  2. Docker for Developers: Develop and run your application with Docker containers using DevOps tools for continuous deliveryDocker for Developers: Develop and run your application with Docker containers using DevOps tools for continuous delivery

See you in the next post!

2 Replies to “Docker container: Next Big Thing in Software Development 2/4”

Leave a Reply