Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: How to use bash with an Alpine based docker image?

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 
like image 936
iamdeit Avatar asked Dec 03 '16 05:12

iamdeit


People also ask

Does alpine have a shell?

3. Starting a Shell in an Alpine Container. Alpine is the most lightweight Linux distribution. Due to its small size, many people are using Alpine as their base image.

What shell does alpine use?

Note: By default Alpine Linux uses the ash shell, but many users may prefer bash, zsh, fish or another shell.


1 Answers

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)

like image 105
anubhava Avatar answered Sep 28 '22 03:09

anubhava