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
File.open("./data/out.txt", "a+") do |line| puts "hola" line.puts "r" + "write your stuff here" end File.open("./data/out.txt").each do |line| puts "aloha" puts line end File.write("./data/log.txt", "data...", mode: "a") File.open("./data/log.txt").each do |line| puts "aloha" puts line end
$ docker build -t file-writer . $ docker run -it file-writer
The output in the console is:
hola aloha write your stuff here aloha data...
But the “local” data folder stills empty.