Azure / docker-login

GitHub action to log in to Azure Container Registry (ACR) or any private container registry
MIT License
110 stars 48 forks source link

Failure to restart docker compose instance / check image and resgistry credintial, inaccessible image #65

Closed chip-davis closed 9 months ago

chip-davis commented 9 months ago

Hello!

I have a project that I spun up with a docker compose file. The images are both in my azure container registry. The container instances were created fine. I used this GitHub action to build and push my images to the registry. This part works fine, and I can verify that the images were correctly updated. When I go to restart the container instances, I get the following error:

Failed to restart the container group 'my-container-group'. Error: Multiple error occurred: 'BadRequest':'InaccessibleImage':The image '{myregistry}/my-repo:my-image-tag' in container group 'my-container-group' is not accessible. Please check the image and registry credential.

This error repeats itself for the other image.

Here is my workflow file:

name: docker_build_push_acr

on:
  push:
    branches:
      - main

jobs:
  docker_build_push_acr:
    name: "Docker Build and Push to ACR"
    runs-on: ubuntu-latest
    environment: production

    # Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
    defaults:
      run:
        shell: bash

    steps:
      # Checkout the repository to the GitHub Actions runner
      - name: Checkout
        uses: actions/checkout@main

      - name: "Docker Login"
        uses: azure/docker-login@v1
        with:
          login-server: ${{ secrets.REGISTRY_LOGIN_SERVER }}
          username: ${{ secrets.REGISTRY_USERNAME }}
          password: ${{ secrets.REGISTRY_PASSWORD }}
      - run: |
          docker build -t ${{ secrets.REGISTRY_LOGIN_SERVER }}/my-repo:frontend-image ./front-end-directory
          docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/my-repo:frontend-image
          docker build -t ${{ secrets.REGISTRY_LOGIN_SERVER }}/my-repo:backend-image ./backend-directory
          docker push ${{ secrets.REGISTRY_LOGIN_SERVER }}/my-repo:backend-image

Again, images are pushed to the registry successfully. It is just when I go to restart the container instance that I get this error. I have to delete the container instances and re-initiate them with my docker compose file to get it to start up again.

If it helps, here are my Dockerfiles and docker-compose:

Front end Dockerfile:

FROM node:20-alpine3.18 as build
WORKDIR /usr/app
COPY . /usr/app
RUN npm ci
RUN npm run build

FROM nginx:1.23.1-alpine
EXPOSE 80
COPY ./docker/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
COPY --from=build /usr/app/dist /usr/share/nginx/html

Backend Dockerfile:

FROM oven/bun

WORKDIR /app

COPY package.json .
COPY bun.lockb .

RUN bun install --production

COPY src src
COPY tsconfig.json .
# COPY public public

ENV NODE_ENV production
CMD ["bun", "src/index.ts"]

EXPOSE 3009

Docker-compose:

version: "3.8"

services:
  frontend:
    image: my-container-registry/my-repo:frontend-image
    ports:
      - "80:80"
    depends_on:
      - backend
    container_name: frontend-container

  backend:
    image: my-container-registry/my-repo:backend-image
    ports:
      - "3009:3009"
    container_name: backend-container

Any help would be greatly appreciated!

chip-davis commented 9 months ago

I switched to using Container Apps in Azure and set up CI/CD through that, so this is no longer an issue I am facing.