Docker has revolutionized the way developers build, ship, and run applications. It's an open-source platform that provides a containerization solution, enabling developers to create portable and efficient environments for their applications to run on any system, regardless of the underlying infrastructure. In this blog we will learn how to run Ubuntu on Windows.
Let's say you are new to Linux and want to try it out or follow some tutorial to learn some commands on CLI, you will have to install Ubuntu on a separate machine, dual boot your machine with Ubuntu or use WSL (Windows Subsytem for Linux). All options are valid but require a lot of setup and configuration to make it work(WSL is still easy to install and use as compared to others). To solve this problem we can use Ubuntu as a container using Docker. We don't need much setup or the know-how of installation to run Ubuntu on Windows using Docker.
Before we get started, You will need to make sure that you have Docker installed on your Windows machine. You can download Docker from the official website, https://www.docker.com/, and follow the installation instructions.
Once, it's installed, you need to launch the Docker Desktop application from the system tray.
We need to get the ubuntu image from docker hub on our local machine. To do this you need to open Powershell/Terminal and type the following command:
docker pull ubuntu
It will take some time based on your connection speed.
Once the image is pulled you can check it by using the command
docker images which will list all the images available on your machine. You can also check the same on Docker Desktop.
Now we need run this Ubuntu image as a container. For this we will type in the following command:
docker run -t -d --name myubuntu ubuntu
-t - Tells the container to run in a TTY mode. Reference
-d - Specifies the image to run in a detached mode.
--name - We specify the name of the conatiner we want, which can be anything.
And, lastly the image name, which is ubuntu.
After this command is executed, it will return the container ID, which tells us that the container is up and running successfully. You can verify the same by typing
Finally to work with the Linux CLI, we type in the following command:
docker exec -it myubuntu bash
-it - Will open an interative bash terminal
NOTE: The linux will be minified version and thus you will need to install the packages and dependencies you require using
apt install <pacakage-name>.
Mission acomplished! We can now play around with linux and do a lot of cool stuff with it. For beginners you can learn basic navigation commands, admin tasks such as newtwork administartion, securing linux servers, user and groups managements, etc.