How to Run Ubuntu Locally Using Docker (Beginner Guide)


Denny Lim

Denny Lim

·June 24, 2025·
LinuxUbuntu 24.04

Introduction

Trying Ubuntu doesn't have to mean installing it on your system or setting up a virtual machine. With Docker, you can run Ubuntu locally in an isolated container environment in just a few minutes. This guide is designed for beginners who want to explore Ubuntu using Docker without modifying their system.

Prerequisites

  • A computer with Windows, macOS, or Linux
  • Docker installed (Download from https://www.docker.com )
  • Basic familiarity with the command line (not required but helpful)

Step 1: Verify Docker Installation

To make sure Docker is installed correctly, open your terminal or command prompt and run:

docker --version

You should see something like:

Docker version 24.0.2, build cb74dfc

If you get an error, make sure Docker Desktop is running.

Step 2: Pull the Ubuntu Docker Image

Docker images are pre-built templates used to create containers. To download the latest Ubuntu image, run:

docker pull ubuntu

This command fetches the official Ubuntu image from Docker Hub.

Step 3: Run the Ubuntu Container

Now let’s run a container from the Ubuntu image:

docker run -it ubuntu

Here’s what the options mean:

  • -it: Runs the container in interactive mode with a terminal
  • ubuntu: The image to use

You’ll now be inside a shell running inside the Ubuntu container. Try typing:

ls

You’re in Ubuntu!

Step 4: Install Basic Tools (Optional)

Ubuntu containers are minimal by default. To install common utilities, use:

apt update apt install nano curl iputils-ping -y

This gives you a simple text editor (nano), a downloader (curl), and the ping command.

Step 5: Exiting the Container

To leave the Ubuntu shell, type:

exit

The container will stop when you exit unless you run it with special flags (like --rm=false or --detach).

Step 6: List and Restart Containers

To see stopped containers:

docker ps -a

To restart a container by its ID:

docker start -ai <container_id>

To remove it:

docker rm <container_id>

Bonus: Create a Persistent Ubuntu Container

If you want your container to persist (so you can keep files or install packages long-term):

docker run -it --name myubuntu ubuntu

This names your container myubuntu, so you can start it later with:

docker start -ai myubuntu

Conclusion

That’s it! You’ve now learned how to run Ubuntu locally using Docker. It’s a safe and fast way to explore Linux, try out commands, or test software—without altering your main operating system.

For more tips, check out:

Happy experimenting!