I created a docker image from openjdk:8-jdk-alpine but when I try to execute simple commands I get the following errors:
RUN bash
/bin/sh: bash: not found
RUN ./gradlew build
env: can't execute 'bash': No such file or directory
docker run --rm -i -t alpine /bin/sh
Alpine docker image doesn't have bash installed by default. You will need to add the following commands to get bash
:
RUN apk update && apk add bash
If you're using Alpine 3.3+
then you can just do:
RUN apk add --no-cache bash
To keep the docker image size small. (Thanks to comment from @sprkysnrky)
Try using RUN /bin/sh
instead of bash.
bash
package adds about 4MB to the size of alpine:3.8
, roughly doubling it, but still far from 50MB.
sh
rather than install bash
as it increases the size of the image.
RUN /bin/sh -c "apk add --no-cache bash"
worked for me.
RUN apk add --no-cache bash
directly
To Install bash you can do:
RUN apk add --update bash && rm -rf /var/cache/apk/*
If you do not want to add extra size to your image, you can use ash
or sh
that ships with alpine.
Reference: https://github.com/smebberson/docker-alpine/issues/43
If you have the option (for instance if you are just creating the script), using an alpine image with bash installed such as alpine-bash might be clever.
The official bash image is based on Alpine and prevents you from needing to install bash every time. Simply use
docker pull bash
This was first published on Oct 19, 2016 at 6:43 pm.
Success story sharing
apk upgrade
is not required.RUN /bin/sh
instead ofRUN bin/bash
bash
specific feature.--no-cache
option?