CodexBloom - Programming Q&A Platform

GitHub Actions scenarios to publish Docker image due to missing context for multi-stage build

👀 Views: 36 💬 Answers: 1 📅 Created: 2025-06-30
docker github-actions ci-cd YAML

I'm working through a tutorial and I'm working through a tutorial and I'm maintaining legacy code that I recently switched to I'm working on a personal project and I'm relatively new to this, so bear with me....... I'm trying to publish a Docker image to GitHub Container Registry using GitHub Actions, but I'm running into an scenario where the build context seems to be incorrect for my multi-stage Dockerfile. My setup is as follows: Here's a snippet of my `.github/workflows/docker-publish.yml`: ```yaml name: Publish Docker Image on: push: branches: - main jobs: build: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Log in to GitHub Container Registry uses: docker/login-action@v1 with: registry: ghcr.io username: ${{ github.actor }} token: ${{ secrets.GITHUB_TOKEN }} - name: Build and push Docker image run: | docker build -t ghcr.io/myusername/myimage:${{ github.sha }} . docker push ghcr.io/myusername/myimage:${{ github.sha }} - name: Cleanup run: docker rmi ghcr.io/myusername/myimage:${{ github.sha }} ``` The Dockerfile is structured for multi-stage builds like so: ```dockerfile # Stage 1: Build FROM node:14 as builder WORKDIR /app COPY package*.json ./ RUN npm install COPY . . RUN npm run build # Stage 2: Serve FROM nginx:alpine COPY --from=builder /app/dist /usr/share/nginx/html EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] ``` The behavior I receive during the Actions run is: ``` behavior: failed to solve: failed to copy: http://example.com: denied access ``` I’ve double-checked that my Dockerfile is in the root of the repository and that my paths are correct. I also verified that the GitHub token has the right permissions to access the registry. My repository is private, and I’m using the `docker/login-action` to authenticate. Has anyone encountered a similar scenario with multi-stage builds in GitHub Actions? What could cause this "denied access" behavior, and how can I ensure that the context is correctly set for my Docker builds? Is there a better approach? This is part of a larger API I'm building. Thanks in advance! I'm working on a API that needs to handle this. How would you solve this? I'm on macOS using the latest version of Yaml. I'd really appreciate any guidance on this. Could someone point me to the right documentation? Any pointers in the right direction? I'm developing on Ubuntu 20.04 with Yaml.