26

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.

mchinaloy
  • 1,444
  • 3
  • 25
  • 42

2 Answers2

9

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

Robert J
  • 840
  • 10
  • 20
  • 1
    Just what I needed, thanks! `/sbin` was not in the path for me, either. – WhatIsHeDoing Jun 28 '19 at 14:23
  • docker 10.10.17, is alpine 3.15 image, no apk, sbin is empty. it may be because the client cleaned it out, its a client image, and it prob was stripped to bare essentials(partially even for security), would this make sense? this is a prometheus only image also, if that rings any bells to anyone . EDIT, maybe this isnt alpine, and no -release file anywhere.. (no apk,yum,apt,dnf,pacman,etc..) – blamb Oct 13 '22 at 17:10
0

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

mchinaloy
  • 1,444
  • 3
  • 25
  • 42
  • Could you detail how it solved your issue? It's not obvious but I'm curious since I have the same original issue :) – user1075613 Sep 20 '22 at 14:12