Skip to content
IT related

Building Docker Images

Updated 2 min read

How to create new Images in the GHCR when there is an version update.

Prerequsites

Make sure you have a github PAT and docker/docker compose installed on the server you are using to test the container on.

Build the Docker Image.

To change then rebuild the image you should edit the Dockerfile file with any changes that are needed.

When you have all the files ready to go use this command to build them.

docker build . -t <image-name> -f Dockerfile

Replace <image-name> and Dockerfile with the name you want, and the path to your Dockerfile.

You can check that the image was created locally with the following command. docker image ls -a | fzf, then search for the container you made. If you dont have many containers on your machine you can leave out fzf.

Testing

Change your docker-compose.yml file so that it uses the local container, by just specifying the name you gave it, to make sure its not using an image from the GHCR.
We can start the containers with docker compose up --force-recreate. Ctrl + C to stop them again.

You can now test them like you would normally, test thoroughly.

Working verion? Lets Deploy it.

If you are happy with the tests, and the new images are ready to be put on the GHCR so that they can be used in production follow these steps.

Github PAT
  1. Go to your GitHub account settings.
  2. Click on "Developer settings" → "Personal access tokens" → "Generate new token".
  3. Grant the token the necessary scopes - write:packages, read:packages.
  4. Save the generated token securely.
Logging into the github container registry.

On the server that will be running the containers we must loginto the GHCR (Github container registry), that is where we are storing the created github containers.

In the home directory of your user, you should make a 'docker' folder, mkdir docker, inside this folder you should make a file called PAT and paste the pat in the file with nothing else nano pat.

From this folder run the following command. Make sure to put your github username in the command.

cat pat | docker login ghcr.io -u  <Github_Username> --password-stdin

You should receive a message saying login succefull.

Tagging the Image

Before pushing the image to the GHCR we need to tag it in the correct format with the correct name.
Replace <local-image>, <tag>, and <repository-name> with your image name, tag, and desired repository name respectively.

docker tag <local-image>:<tag> ghcr.io/<GITHUB_USERNAME>/<repository-name>:<tag>

i.e.

docker tag ytdlfullmetal:latest ghcr.io/ytdlfullmetal/ytdlfullmetal:0.0.1-alpha
Pushing it to the GHCR

The last thing to do is actually push the image(s) to the GHCR so they can be deployed on other servers.

docker push ghcr.io/<GITHUB_USERNAME>/<REPO_NAME>:<TAG>

Done

You should be able to log into github and check the packages page for the new packages.

IT related RSS feed Published with Oblish

Keyboard shortcuts

/
Search
[
Previous page
]
Next page
?
Show this list
Esc
Close