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 $_
Now create a file called Dockerfile
. We’ll stay in the terminal and use vi
to do this.
vi Dockerfile
Now we will add the following line:
FROM ubuntu:latest
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 .
Now we can run bash directly on this container:
docker run -it ubuntu_test bash
We are now dropped into the container as seen by the prompt:
root@818d598207db:/#
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 $_
Create a Dockerfile
. As per usual, we will use vi
in the terminal to create our file.
vi Dockerfile
Add the following:
FROM centos:latest
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
We are now placed in our centos container as shown below:
[root@e761d60cf69c /]#
You should now run a yum update
to make sure everything is updated before running any yum install <package>