DEV Community

Cover image for Learn Linux CLI Commands Using Docker | A Beginner's Guide
Khaled Md Saifullah
Khaled Md Saifullah

Posted on

Learn Linux CLI Commands Using Docker | A Beginner's Guide

If you want to learn Linux, you do not necessarily need to install Linux on your computer or set up a virtual machine.

You can start learning Linux commands using Docker.

Docker allows you to run a Linux environment inside a container, making it easy to practice common Linux commands directly from your terminal. Whether you are a developer, a DevOps beginner or someone curious about Linux, this is a simple way to get started.

In this blog, we will explore how to use Docker to practice Linux CLI commands step by step.

Why Learn Linux Using Docker?

Linux is an essential skill for anyone interested in software development, cloud computing, or DevOps. Many servers, cloud environments and containerized applications run on Linux.

However, beginners sometimes hesitate to install Linux because they are worried about changing their operating system or setting up a virtual machine.

Docker makes the process easier. You can start a Linux container in seconds, practice commands and remove the container when you finish.

Step 1: Install Docker

First, make sure Docker is installed on your computer.

Check your Docker installation by running docker --version

If Docker is installed and running, you are ready to continue.

Step 2: Start a Linux Container

Let's use Ubuntu, one of the most popular Linux distributions for beginners.

Run this command

docker run -it --name linux-lab ubuntu:24.04 bash
Enter fullscreen mode Exit fullscreen mode

Docker will download the Ubuntu image if it is not already available locally and start an interactive container.

You are now inside a Linux environment!

Step 3: Practice Basic Linux Commands

Now you can start exploring Linux from the terminal.

Check your current directory

pwd
Enter fullscreen mode Exit fullscreen mode

List files and directories

ls -la
Enter fullscreen mode Exit fullscreen mode

Check the current user

whoami
Enter fullscreen mode Exit fullscreen mode

Display system information

uname -a
Enter fullscreen mode Exit fullscreen mode

Navigate to another directory

cd /tmp
Enter fullscreen mode Exit fullscreen mode

Create a directory

mkdir linux-practice
Enter fullscreen mode Exit fullscreen mode

Create a file

touch hello.txt
Enter fullscreen mode Exit fullscreen mode

Write some text into the file

echo "I am learning Linux with Docker!" > hello.txt
Enter fullscreen mode Exit fullscreen mode

Read the file

cat hello.txt
Enter fullscreen mode Exit fullscreen mode

These simple commands introduce you to navigation, file management and basic Linux terminal operations.

Step 4: Practice Installing Packages

Linux users often install software through a package manager. Ubuntu uses APT for this purpose.

Inside the container, run

apt update
apt install -y curl
Enter fullscreen mode Exit fullscreen mode

After installation, check the version

curl --version
Enter fullscreen mode Exit fullscreen mode

You have now practiced updating package information and installing software inside a Linux environment.

Step 5: Exit and Reuse Your Container

When you finish practicing, exit the container

exit
Enter fullscreen mode Exit fullscreen mode

Your container stops, but it is not automatically deleted.

You can start it again later

docker start -ai linux-lab
Enter fullscreen mode Exit fullscreen mode

When you want to remove the container and its writable filesystem, exit the container and run

docker rm linux-lab
Enter fullscreen mode Exit fullscreen mode

You can create a fresh Ubuntu container whenever you want to start over.

One important thing to remember: files created inside a container's writable filesystem are generally removed when you delete the container. If you want to keep your practice files, use a Docker volume or bind mount.

What Should You Learn Next?

Once you are comfortable with basic commands, start exploring Linux permissions, users and groups, process management, networking, environment variables and shell scripting.

You can practice commands such as chmod, chown, ps, top, ip and grep. Some commands may require additional packages or capabilities depending on the container environment.

As you progress, try building small Linux practice labs using Docker Compose.

Final Thoughts

Learning Linux does not have to be complicated. You do not need a dedicated Linux machine to get started and you do not need to be afraid of breaking your existing operating system.

With Docker, you can create a Linux environment, practice commands, experiment with files and learn at your own pace.

If you are planning to learn DevOps, Docker, Kubernetes or AWS, start by getting comfortable with the Linux command line. It will make many of the concepts you learn later much easier to understand.

Have you tried learning Linux using Docker? Share your experience in the comments!

Linux #Docker #DevOps #LinuxCommands #Beginners

Top comments (0)