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

  • consul-template using Address not ServiceAddress in template
  • Determining if a process runs inside windows/iis
  • Ahow to use multiple terminals in the docker container?
  • Command works on bash but not on cron
  • Execute configuration bash script during docker build
  • Docker Alpine linux package masked
  • Docker compose Invalid volume destination path: '.' mount path must be absolute
  • Kubeadm + flannel , service not accessable
  • Docker Remote API returns 500 error on create container
  • SQL scripts inside /docker-entrypoint-initdb.d directory are not executed
  • Docker Login for AWS ECR failing with “Cannot connect to the Docker deamon…”
  • `docker run ubuntu:14.04 /bin/echo` produces SELinux error on Fedora 20
  • 3 Solutions collect form web for “How to use bash with an Alpine based docker image?”

    Alpine docker image doesn’t have bash installed by default. You will need to add following commands to get bash:

    RUN apk update && apk add bash
    

    If youre using Alpine 3.3+ then you can just do

    RUN apk add --no-cache bash
    

    to keep docker image size small. (Thanks to comment from @sprkysnrky)

    RUN /bin/sh -c "apk add --no-cache bash"
    

    worked for me.

    Try using RUN /bin/sh instead of bash.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.