0

How can I save the result of the RUN instruction to a file?

Dockerfile example:

# code removed for simplicity

# <--- not working, probably because RUN creates a new layer?
RUN tree -a > public/tree.txt 

ENTRYPOINT ["dotnet", "publish/MyApp.AspNetCore.dll"]
Catalin
  • 11,503
  • 19
  • 74
  • 147
  • 2
    Could you please describe the problem you are trying to solve? The specified command writes the result into a file IN the container. This file exists in the image afterwards and would be accessible for the dotnet application. Writing the file back to the host is not supported though. – Andreas Jägle Nov 23 '20 at 11:33
  • I am manipulating folder contents inside the docker container, and I am using the tree command for debugging purposes. Ideally for me it would be to be able to run the `tree` command multiple times and save the output to external path (using volumes) – Catalin Nov 23 '20 at 12:01
  • 2
    Dockerfiles never access volumes; they can't write back to the host system; they can't make calls to other containers. All of these things need to be done in your application code, inside the `ENTRYPOINT`/`CMD`. For pure debugging, getting a debugging shell on a partially built image might be easier (for example, [How do I Run Docker cmds Exactly Like in a Dockerfile](https://stackoverflow.com/questions/45393971/how-do-i-run-docker-cmds-exactly-like-in-a-dockerfile/45394090#45394090)). – David Maze Nov 23 '20 at 14:16

0 Answers0