Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Alpine /bin/sh apk not found

Tags:

I am building a new Docker image with:

FROM alpine:3.4 RUN apk upgrade --update 

However, its failing with the error:

[INFO] /bin/sh: apk: not found 

This seems to work fine on my local machine (Mac OSX) but when I try building it on a Linux CentOS 7 machine it fails.

like image 652
Mike Chinaloy Avatar asked Oct 26 '16 13:10

Mike Chinaloy


People also ask

Does Alpine have bin sh?

Alpine Linux comes with BusyBox. It is described as “The Swiss Army Knife of Embedded Linux.” BusyBox combines tiny versions of many standard UNIX utilities into a single small executable, including /bin/sh.

How do I install an Alpine package in Linux?

Add a PackageUse add to install packages from a repository. Any necessary dependencies are also installed. If you have multiple repositories, the add command installs the newest package. If you only have the main repository enabled in your configuration, apk will not include packages from the other repositories.

Can you install Docker on Alpine?

To install Docker on Alpine Linux, run apk add --update docker openrc. The Docker package is available in the Community repository. Therefore, if apk add fails because of unsatisfiable constraints error, you need to edit the /etc/apk/repositories file to add (or uncomment) a line.

What is Alpine version in Docker?

What is Alpine Linux? Alpine Linux is a Linux distribution built around musl libc and BusyBox. The image is only 5 MB in size and has access to a package repository that is much more complete than other BusyBox based images. This makes Alpine Linux a great image base for utilities and even production applications.


2 Answers

I ran into something like this. It completely blew my mind, and I was questioning my sanity for a bit until I realized that /sbin wasn't in my container's PATH.

# interactive session PATH="${PATH}:/sbin"  # Dockerfile ENV PATH="${PATH}:/sbin" 

If you type command -v apk in an interactive session in your container's base image and compare that directory with the container's $PATH that should get you squared away.

If command -v apk doesn't work for you, you could try to find it via

find / -name apk -type f -exec dirname "{}" ";" 

To the best of my knowledge this is always in /sbin. However you get there, just ensure that the apk binary's location is part of $PATH

TL;DR - If you see this error, ensure that your executable's dirname is in your $PATH

like image 147
Robert J Avatar answered Sep 17 '22 14:09

Robert J


In the end we upgraded our projects to use this Docker Maven plugin: https://github.com/fabric8io/fabric8-maven-plugin. No issue thus far.

like image 45
Mike Chinaloy Avatar answered Sep 20 '22 14:09

Mike Chinaloy