skip to Main Content

I’m using docker/build-push-action and am trying to find a way to shorten the image name when it gets pushed to github registry.

Currently the docker image name is showing as

ghcr.io/organization-name/project-image:latest

Can this be shortened to just be the image name and tag without the ghcr.io/organization-name/

2

Answers


  1. The name of a docker image tag needs to include a registry hostname when you use docker push (unless you are pushing to the default Docker’s public registry located at registry-1.docker.io)

    It is how docker push knows where to push to.

    That is why a typical "build and push" step looks like:

    name: Build and Push Docker container
    
    on:
      push:
        branches:
          - main
    
    jobs:
      build-and-push:
    
        runs-on: ubuntu-latest
    
        steps:
        - uses: actions/checkout@v1
    
        - name: Build the Docker image
          run: docker build -t ghcr.io/<<ACCOUNT NAME>>/<<IMAGE NAME>>:<<VERSION>> .
    
        - name: Setup GitHub Container Registry
          run: echo "$" | docker login https://ghcr.io -u $ --password-stdin
    
        - name: push to GitHub Container Registry
          run:  docker push ghcr.io/<<ACCOUNT NAME>>/<<IMAGE NAME>>:<<VERSION>>
    

    In your case, (using the docker/build-push-action), even if you were to use a local registry, you would still need to tag accordingly.

    -
            name: Build and push to local registry
            uses: docker/build-push-action@v3
            with:
              context: .
              push: true
              tags: localhost:5000/name/app:latest
                    ^^^^^^^^^^^^^^
                    # still a long tag name
    
    Login or Signup to reply.
  2. Just specify in the tags argument, like:

          - name: Build and push
            uses: docker/build-push-action@v3
            with:
              push: true
              tags: project-image:latest
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search