66

I thought I understood Docker. I understood it as a way to package up software with lots of dependencies..to basically create a little world where absolutely everything is taken care of for a piece of software. Then I stumbled upon this on DockerHub

https://hub.docker.com/_/busybox/

It's an image for BusyBox, which is a tiny little Linux binary that is meant for embedded systems. Then the top comment says:

Busybox is awesome :) By far the most useful container per byte on the entire registry.

But I don't understand at all why this image exists, which makes me think that I don't actually understand why Docker exists. What is the point of a BusyBox docker image?

halfer
  • 19,824
  • 17
  • 99
  • 186
techgnosis
  • 1,879
  • 2
  • 17
  • 19

3 Answers3

44

A Busybox docker image is useful if one is building a container for which busybox can fulfill its dependency chain without needing a full Linux distro.

Often, an embedded appliance can consist of nothing but a statically-linked copy of busybox, an init script that mounts procfs, sysfs, &c. with busybox-provided tools, and then the actual application being invoked. With docker setting up the filesystem namespace, even that init script isn't necessarily needed.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • 3
    I see. So there are some deep things I don't understand about Docker. Are you saying that you use the busybox image as part of another larger docker image? – techgnosis Oct 22 '15 at 22:02
  • 8
    Just about *all* your public docker images are intended to be used as a base. – Charles Duffy Oct 22 '15 at 22:03
  • Alright then, thanks. I'll look into what that means. – techgnosis Oct 22 '15 at 22:03
  • 3
    ...so, you take the public Debian X.Y image, tell Docker you want to add an extra file to it / install a package onto it / bind-mount something from the host into it, and then that's your actual application container. – Charles Duffy Oct 22 '15 at 22:04
  • 3
    ...here, you just have something much lighter and thinner than a Debian/Ubuntu/CentOS/etc. base. – Charles Duffy Oct 22 '15 at 22:05
  • 7
    Oh, duh. This is obvious in hindsight. You're talking about saying "FROM busybox" instead of from a fatter Linux distribution. That makes tons of sense. I dun got confused... – techgnosis Oct 22 '15 at 22:17
  • Yup, exactly. Though I wouldn't be surprised if the actual use case for this one wasn't more about just letting people test busybox quickly (ie. to determine functionality that is/isn't supported in a release compiled with all options enabled) without needing to install much anything on their host. – Charles Duffy Oct 22 '15 at 22:21
  • 1
    I've just used the busybox Docker image in a production environment, in a way that even using the Debian image would be harder to use. I just wanted to fetch a file using `wget` and `unzip` it. Not only both tools come pre-installed, but the `unzip` from busybox accepts zip files from stdin. The `unzip` from Debian doesn't. busybox is just a builder, where it starts with `FROM busybox as build` and the actual image just copies the unzipped file with `COPY --from=build`. Other than that, as someone pointed out, you can just use the tools in a Docker network, with no setup required. – Asrail Nov 01 '19 at 23:57
  • @CharlesDuffy hi it is 2021 but I still don't understand the use case of busybox, can you like at my question here ? Thank! https://stackoverflow.com/questions/67529042/what-is-the-difference-between-alpine-docker-image-and-busybox-docker-image – Qiulang May 18 '21 at 04:46
20

In addition to being a convenient base to use for other docker images. Busybox also makes a very convenient initContainer for kubernetes: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/

Say you need something to happen that sets up the pod filesystem before your real container starts running then busybox is great at this..

As a concrete example the official redis image doesn't run redis as root and so it cannot access the filesystem. If you were running redis with disk backup (in appendonly mode for example) you would need to open up that disk permission for it.

a valid (though probably hacky) initContainer for a statefulSet of redis might looks something like so:

      initContainers:
      - name: redis-data-permission-fix
        image: busybox
        command: ["/bin/chmod", "-R", "777", "/opt/data/redis"]
        volumeMounts:
        - name: data
          mountPath: /opt/data/redis
6

But I don't understand at all why this image exists, which makes me think that I don't actually understand why Docker exists. What is the point of a BusyBox docker image?

I just started using BusyBox with docker, but so far it has been convenient to use with the --rm command to create unsaved instances with common built in utilities like ping, and yeah just ping so far :/

docker container run --rm -it --network [network_name] busybox

and then all those utilities in BusyBox are available on that docker custom network and instantly destroyed when you exit the BusyBox CLI

skosari
  • 95
  • 1
  • 6