Get started with GitHub GHCR, an Alternative of DockerHub.
What is GHCR?
GHCR stands for Github Container registry, The GitHub Container registry allows you to host and manage your Docker container images in your personal or organization account on GitHub. One of the benefits is that permissions can be defined for the Docker image independent from any repository, It's similar in function to Docker Hub but is tightly integrated with GitHub.
To developer → setting → generate new token → usetoken → startbuilding images.
To work with GHCR we have to create PAT (Personal Access Token).
To use GHCR you need to generate a PAT (Personal Access Token) is a type of token used to authenticate and authorize access to resources on GitHub. PATs are commonly used to grant third-party applications or services limited access to your account without exposing your actual account credentials.
Setting up GitHub Container Registry (GHCR)
Setting up GitHub Container Registry (GHCR) for storing Docker images involves a few steps. Here's a guide on how to set up an account on GHCR and push images for different services, similar to how you would on Docker Hub:
Step 1: GitHub Account:
If you don't already have a GitHub account, you'll need to create one. Visit https://github.com/ to sign up.
Step 2: Create a Repository:
Create a repository on GitHub to store your Docker images. You can either create a new repository or use an existing one.
Step 3: Authenticate with GitHub Personal Access Token (PAT):
To push images to GHCR, you need to authenticate using a GitHub Personal Access Token (PAT) with the write:packages scope. Here's how to create and use a PAT:
Go to your GitHub account settings and navigate to "Developer settings" > "Personal access tokens."
Click on "Generate new token."
Select Tokens Classic .
Give the token a name, select the write:packages scope, and generate the token.
Copy the generated token.
Step 4: Authenticate with Docker:
Before you can push images to GHCR, you need to log in to the GitHub Container Registry using your GitHub username and the PAT you generated.
In your terminal, run:
docker login ghcr.io -u USERNAME -p YOUR_PAT
Replace USERNAME with your GitHub username and YOUR_PAT with the copied Personal Access Token.
Step 5: Tag and Push Images:
Now that you're logged in, you can tag your Docker images to push them to GHCR:
Build Your Image:
Navigate to the directory containing the Dockerfile for your service. Build your Docker image with a tag using the following command:
docker build -t ghcr.io/USERNAME/REPO_NAME/IMAGE_NAME:TAG .
Push Your Image:
Push the tagged image to GHCR:
docker push ghcr.io/USERNAME/REPO_NAME/IMAGE_NAME:TAG
Step 6: View Your Images on GHCR:
Visit the "Packages" section of your GitHub repository to view the images you've pushed to GHCR.
Also, you can use this method to reference
See in the image To The push refers to repository [ghcr.io/userId/repoName/imageName ]
copy this URL and past in the browser you will get interface like that below.
Remember that the repository structure for GHCR follows this format: ghcr.io/USERNAME/REPO_NAME/IMAGE_NAME:TAG.
By following these steps, you can set up your GitHub account to push Docker images to GHCR for different services, just like you would on Docker Hub, and you can use these images for deployment of the application .
Thank you .