Fix Bash Error in Docker

By  on  

I really enjoy working with Docker because it gives me more insight into creating and maintaining your own environments, mostly from scratch.  I instantly gained a greater appreciation for Ops engineers, package creators, and other engineers who work on low level software.  I think what I'm trying to say is that I've made a whole bunch of mistakes and completed an insane amount of Google searches for help.

One of the more basic errors I've recently encountered was trying to run a bash script within the container, only to get the following error:  env: can't execute 'bash': No such file or directory.  I was under the impression that bash was always a given in Linux machines, but apparently not in alpine images.  The fix was adding the following to my Dockerfile file:

RUN apk update && apk add bash

Or if you're in the machine, just run:

apk update && apk add bash

That command installs bash and your bash scripts should then work!

Recent Features

  • By
    39 Shirts – Leaving Mozilla

    In 2001 I had just graduated from a small town high school and headed off to a small town college. I found myself in the quaint computer lab where the substandard computers featured two browsers: Internet Explorer and Mozilla. It was this lab where I fell...

  • By
    CSS Animations Between Media Queries

    CSS animations are right up there with sliced bread. CSS animations are efficient because they can be hardware accelerated, they require no JavaScript overhead, and they are composed of very little CSS code. Quite often we add CSS transforms to elements via CSS during...

Incredible Demos

  • By
    CSS Selection Styling

    The goal of CSS is to allow styling of content and structure within a web page.  We all know that, right?  As CSS revisions arrive, we're provided more opportunity to control.  One of the little known styling option available within the browser is text selection styling.

  • By
    “Top” Watermark Using MooTools

    Whenever you have a long page worth of content, you generally want to add a "top" anchor link at the bottom of the page so that your user doesn't have to scroll forever to get to the top. The only problem with this method is...

Discussion

  1. Hamish

    Alternatively, you can use ash instead of bash.

    Not sure what the differences are, but I would expect parity on most standard features.

  2. If the script is simple you can use the default /bin/sh shell.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!