How do I write a file with Ruby within a Docker container?

I am trying to write a new file using Ruby dockerized. I can read the file after writing it but just inside the container. I tried to create a volume and save the file in it but I am doing something wrong because the data folder is always empty.

Here is my Dockerfile:

RUN mkdir /data
VOLUME data data
COPY hello.rb .
ENTRYPOINT ["ruby", "hello.rb"]

And here is hello.rb"./data/out.txt", "a+") do |line|
  puts "hola"
  line.puts "r" + "write your stuff here"
end"./data/out.txt").each do |line|
  puts "aloha"
  puts line

File.write("./data/log.txt", "data...", mode: "a")"./data/log.txt").each do |line|
  puts "aloha"
  puts line

After running:

$ docker build -t file-writer .
$ docker run -it file-writer

The output in the console is:



write your stuff here



But the “local” data folder stills empty.

Source: StackOverflow