How to pass github action's variable into Dockerfile - Image Builds - Docker Community Forums
How to pass github action's variable into Dockerfile Image Builds aws , github-action suddhasilsarkar2023 (Suddhasilsarkar2023) February 14, 2025, 2:14am 1 Hi All, need help- I want pass environment variable (value) from Git Action’s deployment.yaml to dockerfile", is that something I can do ? Basically I have a python script which has static value given for AWS secret, I want to make it dynamic based on the environment(stage, prod, etc…).
I have an Environment variable defined in deploy.yaml in github actions workflow, I want to pass that environment value into dockerfile . Can i do that ? Any guidance would be a great help meyay (Metin Y.) February 15, 2025, 9:53am 2 So basically the question is how to configure the GitHub Action to pass the variables into the build. The docker perspective is quite simple: declare ARG instructions in your Dockerfile, and pass their values in with build args.
See: https://docs.docker.com/reference/dockerfile/#arg Now you need to figure out how to configure the GitHub Action to pass the build args into the build. kristiyan22 (Kristiyan Velkov) February 15, 2025, 12:32pm 3 Hello, In GitHub Actions , pass build arguments ( ARG ) to the Docker build using build-args in docker/build-push-action : - name: Build and push Docker image uses: docker/build-push-action@v5 with: context: . push: true tags: your-dockerhub-username/your-image-name:latest build-args: | API_URL=${{ secrets.API_URL }} NEXT_PUBLIC_API_KEY=${{ secrets.NEXT_PUBLIC_API_KEY }} Add secrets in GitHub Settings → Actions → Secrets and variables .
Related topics Topic Replies Views Activity Can't pass gitlab user defined variable through Docker image through --build-arg General docker 3 206 March 5, 2026 Deploying a Dockerised go server to AWS Elasticbeanstalk/Ec2 instance via GitHub Actions environment variable issue Docker Hub aws , docker 0 471 May 1, 2024 Pass gitlab variables to a speccific path in Dockerfile General 1 9869 July 17, 2019 How do i use secrets in Docker build?
Docker Hub dockerhub , docker , build 0 1294 May 14, 2024 Passing variables to an automated build - DOCKER_TAG Docker Hub build 1 2500 March 26, 2019