Automation Lab 1 | Docker

First post in the serie to deploy an Automation Virtual Lab.

Posted by PeCoBe on 2023-02-18 ·

Docker

Why Docker

Docker is a popular containerization technology that allows you to package an application with its dependencies into a lightweight and portable container.

From the official Docker's website:

“A container is a sandboxed process on your machine that is isolated from all other processes on the host machine”

As a QA engineer, this should make a lot of sense, and should be more than enough to understand why the use of Docker, or containers, is so popular. We are used to creating sandbox environments in order to test code and applications, to prevent external factors to affect our tests.

Is a dream come true for testers, an easy to deploy and maintain on demand environment, that is clean and that we can easily share with developers and other testers to easily reproduce defects, test workflows, and break the application without affecting other people.

Other benefits include:

  • Portability: With Docker, you can package your application and its dependencies into a container that can run on any platform, whether it's a developer's machine or a production server. No more configuration issues!

  • Consistency: Docker containers ensure that the application runs consistently across different environments, regardless of the underlying operating system or infrastructure. Sayonara "works on my machine" problem.

  • Isolation: Docker containers provide a high degree of isolation between the application and its host system. This means that you can run multiple containers on the same machine without worrying about conflicts between different applications or dependencies.

  • Efficiency: Docker containers are lightweight and consume minimal resources, making them ideal for running multiple instances of an application on a single machine or a cluster of machines.

  • Additionally, testers can use Docker to automate the deployment of their testing infrastructure, making it easier to manage and maintain.

Finally, with Docker, testers can collaborate more effectively with developers, as they can easily share container images and reproduce issues in a consistent environment.

In summary, Docker is a valuable tool for developers and testers alike. It provides a portable, consistent, and efficient way to package and deploy applications, making it easier to develop, test, and deploy software. As such, QA testers who learn how to use Docker can streamline their testing process and collaborate more effectively with developers.

Using Dockers with Windows and WSL

In this post we are going to prepare the bases for the creation of our own virtual lab, using Dockers and WSL. The only prerequisite is to have a Windows 10 version 2004, build 19041 or higher, or Windows 11.

For the purpose of this tutorial, we are going to assume we do 🙂

We are going to prepare the following:

  1. WSL 2 (Windows Subsystem for Linux)
  2. Docker Desktop.

Installing WSL 2

Open PowerShell in administrator mode, and enter the following command to install WSL. Restart your machine after that.

Install a Linux distribution, you have many options. Using wsl --list --online we can check what distributions are available for us:

And then install using wsl --install -d < Distribution Name >

Upgrading to WSL 2 By default, new installations will be set to WSL 2. To check this, we can use wsl -l -v

In case we have a WSL 1, we can change version using wsl --set-version < Distribution Name > 2

access using wsl (if is the default) Great! we are inside our Linux distribution, inside Windows!!

Installing Docker Desktop for Windows

  1. Donwload Docker Desktop for Windows from the official site.
  2. Follow the instructions. Remember to enable WSL 2 to continue.
  3. Start Docker Desktop.
  4. In the Docker menu, select Settings > General
  5. Select Use WSL 2 based engine.
  6. Select Apply & Restart

You Docker Desktop should look like this:

To verify everything is fine, inside your WSL enter docker and you should be able to see all the options to run the command:

Note: In this and all the following tutorials, we were going to use VSCode as our editor. We can quickly use to work with a remove server in the Linux distro. We can access it using, inside our Linux distro:

Playing around with Docker and WSL

After we successfully installed WSL 2 and Docker Desktop, we can start playing around. This in not going to be a deep Docker or WSL tutorial, but I will be explaining a few concepts at the time we complete the steps.

Basic concepts:

A few things to have in mind while we work with Docker:

  1. Docker image: Is a lightweight, standalone, executable package that includes everything needed to run an application, including the code, system tools, libraries, and settings.
  2. Start an image: We can run images, this is, start a container, and then interact with it. You can run multiple containers, independent of each other and the host.
  3. Docker Hub: We can find multiples images that we can download and use in the official Docker Hub site. We would need to download first, before we can start a container.

Running a web server

We are going to install NGINX in a Linux distribution, to use as a web server.

  1. With our PowerShell session open, enter WSL to open our default Linux Distribution.
  1. Go to the official NGINX Docker Hub page
  2. Open the Tag tab, and choose any version, we are going to use stable-perl. Use the command docker pull to download it. You can find it in the page.
  3. Another way to download it, is using the official name when creating a new container. Run the following command to run our NGINX web server
  1. Running docker images we can see all the images we have available:
  1. With this command, we started a container called "webserver", based on the "nginx" image that we downloaded, running in the background "-d" as a daemon, and map a host port to a container port "8080:80"
  2. We can verify our docker image is up and running, going to http://localhost:8080/

Congratulations!! You just ran a docker image running a web server. To stop the image we can use docker stop webserver to save resources.

That's all for now. In our next Docker tutorial, we will set up a more interesting web page in our web server, and prepare another container where we will install Mocha and Chai, to start our Automation Lab.