You may have a need to keep multiple versions of an executable (like java) on your system. Perhaps most of your system will work with Java 8, but one application needs Java 7.

The alternatives program lets you switch from one version to another, quickly.

EDIT: For other reasons you may want to do this, see What is the difference between JAVA_HOME and update-alternatives? and Better way to add alternative using update-alternatives?

From man alternatives:

It is possible for several programs fulfilling the same or similar functions to be installed on a single system at the same time. For example, many systems have several text editors installed at once. This gives choice to the users of a system, allowing each to use a different editor, if desired, but makes it difficult for a program to make a good choice of editor to invoke if the user has not specified a particular preference.

The alternatives system aims to solve this problem. A generic name in the filesystem is shared by all files providing interchangeable functionality. The alternatives system and the system administrator together determine which actual file is referenced by this generic name.


Answer from StandardEyre on Stack Exchange
🌐
Stack Overflow
stackoverflow.com › questions › 39975866 › docker-ubuntu-update-alternatives
Docker Ubuntu update-alternatives - Stack Overflow
you want to chain all your RUNs so it should be something like: RUN apt update && apt install -y gcc-4.9 g++-4.9 cmake make gfortran-4.9 make git wget && update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 10 && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 10 && update-alternatives --install /usr/bin/gfortran gfortran /usr/bin/gfortran-4.9 10
🌐
Data-mining
data-mining.co.nz › docker-for-data-scientists › tips_and_tricks
Tips & Tricks - Docker for Data Scientists
update-alternatives --install /usr/bin/python python /usr/bin/python3.5 1 && \ update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2 && \ update-alternatives --set python /usr/bin/python3.6 && \ update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1 && \ update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2 && \ update-alternatives --set python3 /usr/bin/python3.6 && \
Discussions

docker - Why use the alternatives command? - Unix & Linux Stack Exchange
I'm following instructions from this site about building a spring-boot docker container. They are using CentOS. In their dockerfile, they call the alternative command several times. I would li... More on unix.stackexchange.com
🌐 unix.stackexchange.com
Use update-alternatives for docker-compose
Should the install script use update-alternatives to link back to the newer docker-compose-plugin? update-alternatives --install /usr/local/bin/docker-compose docker-compose /usr/libexec/docker/cli-plugins/docker-compose 1 This would cre... More on github.com
🌐 github.com
0
October 26, 2022
What's the best Docker updates management tool?
For me, Komodo is by far the best Docker management software and also includes intuitive update functions. I love it! More on reddit.com
🌐 r/homelab
5
0
July 29, 2025
Creating a docker container with a specific compiler version requires update-alternatives to be added as the last line of the Dockerfile - Stack Overflow
However, we have to use the same update-alternatives for this purpose, once to ensure that our other packages are installed with the correct compiler, and once again in the end to ensure that anything that is executed in the container uses the specified versions as well. If we omit the last part, the originally present compiler will be used. Why is this happening, and is there a more efficient way we can design our Dockerfile... More on stackoverflow.com
🌐 stackoverflow.com
🌐
XDA Developers
xda-developers.com › home › software and services › i stopped using watchtower and found something better for docker updates
I stopped using Watchtower and found something better for Docker updates
February 20, 2026 - Tugtainer provides me with the control and visibility to monitor Docker container updates without manual checks. If auto-updates are breaking your containerized system in your home lab, Tugtainer is the perfect alternative to Watchtower.
🌐
Wiz
wiz.io › academy › container-security › top-docker-alternatives
Top Docker Alternatives for 2026 | Wiz
February 26, 2026 - Declarative management with rolling ... healthy containersSimple CLI experience: Builds on existing Docker CLI knowledge · Rancher Desktop is a free, open-source alternative to Docker ......
🌐
GitHub
github.com › docker › docker-install › issues › 320
Use update-alternatives for docker-compose · Issue #320 · docker/docker-install
October 26, 2022 - Should the install script use update-alternatives to link back to the newer docker-compose-plugin? update-alternatives --install /usr/local/bin/docker-compose docker-compose /usr/libexec/docker/cli-plugins/docker-compose 1 This would cre...
Author   docker
Find elsewhere
Top answer
1 of 1
1

🚨 For working Dockerfile see end of answer. Here's some of the reasoning for how I got there.

I think you'll find that you are not actually using GCC 10 to compile the PETSc code.

Try inserting RUN gcc --version immediately before you clone and build the PETSc repository. I think you'll find that you see something like this:

Step 13/13 : RUN gcc --version
 ---> Running in dc6e2b3c0095
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

This means that, despite you setting an alternative version of the compiler prior to that it's still reverting to the default compiler. Why?

The reason for this is that something in the subsequent apt-get install is reverting the compiler change. If you change the order of operations to this then you'll find that GCC 10 is in effect when you come to compile PETSc.

RUN apt-get install -y build-essential git python3 openssh-server openssh-client python3-pip ffmpeg libsm6 libxext6 cmake pkg-config \
                       openmpi-bin libopenmpi-dev

RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${COMPILER_VERSION} 60 && \
    update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-${COMPILER_VERSION} 60 && \
    update-alternatives --install /usr/bin/gfortran gfortran /usr/bin/gfortran-${COMPILER_VERSION} 60

Now you should see this before the clone/compile step:

Step 13/13 : RUN gcc --version
 ---> Running in 77abf17d52bc
gcc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

But now there's a snag: there's an error in the PETSc build. It prefers the default compiler version!

My suggestion is to simply remove the first set of update-alternatives commands because they are not having any effect on the subsequent build.

Anyway, here's a complete Dockerfile that should do what you want without duplication. I had to install an updated CMake.

ARG UBUNTU_VERSION=20.04
FROM ubuntu:${UBUNTU_VERSION}

ARG COMPILER_VERSION=10
ARG PETSC_VERSION=v3.18.6

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
    apt-get install -y \
        software-properties-common \
        gnupg \
        wget \
        lsb-release
RUN add-apt-repository ppa:ubuntu-toolchain-r/test

# For recent CMake version.
#
RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc | gpg --dearmor - | tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null
RUN echo "deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu $(lsb_release -cs) main" | tee /etc/apt/sources.list.d/kitware.list

RUN apt-get update
RUN apt-get install -y \
        gcc-${COMPILER_VERSION} \
        g++-${COMPILER_VERSION} \
        gfortran-${COMPILER_VERSION} \
        build-essential \
        git \
        python3 \
        openssh-server \
        openssh-client \
        python3-pip \
        ffmpeg \
        libsm6 \
        libxext6 \
        cmake \
        pkg-config \
        openmpi-bin \
        libopenmpi-dev

RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${COMPILER_VERSION} 60 && \
    update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-${COMPILER_VERSION} 60 && \
    update-alternatives --install /usr/bin/gfortran gfortran /usr/bin/gfortran-${COMPILER_VERSION} 60

RUN python3 -m pip install pytest numpy h5py pathlib requests pandas matplotlib plotly scikit-learn PyYAML Pillow vtk types-PyYAML pytest-cov

RUN echo "Using PETSC_VERSION: ${PETSC_VERSION}"
RUN git clone -b ${PETSC_VERSION} https://gitlab.com/petsc/petsc.git /petsc && \
    cd /petsc && \
    ./configure \
        PETSC_ARCH=linux-gnu \
        --with-fc=gfortran --with-cc=gcc --with-cxx=g++ \
        --with-fortran-bindings \
        --download-openmpi \
        --with-mpi-f90module-visibility=1 \
        --download-fftw \
        --download-hdf5 \
        --download-hdf5-fortran-bindings \
        --download-fblaslapack \
        --download-scalapack \
        --download-ml \
        --download-zlib && \
    make all

ENV PETSC_DIR /petsc
ENV PETSC_ARCH linux-gnu

ENV OMPI_ALLOW_RUN_AS_ROOT 1
ENV OMPI_ALLOW_RUN_AS_ROOT_CONFIRM 1
🌐
XDA Developers
xda-developers.com › home › software and services › with watchtower getting discontinued, here’s what i use to update docker containers
With Watchtower getting discontinued, here’s what I use to update Docker containers
February 9, 2026 - But if you’re willing to spend some time configuring all the watchers, triggers, and labels, you’ll find What’s Up Docker a fantastic alternative to Watchtower.
🌐
XDA Developers
xda-developers.com › home › i gave up watchtower for this docker update tool, and i’m never going back
I gave up Watchtower for this Docker update tool, and I’m never going back
April 20, 2025 - That was the tipping point for me to find an alternative that was just as convenient but didn’t mess with the workflow, which led me to Diun. ... Diun (short for Docker Image Update Notifier) is a lightweight tool that does one thing well: it tells me when a new container image update is ...
🌐
Groundcover
groundcover.com › observability, for the cloud. › groundcover blog | check our latest articles › top 12 docker alternatives in 2026: features & comparisons
Top 12 Docker Alternatives in 2026: Features & Comparisons
3 weeks ago - This nuance matters because finding a Docker alternative requires deciding which parts of Docker, exactly, you want an alternative to – and not all alternate technologies are drop-in replacements for the complete Docker platform. For example, Kubernetes is an alternative to Docker in the sense that Kubernetes can orchestrate and manage containers.
🌐
CloudZero
cloudzero.com › home › blog › 15+ best docker alternatives for containers and beyond
15+ Best Docker Alternatives For Containers And Beyond
August 12, 2025 - It builds container images without needing a Docker daemon — perfect for Kubernetes-native environments. With Werf, you can define and track builds directly from Git commits, making deployments repeatable and auditable. It also integrates with existing tools, such as GitLab CI/CD, GitHub Actions, and ArgoCD. Red Hat OpenShift is a Kubernetes platform that integrates with DevOps tools to improve functionality. It boasts robust features, including automated updates, built-in CI/CD tools, and top-notch security protocols.
🌐
Spacelift
spacelift.io › blog › docker-alternatives
Top 12 Most Useful Docker Alternatives for 2026 [List]
3 weeks ago - Podman’s CLI is Docker-compatible. Most commands can be converted by simply replacing docker with podman, such as podman ps and podman run instead of docker ps and docker run. Podman also has a graphical desktop app, Podman Desktop, which is an open-source alternative to Docker Desktop.
🌐
Reddit
reddit.com › r/docker › updating all docker containers
r/docker on Reddit: Updating all Docker containers
March 15, 2023 -

I've been discovering docker in the past days and I now have several containers running on my Synology NAS via docker compose.

I was wondering how I can keep my containers up to date so that I don't miss security updates but I don't know how to best deal with it.

The first option I found would be to regularly go in each and every folder where my docker-compose files are and do the following but it's too tedious to do it very regularly :

docker compose pull && docker compose up -d

The second option I came across is Watchtower but I read mixed things about it.

How do you handle this? Is there a more elegant solution?

Thanks!

🌐
Igmguru
igmguru.com › blog › docker-alternatives
15 Best Docker Alternatives in 2026 | igmGuru
3 weeks ago - In this article, I'll walk you through what Docker is (a refresher), where I've found limitations, why we might need alternatives, and then dive into some of the strongest contenders like Podman, containerd (with nerdctl), and LXC.
🌐
Reddit
reddit.com › r/selfhosted › watchtower is no longer maintained... alternatives/ decent forks?
r/selfhosted on Reddit: Watchtower is no longer maintained... alternatives/ decent forks?
February 13, 2026 -

Hey,

just saw that: https://github.com/containrrr/watchtower is no longer maintained.
I use Watchtower to automatically update my Docker containers and notify me via nfty.

The original creator stated "There are a few forks out there - unfortunately I know nothing about them so can't really vouch for their legitimity. If you want to continue using Watchtower, please assess them yourself without switching. A few of the active forks I've looked at are full of AI slop and while they might work, I wouldn't advice using any of them."

Now I am wondering if this https://github.com/nicholas-fedor/watchtower is a decent fork or if its the so called AI slop? I'm no expert myself and cant confirm this for myself unfortunately.

What do you guys think?

🌐
guvi.in
studytonight.com › linux-guide › update-alternatives-command-in-linux
update-alternatives Command in Linux
February 13, 2023 - Docker - docker run cmd.cat/update-alternatives update-alternatives · update-alternatives [option...] command · Let's say you have Python 2 and Python 3 installed on your PC as an example. You can create a new Python executable (/usr/local/bin/python) and add every Python version that is currently available to the alternatives database by using the update-alternatives command.
🌐
Reddit
reddit.com › r/selfhosted › what’s your preferred way to update docker images & containers in the background?
r/selfhosted on Reddit: What’s your preferred way to update Docker images & containers in the background?
January 12, 2026 -

Hey everyone,

I’m fairly new to self-hosting and Docker, and I’m curious how others handle keeping their containers up to date.

What are your best practices for:

  • Pulling updated images

  • Restarting containers with minimal downtime

  • Running updates automatically or in the background

  • Avoiding breaking changes when images update

Do you rely on tools like Watchtower, custom scripts + cron, CI/CD pipelines, or manual updates?

I’d love to hear what’s been working well for you (and what you’d avoid). Thanks!

🌐
SigNoz
signoz.io › comparisons › 15 best docker alternatives for 2026: complete guide with pros, cons & migration
15 Best Docker Alternatives for 2026: Complete Guide with ...
1 week ago - While it can use existing Dockerfiles, migrating CI/CD pipelines may require rewriting build scripts. Best Use Cases: Building container images in CI/CD pipelines, creating custom build workflows, and in secure environments where a daemon is not desirable. ... Rancher Desktop is a free and open-source application for Mac, Windows, and Linux that provides a graphical user interface (GUI) for container management. It's a popular alternative to Docker Desktop, especially for developers.