How to Dockerize Bash Script (Shell Script)

How to Dockerize Bash Script

In this tutorial, I will show you how to Dockerize Bash Script. Dockerizing an app is the easiest way to pack and ship it. I like to use Docker for all my apps. It is easy to use and deploy. So, let’s get started dockerizing the bash script.


  • Docker installed
  • Bash Script

You may also like: How to Dockerize go (golang) web app

Sample Bash Script

Here I am creating a sample bash script for this tutorial. I am creating a hello world script.

$ vim

echo Hello World!

Dockerize the Script

Now its time to dockerize the Script. Firstly, add Dockerfile in the root of your app.

$ vim Dockerfile

Then paste the following content into Dockerfile:

FROM ubuntu
ADD ./ /usr/src/
RUN chmod +x /usr/src/
CMD ["/usr/src/"]

Build your app

After creating Dockerfile its time to build your app. You can use docker build command to build the docker image. We will also tag our image with -t option.

$ docker build -t sample .
Sending build context to Docker daemon 3.072kB
Step 1/4 : FROM ubuntu
---> f975c5035748
Step 2/4 : ADD ./ /usr/src/
---> Using cache
---> 3c9637b399e3
Step 3/4 : RUN chmod +x /usr/src/
---> Running in a1a4839148d3
Removing intermediate container a1a4839148d3
---> c8d7eb17a3a2
Step 4/4 : CMD ["/usr/src/"]
---> Running in e5daa54f6cfa
Removing intermediate container e5daa54f6cfa
---> b968199ada0e
Successfully built b968199ada0e
Successfully tagged sample:latest

Test your Image

Now its time to test your docker image.

$ docker run -it sample
Hello World!

Now you can see it is working as expected.

Please let me know if you like this tutorial.

If you have any issues please feel free to comment below.


Leave a Reply

Your email address will not be published.


48-Hour Flash Sale! Courses from just $10.99