GitHub Actions not passing environment variables to Docker container during build step
I've been banging my head against this for hours. I'm trying to build a Docker container using GitHub Actions, but I'm running into an scenario where the environment variables I set in the workflow are not being passed into the Docker build step. My workflow is defined in `.github/workflows/docker-build.yml` and looks like this: ```yaml name: Docker Build on: push: branches: - main jobs: build: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - name: Build and push Docker image uses: docker/build-push-action@v2 with: context: . file: ./Dockerfile push: true tags: user/repo:latest env: MY_ENV_VAR: ${{ secrets.MY_SECRET }} ``` I expect `MY_ENV_VAR` to be available during the build process in the Dockerfile, but when I run `docker build`, it seems like the variable is not recognized. I’ve also added a simple echo statement in the Dockerfile: ```dockerfile FROM node:14 ARG MY_ENV_VAR RUN echo "MY_ENV_VAR is: $MY_ENV_VAR" ``` But when the build runs, it outputs `MY_ENV_VAR is:` without any value. I’ve tried using both `ARG` and `ENV` in the Dockerfile but to no avail. I’ve also checked that `MY_SECRET` is correctly set in the repository secrets. What am I missing here? Is there a specific way to pass environment variables to a Docker build within GitHub Actions? I'm working on a application that needs to handle this. What's the best practice here?