Docker Community Forums

Share and learn in the Docker community.

Run Script in Dockerfile


(11776534) #1

I am trying to run a script through a Dockerfile but no output is shown.
To make it as simple as possible, this is my script file:

test.sh


#!/bin/sh
echo “WELCOME!”


this is my Dockerfile:


FROM ubuntu:latest
RUN mkdir -p /home/helloWorld
COPY . /home/helloWorld
RUN [“chmod”,"+x","/home/helloWorld/test.sh"]


Then i use the command:

sudo docker build -t testapp .
sudo docker run testapp

Nothing happens. Why?
Is there anything I am missing?


(Mikma) #2

Nothing is shown since the program started in your container is the bash shell and I think it exits since you don’t run it interactively and don’t allocate a pseudo tty (-it).

Add CMD /home/helloWorld/test.sh to the Dockerfile to run the program or add the script name to the docker run command line.


(11776534) #3

It works! Thankyou so much.