---
title: "Call Docker in Container"
date: 2021-08-05T16:57:41.000Z
author: Z.SHINCHVEN
tags: [Docker, container, GitLab Runner]
canonical: https://atlassc.net/2021/08/06/call-docker-in-container
---
## Theory

There is no way to actually run a `docker daemon` in a container, but we can pass [docker cli](https://docs.docker.com/engine/reference/run/) and [docker daemon](https://docs.docker.com/engine/reference/commandline/dockerd/) through volume mirroring.

## Example

Let's run a container along with those we need mirrored.

```bash
docker run -it \
-v /usr/bin/docker:/usr/bin/docker \            ## mirror docker cli
-v /var/run/docker.sock:/var/run/docker.sock \  ## mirror docker.sock
ubuntu /bin/bash
```

Inside this container we can actually call the `docker cli`.

```bash
root@72f21d4335b99:/# docker info
Client:
 Context:    default
 Debug Mode: false
## other info ...
```

## Use Case

The reason for me to do this is that I want to call docker cli in a gitlab-runner/docker executor during pipeline. The executor itself is a docker container.

Thus, I configured the runner this way:

```toml
[[runners]]
  [runners.docker]
    image = "ubuntu"
    volumes = [
        "/usr/bin/docker:/usr/bin/docker",
        "/var/run/docker.sock:/var/run/docker.sock",
        "/usr/local/bin/docker-compose:/usr/local/bin/docker-compose", 
        "/cache"
    ]
```
