bash write file script not working in docker container

  bash, docker

I am following docker tutorial and attempting to run bash script from docker container.
The scripts runs in terminal as expected (prints on screen and craetes log folder with log.txt file). I then use docker build . to create image. docker run [image] starts the script and prints on screen in terminal but doesn’t create log/log.txt file. Why is that and what am I missing here? Thanks!

app.sh

mkdir log
for ((i=1; ; i++))
do
   text="$(date "+%Y-%m-%d %H:%M:%S") - infinite loops $i"
   echo $text
   echo $text  >> log/log.txt
   sleep 1
done

dockerfile

FROM ubuntu:latest
COPY . ./
CMD /bin/bash app.sh 

PS I just copied the shell script from tutorial material, I am not very familiar with shell scripts.

Source: Docker Questions

LEAVE A COMMENT