0

I'm currently learning about gitlab-ci, and deploying. My gitlab instance runs in a docker container, and I would like to use the host's docker in order to build and deploy an image.

Is there such a way to do this?

1 Answer 1

1

Yes. If docker is not installed in the image (the current gitlab/gitlab-ce doesn't have it) you need to extend the image with an installation. E.g.

FROM gitlab/gitlab-ce:8.14.4-ce.0 ENV DOCKER_API_VERSION 1.23 RUN apt-get update && apt-get install -y docker.io 

The ENV DOCKER_API_VERSION 1.23 is there to ensure API compatibility between the installations. At the time of writing, you'll receive version 1.12.1 from the apt-get install. If you have the same version on the host, then you can leave out the environment variable. If you have 1.11 on the host, then you'll need it (if you have some other version, you'll get an error message with the version number to use).

Build the image like this

docker build -t myrepo/myorg/mygitlab:8.14.4-ce.0 . 

And then run it like this

docker run -d --name gitlab -v /var/run/docker.sock:/var/run/docker.sock myrepo/myorg/mygitlab:8.14.4-ce.0 

You'll now have docker available from the container:

docker exec -it gitlab bash $~ docker ps 
Sign up to request clarification or add additional context in comments.

3 Comments

I tried it, but it didn't work. Should I install docker in the container too ?
Sorry, I didn't try out the gitlab image, just assumed it had docker installed. Answer updated.
Yes, I updated my Dockerfile to add the docker installation and it works. Thanks !

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.