How to use Docker to test any Linux distribution locally

I often need to test a specific Linux binary or make sure something works as expected from yum install or apt install.

To do this, it’s common to have a virtual machine lying around, or even a VPS that you can just quickly log into.

Things are a bit easier and quicker if you use Docker.

Let’s run two tests, the first one to get going with Ubuntu, and the second to get going with Centos.

Ubuntu in 30 seconds

Head over to your terminal and type the following:

mkdir -p ~/tmp/docker_testing/ubuntu && cd $_
Code language: Bash (bash)

Now create a file called Dockerfile. We’ll stay in the terminal and use vi to do this.

vi Dockerfile
Code language: Bash (bash)

Now we will add the following line:

FROM ubuntu:latest
Code language: Dockerfile (dockerfile)

Now press ESC, followed by :x to save and exit vi.

From the terminal window we can now build the Dockerfile:

docker build -t ubuntu_test .
Code language: Bash (bash)

Now we can run bash directly on this container:

docker run -it ubuntu_test bash
Code language: Bash (bash)

We are now dropped into the container as seen by the prompt:

Code language: Bash (bash)

We will now run an apt update followed by the apt search <package> that we want to install.

CentOS in 30 seconds

The setup for CentOS is pretty much the same as we did above for Ubuntu. However, if you weren’t paying attention, let’s run it again quickly:

mkdir -p ~/tmp/docker_testing/centos && cd $_
Code language: Bash (bash)

Create a Dockerfile. As per usual, we will use vi in the terminal to create our file.

vi Dockerfile
Code language: Bash (bash)

Add the following:

FROM centos:latest
Code language: Dockerfile (dockerfile)

Now press ESC, followed by :x to save and exit vi. Then let’s build and run our Docker image!

docker build -t centos_test . docker run -it centos_test bash
Code language: Bash (bash)

We are now placed in our centos container as shown below:

Code language: Bash (bash)

You should now run a yum update to make sure everything is updated before running any yum install <package>

Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
trackback

[…] I often need to test a specific Linux binary or make sure something works as expected from yum install or apt install. To do this, it’s common to have a virtual machine lying around, or even a VPS that you can just quickly log into. Things are a bit easie… Read more […]