# Docker build in gitlab ci

**URL:** <https://forums.docker.com/t/docker-build-in-gitlab-ci/53523>\
**Category:** General\
**Created:** [July 5, 2018, 11:09am UTC](https://forums.docker.com/t/docker-build-in-gitlab-ci/53523 "2018-07-05T11:09:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![user1989](https://avatars.discourse-cdn.com/v4/letter/u/85f322/32.png) [@user1989](https://forums.docker.com/u/user1989)\
**Post date:** [July 5, 2018, 11:09am UTC](https://forums.docker.com/t/docker-build-in-gitlab-ci/53523/1 "2018-07-05T11:09:05Z")

</div>

My gitlab-ci.yml file contains the build script and path to build tools to use such as curl.exe, jfrog etc. The build generates artifacts.The artifact contains libraries/binaries and .exe application in ZIP format. These artifacts are delivered to artifactory. How can I dockerize this build? Can I create images for the build tools? I am using gitlab ci/cd and windows server 2012. the build tools are installed manually on this windows server. The gitlab runner uses shell as executor. How can I generate artifacts using docker build?

---

<div class="post-metadata">

**Author:** ![agowa338](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@agowa338](https://forums.docker.com/u/agowa338)\
**Post date:** [July 5, 2018, 12:30pm UTC](https://forums.docker.com/t/docker-build-in-gitlab-ci/53523/2 "2018-07-05T12:30:17Z")

</div>

gitlab-runner currently don’t support docker executor on windows, so you can only do one of these:  
- Update your windows server 2012 to either windows server 2016, 1809 or 1903 and install docker.  
- Install another server/vm with windows server 2016/1809/1903/… (1809, 1903 are the half-annual version of windows server, these have the newest features, but are not supported by microsoft, 2016 is the lts version of windows server) And run `docker build --no-cache --pull .` inside there. Also you need to tag your runners to use multiple ones inside a single gitlab-ci.yml file.  
- Wait until gitlab-runner supports docker executor on windows for using the same steps for building a windows container as on linux (by pulling the docker in docker container and building inside there)  
- Sync your repository by using the gitlab-ee mirror feature to github and add it at dockerhub as an automated repository. Than enable webhooks and call the hook from gitlab after every push. So your image is build directly at dockerhub (also everyone can see your Dockerfile there).

---

<div class="post-metadata">

**Author:** ![user1989](https://avatars.discourse-cdn.com/v4/letter/u/85f322/32.png) [@user1989](https://forums.docker.com/u/user1989)\
**Post date:** [July 5, 2018, 1:47pm UTC](https://forums.docker.com/t/docker-build-in-gitlab-ci/53523/3 "2018-07-05T13:47:34Z")

</div>

> [@agowa338](#):
>
> gitlab-runner

Okay Thank you. I have installed docker toolbox on windows server 2012 R2. I can try to build/run docker image locally without using gitlab-runner to test the builds locally?

---

<div class="post-metadata">

**Author:** ![agowa338](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@agowa338](https://forums.docker.com/u/agowa338)\
**Post date:** [July 5, 2018, 1:52pm UTC](https://forums.docker.com/t/docker-build-in-gitlab-ci/53523/4 "2018-07-05T13:52:46Z")

</div>

If you have installed docker toolbox, you can run “docker build .”? (Haven’t used docker on 2012R2)  
If so, you just have to put `docker build .` into you gitlab-ci.yml for execution on that runner. So what’s exactly the problem?  
Are you trying to build a container by utilizing these artifacts? Or  
Are you trying to build a container for your “build chain”?

---

<div class="post-metadata">

**Author:** ![user1989](https://avatars.discourse-cdn.com/v4/letter/u/85f322/32.png) [@user1989](https://forums.docker.com/u/user1989)\
**Post date:** [July 5, 2018, 2:09pm UTC](https://forums.docker.com/t/docker-build-in-gitlab-ci/53523/5 "2018-07-05T14:09:37Z")

</div>

![image](https://global.discourse-cdn.com/docker/original/3X/d/9/d93d8f39fb3f14478290483de9aa551251ab5ace.jpg)

---

<div class="post-metadata">

**Author:** ![agowa338](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@agowa338](https://forums.docker.com/u/agowa338)\
**Post date:** [July 5, 2018, 2:13pm UTC](https://forums.docker.com/t/docker-build-in-gitlab-ci/53523/6 "2018-07-05T14:13:50Z")

</div>

You missed the dot at the end.  
Your command is `gitlab-runner.exe exec shell docker build` and not `gitlab-runner.exe exec shell docker build .`

---

<div class="post-metadata">

**Author:** ![user1989](https://avatars.discourse-cdn.com/v4/letter/u/85f322/32.png) [@user1989](https://forums.docker.com/u/user1989)\
**Post date:** [July 5, 2018, 2:39pm UTC](https://forums.docker.com/t/docker-build-in-gitlab-ci/53523/7 "2018-07-05T14:39:49Z")

</div>

> [@agowa338](#):
>
> gitlab-runner.exe exec docker build .

Okay thank you so much will try it now. If I mention the build path or “build context” (i.e. current directory ‘.’) is enough right? should i change the executor to “docker” in runner config.toml file ?

---

<div class="post-metadata">

**Author:** ![agowa338](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@agowa338](https://forums.docker.com/u/agowa338)\
**Post date:** [July 5, 2018, 4:05pm UTC](https://forums.docker.com/t/docker-build-in-gitlab-ci/53523/8 "2018-07-05T16:05:17Z")

</div>

You cannot change the executor to docker right now. This is unsuported for windows hosts (also there is currently no gitlab-runner-helper container for windows).  
You have to deal with the shell executor for now.

And I wrote the wrong commands before. It should actually be:  
`gitlab-runner.exe exec shell build`

---

<div class="post-metadata">

**Author:** ![user1989](https://avatars.discourse-cdn.com/v4/letter/u/85f322/32.png) [@user1989](https://forums.docker.com/u/user1989)\
**Post date:** [July 6, 2018, 6:31am UTC](https://forums.docker.com/t/docker-build-in-gitlab-ci/53523/9 "2018-07-06T06:31:31Z")

</div>

Okay Thank you so much once again.
