0

I recently installed Docker Desktop app version 4.22.0 on macOS Ventura on a Mac with Apple Silicon (ARM, not Intel). I successfully pulled and ran a couple of containers: one for MySQL database server, and one for Postgres database server.

Unfortunately, when I went to edit some configuration files for those servers, I was surprised to find basic utilities missing: zsh shell and nano text-editor.

Within a single container, I did successfully execute:

apt update 
apt install nano

That worked for just that one single container. The other containers continue to lack the nano editor. That lack is understandable given that the purpose of containers is to be isolated from one another.

I would like these utilities to appear in all my containers within Docker Desktop app.

👉🏼 Is there a simple way to install these console apps into the underlying base Linux, to be shared across containers?

Emphasis on simple. My goal in using Docker Desktop is to learn as little as possible about Linux, and about Docker. I merely want to conveniently run some servers for local app development & testing. After some web searching, the only advice I found was to "roll your own image" which seemed to mean creating and maintaining my own Linux installation — which exceeds my knowledge, my interest, and my purpose in choosing to use the Docker Desktop app.

4
  • 1
    "which seemed to mean creating and maintaining my own Linux installation" lol no. You create a copy of the config file you want to change, then create a Dockerfile that basically does FROM some-base-image COPY my/config/file /etc/some/config and run docker build. Definitely easier than hacking around Docker to get it to run apt update; apt install nano in random Docker images, some of which might not even have apt (or even any package manager at all).
    – muru
    Aug 23, 2023 at 6:21
  • 1
    Also these database images often are highly configurable using environment variables, but how exactly depends on the image. And also: There is no common "underlying base Linux" for these images. While there is a Linux VM being run, accessing that VM doesn't get you any closer to accessing the containers themselves.
    – muru
    Aug 23, 2023 at 6:22
  • advanced shells like zsh isn't basic at all. Many distros don't even have bash and only have pure sh, ash or dash
    – phuclv
    Aug 23, 2023 at 10:08
  • @phuclv to be fair, though, a lot of container images do contain bash (debian's default images do!) and the installed size of the zsh package, which includes a lot of completions and scripts on e.g. fedora is 8188 kB, for bash it's 8375 kB, and nobody argues that bash is the "mightier" shell (I'd very much question that, actually) Aug 23, 2023 at 13:11

1 Answer 1

3

The whole idea of docker images is that, no. There isn't a way. If you want to change the base layer of images, then you need to change that base layer and rebuild the image atop of it.

The idea here is that image layers are immutable, so it's easy to reason about what version things are in, what is guaranteed to work at each point, and so on.

So,

the only advice I found was to "roll your own image"

reflects what this system is supposed to do. However, that's not actually as hard as you presume. The things you need to write has four lines (my example below is just intentionally verbose!)

Say you have an image named "foobar" that you want to make sure contains nano and zsh. Well, as you noted, if that foobar image uses apt for installing software (i.e., it's some debian, or debian derivative like Fedora), you can run apt installs -y zsh nano and get these. All you need to do then is make an image out of that new state.

That's rather easy. Create a text file, containing but the following

FROM foobar

# Reminder for yourself that you're the one who built this
LABEL maintainer="[email protected]"

# you get to pick a version, relatively freely.
# If you feel like it works for you as you want, I'd recommend to start using 1.something
LABEL version="0.0.1"

# The "line continuation" \ at the end of each line are important; they
# "swallow" the line break character, otherwise the RUN command will break.
#
# Set the frontend for apt to "Don't ask me any questions, please"==noninteractive;
# and be -q (uiet), answer -y (es) to everything
# and also don't install fancy stuff that you get recommended, let's keep this slim
RUN apt-get update;\
    DEBIAN_FRONTEND=noninteractive apt-get install \
    --no-install-recommends -q -y \
    nano \
    vim \
    && \
    apt-get clean && apt-get autoclean

save as "Dockerfile-improved-foobar", and run

docker build -f Dockerfile-improved-foobar -t foobar-with-tools

When you now run docker images you'll see foobar-with-tools in there! And you can use it like any other image that you get e.g. automatically from dockerhub.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .