skip to Main Content

I’ve got a gitlab container running on docker. I want to define a gitlab runner to run the docker I use on my machine. I’m stuck.
Should I make a symlink from the container to the docker executable on the machine when building the image? If yes then how should I do that?
If above is not possible how should I handle the situation I have?

2

Answers


  1. Chosen as BEST ANSWER

    The solution is docker in docker (dind) can be seen here.


  2. If I understand you correct, you want an access to docker engine of your host environment from your gitlab container. So, for example, when you execute docker ps in your gitlab container you actually accessing docker engine of the host machine.

    To achieve that you have to do 2 things:

    • Install docker cli inside your gitlab container, I’m not familiar with this image, probably docker cli is already here, but to be sure here how to do this. In short:

      COPY --from=docker:latest /usr/local/bin/docker /usr/local/bin/
      

      This will copy cli binaries from docker image into your container.

    • Docker cli communicates with docker engine via unix socket: /var/run/docker.sock so you’ll have to mount it inside your gitlab container.

      • If your docker engine host Os is windows, you’ll have to mount it
        like this:

        --volume //var/run/docker.sock:/var/run/docker.sock
        
      • If your docker engine host OS is linux, it is pretty straightforward:

        --volume /var/run/docker.sock:/var/run/docker.sock
        
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search