DEV Community

Cover image for Docker + bash : This tip can save your time ! ⏰
Demily Clément
Demily Clément

Posted on • Originally published at

Docker + bash : This tip can save your time ! ⏰

Today, I'm going to give you a tip on an inattention error with docker that cost me few minutes of my time!

This advice is intended for beginners with docker.


There are quite a few kinds of docker images, we'll take the ruby image as an example.
As you can see, there are different types of images available: buster, slim, alpine, stretch, ...

Some of these images are based on particular distributions, much lighter (alpine), others come with larger OS & dependencies.

To package and deploy my application, I chose to use an alpine image. This image has minimum dependencies & pre-installed packages, and therefore ideal for deployment.

The problem

When you create your dockerfile, you have the option of using the ENTRYPOINT &CMD directives at the end of your file. These directives allow you to execute commands and to call scripts that you could have previously created.

If you are used to using bash to execute your script, you must have written the following line in your script file header: # /bin/bash.
This tells the terminal (inside docker) to use bash to run this script.

# /bin/bash

echo "test"
Enter fullscreen mode Exit fullscreen mode

When you launch docker with the dockerfile, it might doing nothing: no script starts, leaving you without an error message. 😨

The solution

As said before, the alpine images are very light and do not embed superfluous dependencies. You must either install bash using the RUN directive in your dockerfile:

  RUN apk add --no-cache bash
Enter fullscreen mode Exit fullscreen mode

Either change your script to make it compatible with the sh shell:

# / bin / sh

echo "test"
Enter fullscreen mode Exit fullscreen mode

Hope I have been clear on how to fix this.
I wish you all a happy coding ! 🐳 ✨

Top comments (0)