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

后端 未结 4 1268
生来不讨喜
生来不讨喜 2020-11-28 17:59

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

R         


        
相关标签:
4条回答
  • 2020-11-28 18:34

    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

    0 讨论(0)
  • 2020-11-28 18:41

    Try using RUN /bin/sh instead of bash.

    0 讨论(0)
  • 2020-11-28 18:55

    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)

    0 讨论(0)
  • 2020-11-28 18:57
    RUN /bin/sh -c "apk add --no-cache bash"
    

    worked for me.

    0 讨论(0)
提交回复
热议问题