
Mounting your host’s Docker socket into your job’s environment is an alternative option when you’re using the Docker executor. docker build -cache-from $CI_REGISTRY_IMAGE:latest -t $CI_REGISTRY_IMAGE:latest. docker pull $CI_REGISTRY_IMAGE:latest || true registration-token $GITLAB_REGISTRATION_TOKEN Add the -docker-privileged flag when you register your runner: sudo gitlab-runner register -n You need to register your GitLab Runner Docker executor with privileged mode enabled to use DinD. The Docker process that performs the build will be a child of the container that GitLab Runner creates on the host to run the CI job. Using Docker-in-Docker (DinD) to build your images gives you a fully isolated environment for each job. You then use the official Docker container image as your job’s image, making the docker command available in your CI script.

The Docker executor gives you two possible strategies for building your image: either use Docker-in-Docker, or bind the host’s Docker socket into the Runner’s build environment. The job will execute in an isolated container so the docker binary on the Runner host will be inaccessible. GitLab Runner’s Docker executor is commonly used to provide a completely clean environment for each job. GitLab will make these variables available in the shell environment used to run your job. Click the blue “Add variable” button to create a new variable and assign a value. docker login -u $DOCKER_REGISTRY_USER -p $DOCKER_REGISTRY_PASSWORDĭefine the values of the two credential variables by heading to Settings > CI/CD > Variables in the GitLab web UI. If you’re using a private registry, run docker login first to supply proper authentication details: script: Otherwise it would only be available to the local Docker installation that ran the build. This file defines the GitLab CI pipeline that will run when you push changes to your project.Īfter the build completes, you can docker push the image to your registry. gitlab-ci.yml file at the root of the repository. Head to the Git repository for the project you want to build images for. The executor works by running regular shell commands using the docker binary on the Runner’s host. If you’re using the Shell executor, make sure you’ve got Docker installed on the machine that hosts your runner. We’ll cover the Shell and Docker executors below. The steps you need to take vary slightly depending on the GitLab Runner executor type you’ll use for your pipeline.
DOCKER RUN IMAGE FROM LOCAL REGISTRY HOW TO
In this guide, we’ll show you how to set up Docker builds that use both the above features.

GitLab CI is a great choice for this as it supports an integrated pull proxy service, meaning faster pipelines, and a built-in registry to store your built images. One common use case for CI pipelines is building the Docker images you’ll use to deploy your application.
