How can I access the current repo context and files from a Docker container action ? #26855
-
Hello ! I am trying to build a new Docker container action that must interact with the current repo files. Thanks in advance ! |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 2 replies
-
@obrassard When use a Docker container action in the workflow, it will automatically run with a volume mapping from GITHUB_WORKSPACE (on the runner machine) to /github/workspace (inside container). So you could easily get access to your repo files under / github/workspace inside the container. For example, I want to access to the README.md in my repo, In my Docker container action > entrypoint.sh, I could use
to show the content of README.md. |
Beta Was this translation helpful? Give feedback.
-
Thanks for your great answer !!! I think this information should be better explained in the GitHub actions documentation. Have a nice day 👍 |
Beta Was this translation helpful? Give feedback.
-
That doesn’t seem to be the case for me. I’m running the In my logs you can see that even though I’m trying to copy my What am I doing wrong? |
Beta Was this translation helpful? Give feedback.
-
That’s part of the container build, not run. The workspace directory is only mounted at run time. Also Docker builds in general can’t access random files, only files in their build context (see the Usage section of the Dockerfile reference). Simply put, you can’t use files from the repository running your action in the Dockerfile, only later in the code that’s running in the resulting container. |
Beta Was this translation helpful? Give feedback.
-
Indeed, you won’t have access to |
Beta Was this translation helpful? Give feedback.
-
Thanks for your quick reply! I’ll be honest I don’t fully understand what the difference between the build and run phase is… Could you give me an example of how or at what point I would be able to use my repo files in a docker action? Or if I can never access to my repo files in a docker action then I don’t really understand why anyone would ever choose docker for their action type. Surely the point in having an action is for it to be able to do something with your source code? If there is documentation answering this question then please point me towards it, but I’m struggling to understand how actions work in anything more complicated than the basic examples. |
Beta Was this translation helpful? Give feedback.
-
Arrow7000:
The distinction between building a container image and running it is a general Docker (and container) concept, so I’d start with the Docker introduction: Orientation and setupOrientation and setup Build and run your image Share images on Docker Hub Welcome! We are excited that you want to learn Docker. This page contains step-by-step instructions on how... Highly simplified: The Dockerfile describes what should be included in the container image, usually software and maybe supporting files. When the container gets run, the command you set as |
Beta Was this translation helpful? Give feedback.
-
Ok thank you for that. I’ll have a read through the docs. But is there a reason why docker shouldn’t have access to the repo files during the build phase? I can’t see why this should be the case. Why not make them available during the build phase too? |
Beta Was this translation helpful? Give feedback.
-
Arrow7000:
Because the build is about getting your action code ready to run. You can roughly compare it to compiling a piece of software, and depending on the action code there may be actual compiling involved. Needing the data a user might want to process while compiling a tool doesn’t make sense. It’d also cause a bunch of technical issues, in particular how to make which files available to the Docker build. That should become clear when you read about the build context in the Docker documentation. |
Beta Was this translation helpful? Give feedback.
-
Ok I think that makes sense. I’ll have a look at the docs like you recommended. Thanks again for your help! |
Beta Was this translation helpful? Give feedback.
@obrassard When use a Docker container action in the workflow, it will automatically run with a volume mapping from GITHUB_WORKSPACE (on the runner machine) to /github/workspace (inside container).
So you could easily get access to your repo files under / github/workspace inside the container.
For example, I want to access to the README.md in my repo,
In my Docker container action > entrypoint.sh, I could use
to show the content of README.md.