From 40ed14ec71627fd94fa5aa5ce9e4d1c86006f05d Mon Sep 17 00:00:00 2001 From: Rich Seviora Date: Fri, 21 Mar 2025 11:57:29 -0700 Subject: [PATCH] Update section-running-jobs-in-a-container.md Adds a note and example explaining that the working directory may need to be set when using a custom container. --- .../section-running-jobs-in-a-container.md | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/data/reusables/actions/jobs/section-running-jobs-in-a-container.md b/data/reusables/actions/jobs/section-running-jobs-in-a-container.md index c88b784576d4..c7f1447f394f 100644 --- a/data/reusables/actions/jobs/section-running-jobs-in-a-container.md +++ b/data/reusables/actions/jobs/section-running-jobs-in-a-container.md @@ -5,6 +5,9 @@ If you do not set a `container`, all steps will run directly on the host specifi > [!NOTE] > The default shell for `run` steps inside a container is `sh` instead of `bash`. This can be overridden with [`jobs..defaults.run`](/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_iddefaultsrun) or [`jobs..steps[*].shell`](/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell). +> [!NOTE] +> If you supply your own container image, the `WORKDIR` statement may not be detected and you will need to (re)specify it yourself with the [`jobs..defaults.run.working-directory](/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_iddefaultsrunworking-directory) option. + ### Example: Running a job within a container ```yaml copy @@ -37,3 +40,31 @@ jobs: runs-on: ubuntu-latest container: node:18 ``` +### Example: Running a job within a custom container with a working directory set +```yaml copy +name: CI +on: + push: + branches: [ main ] +jobs: + container-test-job: + runs-on: ubuntu-latest + defaults: + run: + working-directory: `/home/app/webapp` + container: + image: myimage + credentials: + username: MYUSERNAME + password: MYPASSWORD + env: + NODE_ENV: development + ports: + - 80 + volumes: + - my_docker_volume:/volume_mount + options: --cpus 1 + steps: + - name: Check for dockerenv file + run: (ls .dockerenv && echo Found dockerenv) || (echo No dockerenv) +```