Docker

Using Docker with BusyBox

Containerization is one of the most influential technologies of the modern age. Using containers, we can develop, package, and ship the applications as standalone units that can run in any environment without needing to worry about compatibility of dependency installations.

At the forefront of containerization is Docker. Docker has provided all the tools and resources that are required to work with containerized applications in almost all environments.

In this tutorial, we will show you how to get started with the features of Docker by learning how to create and use the Docker containers using a minimalistic and lightweight Docker Linux distribution called BusyBox.

Requirements:

Before we start and learn how to configure the Docker containers, ensure that you have the following:

  1. A host that runs either Windows, macOS, Linux or any other Docker compatible system
  2. An installed Docker Engine version 23 and above is recommended

You can reference our tutorials on the topics to learn how you can install and configure Docker on your target host.

Once Docker is installed, you can verify its installation by running the following command:

$ docker --version

This command should return the version of your installed Docker Engine.

BusyBox in Docker

Before we dive into the practical matters of working with Docker images and containers, let us start by understanding what is BusyBox.

BusyBox is a minimalistic Linux distribution that contains a minimal set of common and useful Unix utilities and tools. You will often find it in embedded devices and applications as it is capable of running in small storage spaces.

In Docker, the BusyBox image allows you to run a small and efficient Docker container that runs on the Linux kernel without installing a Linux distribution such as Ubuntu or equivalent.

Create a Docker Container with Busybox

Now that we know and understands what BusyBox is, let us proceed and learn how to create a Docker container using BusyBox.

Before creating the container, we start by pulling the BusyBox image from the Docker Hub. Run the command as follows:

$ sudo docker pull busbox

The given command should download the latest version of the BusyBox image.

Once we have the image downloaded, we can proceed and run the container using the image. We can use the Docker “run” command as shown in the following:

$ sudo docker -itd --name docker_busybox busybox

The given command should create a container called “docker_busybox” using the downloaded BusyBox image. We also tell Docker to run the container in detached but interactive mode. This allows us to interact with the container using the shell.

Once you run the previous command, you should be dropped inside a shell session within the BusyBox container.

Run the Commands in the Container

We can run the commands inside the container to allow us to perform the operations on the system. Keep in mind that the BusyBox image is minimalistic and hence contains fundamental commands and core utilities such as echo, cd, ls, pwd, etc.

For example, you can run the “ls” command to list all files and directories inside that container as follows:

$ ls -la

To exit the container’s shell and return to your host machine, simply type “exit”.

Stop and Remove the Container

To stop the running container, use the following command:

$ sudo docker stop docker_busybox

To remove the container (whether it’s running or stopped), run the command as follows:

$ sudo docker rm docker_busybox

Remember that removing a container also deletes all its data unless you have the data persistency enabled for the container.

Conclusion

In this tutorial, we learned how to use Docker with the BusyBox image. We started by learning what is BusyBox, how to pull the image, and creating a container from the image.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list