How to migrate Gitlab Docker Registry to another docker registry? - docker

I am trying to migrate from gitlab-ce to gitlab.com. This includes Docker registry as well. What I need to migrate Gitlab Docker Registry to hosted Docker registry (Nexus3). This might be manually done I imagine, but is there any more efficient way to do it?

Normally I used the following workflow for each tag:
docker pull SRC_REGISTRY_HOST/<REPOSITORY:TAG
docker tag SRC_REGISTRY_HOST/<REPOSITORY:TAG DEST_REGISTRY_HOST/<REPOSITORY:TAG
docker push DEST_REGISTRY_HOST/<REPOSITORY:TAG
But I couldn't find it clean so I wrote a small tool to automate all the steps and just use the following:
docker run --rm -it smqasims/imagesync --src SRC_REGISTRY_HOST/<REPOSITORY> --dest DEST_REGISTRY_HOST/<REPOSITORY
This will sync both the repositories and is faster/manageable compared to the other workflow.

Related

How to start docker daemon in my custom Docker image?

I am trying to create my custom docker image which I will use in my GitLab build pipeline. (Following this guide as I would like to configure my GitLab runners over AWS Fargate https://docs.gitlab.com/runner/configuration/runner_autoscale_aws_fargate/).
One of the prerequisites is to create your own custom docker image that has everything that's needed for the build pipeline to execute.
I would need to add a docker to my docker image.
I am able to install docker, however, I do not understand how to start the docker service as the error I am getting is
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
each time docker command is used.
I tried to add in my startup.sh script used as a docker entrypoint to start docker using rc-service(alpine-based image) or systemctl (amazon linux 2) but without any luck.
Any help is appreciated. Thanks.
For running docker in docker you need to configure docker image with docker-dind service to build docker. But it is limited and requires sudo priviledges, I do recommend to use kaniko, it is very easy to configure, does not require anything more than kaniko executor image.
https://docs.gitlab.com/ee/ci/docker/using_kaniko.html
If really need to use DinD (docker in docker), just go to:
https://docs.gitlab.com/ee/ci/docker/using_docker_build.html
Kaniko is simplest and safe way to run docker build

Update Jenkins running on docker container

I have a Jenkins running on Docker container and local docker registry.
docker-compose up
it does't go out side network rather pulls the image from local registry.
Is there a way i can update my local docker registry with latest Jenkins image?
And when i run docker-compose up i have latest Jenkins? Thank you!
So by default docker nature is always look for image available on host-machine and if not specific tag is provided it will search for default tag which is latest .
So in your case when you already have latest jenkins image available on host docker-compose will always use that image pretending this is the latest one. For using latest image available from registry you need to clean/delete jenkins image from your host who is having latest tag.
Delete and use latest jenkins image:
docker rmi -f jenkins:latest
docker-compose stop
docker-compose rm -f
docker-compose pull
docker-compose up -d
this is your private registry so you need to login to it:
docker login my-server.test:5000

How to pull new docker images and restart docker containers after building docker images on gitlab?

There is an asp.net core api project, with sources in gitlab.
Created gitlab ci/cd pipeline to build docker image and put the image into gitlab docker registry
(thanks to https://medium.com/faun/building-a-docker-image-with-gitlab-ci-and-net-core-8f59681a86c4).
How to update docker containers on my production system after putting the image to gitlab docker registry?
*by update I mean:
docker-compose down && docker pull && docker-compose up
Best way to do this is to use Image puller, lot of open sources are available, or you can write your own on the Shell. There is one here. We use swarm, and we use this hook concept to be triggered from our CI-CD pipeline. Once our build stage is done, we http the hook url, and the docker pulls the updated image. One disadvantage with this is you need a daemon to watch your hook task, that it doesnt crash or go down. So my suggestion is to run this hook task as a docker container with restart-policy as RestartAlways

How can I docker commit azure container instance to azure container registry

We have ansible configured to deploy our various applications on IIS environment. I am trying to create a docker image of deployed applications so that I can just start up containers as we need for testing and otherwise.
I am planning to build on the Windows IIS image, start the container on azure, run our ansible to install everything on the server, then save the image on container.
I cannot find any documentation on how I can docker commit the container image into our private azure container registry.
Is it possible?
If you have an existing Docker registry in azure you should be able to use the az acr login --name myregistry command to authenticate to it https://learn.microsoft.com/en-us/azure/container-registry/container-registry-get-started-docker-cli. Make sure you have a registry created for the container image you want to push up.
Next, you can run the container in azure and do all the installation you want. SSH or RDP into the instance in Azure that is running this container. Now run docker ps and find the container id for the correct container. Next, use docker commit <container id> myregistry.azurecr.io/samples/nginx.
Then, just docker push myregistry.azurecr.io/samples/nginx
Also not sure what your use case is, but starting a container in order to modify and commit it in that way seems like an atypical use case for Docker since the build isn't reproducible via the Dockerfile. Looks like there are ways to replace Dockerfiles using Ansible playbooks with something like ansible-containers https://docs.ansible.com/ansible-container/ so you might want to take a look at that(I've never used this tool).

Pull image from another Docker Machine

Is it possible to pull an image from another docker machine without having to install the docker repository?
I got 2 docker machines for development and i would like to deploy an image on the second docker machine that i have build with the first one.
Is this possible?
If you have created your docker servers using docker-machine then you could do an export/import using remote access to the docker agents on each server.
docker $(docker-machine config server1) export exampleimage:1.0 | docker $(docker-machine config server2) import - exampleimage:1.0
But....it would be a lot simpler to just rebuild the image on the second server, using the same Dockerfile.

Resources