Reputation: 6055
I created a docker image from openjdk:8-jdk-alpine
and I want to use bash
, rather than sh
as my shell, however 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
Upvotes: 473
Views: 470167
Reputation: 956
Option 🐈: Start from Bash
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.
Option 🐕: Use your Existing Base Image
If you want to use your existing base image, while avoiding the need to install bash on every container boot, then you can add this to your Dockerfile.
# Use openjdk:8-jdk-alpine as the base image
FROM openjdk:8-jdk-alpine
# Install bash package
RUN apk add --no-cache bash
Upvotes: 23
Reputation: 31
USER root
RUN apk add --no-cache bash
/bin/sh
is good, but not enough to use. Sometimes /bin/bash
is necessary. So I used above code to install bash in alpine.
Upvotes: 1
Reputation: 3599
It doesn't work because this docker image uses Busybox. Busybox is a popular minimal Docker base image that uses ash, a much more limited shell than bash.
If you use sbt-native-packager you just need to add support
enablePlugins(AshScriptPlugin)
Upvotes: 0
Reputation: 785856
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)
If you just want to connect to the container and don't need bash, you can use:
docker run --rm -i -t alpine /bin/sh --login
Upvotes: 728
Reputation: 1042
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.
Upvotes: 2
Reputation: 5225
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
Upvotes: 14