# Building and running a new docker-image

**URL:** <https://discuss.circleci.com/t/building-and-running-a-new-docker-image/20928>\
**Category:** Build Environment\
**Tags:** docker\
**Created:** [March 21, 2018, 11:03pm UTC](https://discuss.circleci.com/t/building-and-running-a-new-docker-image/20928 "2018-03-21T23:03:35Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrsimpson](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/mrsimpson/32/11464_2.png) [@mrsimpson](https://discuss.circleci.com/u/mrsimpson)\
**Post date:** [March 21, 2018, 11:03pm UTC](https://discuss.circleci.com/t/building-and-running-a-new-docker-image/20928/1 "2018-03-21T23:03:35Z")

</div>

Hi there,

I’m Oliver, a noob to CircleCi and I’m having quite a special use case, I guess:  
I need to create a docker image upon which integration tests depend on during CI-execution. I can’t load this image up to dockerhub or alike due to legal reasons.

On Travis, I launched the docker container inside Travis and connected it via `--net=host` ([here](https://github.com/assistify/Rocket.Chat/blob/assistify-circle-ci/.scripts/smarti.sh)).

On Circle-CI, I know I don’t have a docker daemon running but could connect to a remote docker host. I got the image built in this remote host (you can find some remains of it [here](https://github.com/assistify/Rocket.Chat/blob/assistify-circle-ci/.circleci/config.yml#L233) ), but since it relies on other containers running in the primary container, and _since I need a bidirectional HTTP-connection between the primary container and the built-one_, I couldn’t properly get it connected.  
I have seen the hints about networking on the docs, but this addresses two containers talking to each other - I need to achieve the same with the primary one. Any hints on getting them into the same network?

Hope I could explain things properly

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [March 21, 2018, 11:56pm UTC](https://discuss.circleci.com/t/building-and-running-a-new-docker-image/20928/2 "2018-03-21T23:56:24Z")

</div>

I read this through a couple of times, and I didn’t understand it. I think the stuff about the HTTP connection may be an example of [the X-Y problem](https://duckduckgo.com/?q=x-y+problem) - you may be jumping to a non-optimal solution, and it is better to get readers to fully understand the problem instead.

If you cannot store the image at Dockerhub (or presumably any other third-party registry) for legal reasons, then why can you do a build at Travis or Circle? The output image is the same. Do you regard CI systems as more secure than Docker registries?

---

<div class="post-metadata">

**Author:** ![mrsimpson](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/mrsimpson/32/11464_2.png) [@mrsimpson](https://discuss.circleci.com/u/mrsimpson)\
**Post date:** [March 22, 2018, 8:02am UTC](https://discuss.circleci.com/t/building-and-running-a-new-docker-image/20928/3 "2018-03-22T08:02:50Z")

</div>

D’oh! That’s actually what I wanted to avoid. Sorry.  
Let me sketch the requirement a bit more illustratively.

## Requirements

This is how the application looks like, R is to be CI-ed.  
 ![ci1](https://global.discourse-cdn.com/circleci/original/3X/f/f/ff9faea1434a6e57bd90fd9c38be14b3f41eaa0b.png)

- Our application consists of two components, R and S. We want a CI for R.
- There are parts in R which depend on S. R sends HTTP-requests to R which are responded to asynchronously (a second request the other direction).
- There are integration tests between the components which shall be executed during CI
- S contains GPL-components, thus we don’t distribute an image publicly but build the image on-demand for the test. (Yes, a private Docker-repo would be an option, but I don’t have one.)

I’ll post potential solutions into a separate post since I can only add one picture a post…

---

<div class="post-metadata">

**Author:** ![mrsimpson](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/mrsimpson/32/11464_2.png) [@mrsimpson](https://discuss.circleci.com/u/mrsimpson)\
**Post date:** [March 22, 2018, 8:03am UTC](https://discuss.circleci.com/t/building-and-running-a-new-docker-image/20928/4 "2018-03-22T08:03:22Z")

</div>

## Ideas/solutions though of

In order to prevent X-Y-issues: Those are the potential solutions - both might be suboptimal

### Run the image of S inside the primary build container of R

![ci2](https://global.discourse-cdn.com/circleci/original/3X/c/9/c92bb99a064c88663d3c6a33c75f85fe22035844.png)

- We did this on Travis, that was working fine except memory limits
- On CircleCI, there’s no local docker daemon inside the primary container

---

<div class="post-metadata">

**Author:** ![mrsimpson](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/mrsimpson/32/11464_2.png) [@mrsimpson](https://discuss.circleci.com/u/mrsimpson)\
**Post date:** [March 22, 2018, 8:03am UTC](https://discuss.circleci.com/t/building-and-running-a-new-docker-image/20928/5 "2018-03-22T08:03:57Z")

</div>

### Run the image of S on a separate docker-host and connect the networks

 ![ci3](https://global.discourse-cdn.com/circleci/original/3X/8/8/8815249821bfa8128feab4beba9359a8be1a5eb5.png)

- Looks like this was the preferred architectural way
- Don’t know how to make two containers (the primary one and the on running S) see each other

@halfer I hope to have sketched the requiement properly now and separated it from potential solutions - and I’m looking forward to reading your ideas on that!

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [March 22, 2018, 11:55am UTC](https://discuss.circleci.com/t/building-and-running-a-new-docker-image/20928/6 "2018-03-22T11:55:27Z")

</div>

Ah, OK - it sounds like your legal reasons were just relating to the GPL then?

> [@mrsimpson](#):
>
> On CircleCI, there’s no local docker daemon inside the primary container

There is if you want one! Are you using Circle 2.0, and if so, what base image are you using? I use `docker:17.05.0-ce-git` and it works very well.

It strikes me also that Docker Compose would be good for this - it would allow you to bring up R and S and possibly a third image to contain your tests.

---

<div class="post-metadata">

**Author:** ![mrsimpson](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/mrsimpson/32/11464_2.png) [@mrsimpson](https://discuss.circleci.com/u/mrsimpson)\
**Post date:** [March 22, 2018, 12:11pm UTC](https://discuss.circleci.com/t/building-and-running-a-new-docker-image/20928/7 "2018-03-22T12:11:38Z")

</div>

> Ah, OK - it sounds like your legal reasons were just relating to the GPL then?  
> Yup.

I’m using version 2.  
Do you have to install the docker runtime explicitly?

I’ve had no exposure on DockerCompose yet, so I might venture into that one.  
Another alternative which came to my mind was to download the GPL dependencies inside the container of S (instead of building an image based upon S and `ADD`ing them).

As far as I understood, this should do the trick:

```auto
      - image: S
        command: [curl, https://repo1.maven.org/maven2/edu/stanford/nlp/stanford-corenlp/3.8.0/stanford-corenlp-3.8.0.jar, -o, /opt/ext/stanford-corenlp-3.8.0.jar, , -s, &&, curl, https://repo1.maven.org/maven2/edu/stanford/nlp/stanford-corenlp/3.8.0/stanford-corenlp-3.8.0-models-german.jar, -o, /opt/ext/stanford-corenlp-3.8.0-models-german.jar, -s]

```

Anyway, would be interested in how to spin up a container inside the primary container.

Thanks!

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [March 22, 2018, 12:14pm UTC](https://discuss.circleci.com/t/building-and-running-a-new-docker-image/20928/8 "2018-03-22T12:14:36Z")

</div>

> [@mrsimpson](#):
>
> Do you have to install the docker runtime explicitly?

Not if you use the Docker base image I mentioned, it’s already installed. You can do things like `docker build` and `login` and `push`.

> [@mrsimpson](#):
>
> I’ve had no exposure on DockerCompose yet, so I might venture into that one.

It’s how I would tackle it. I have a microservices system that pulls ~10 images into the Circle build container and then starts them up via Docker Compose. The great thing with DC is that it is really easy to learn, and it sets up networking between your containers automagically.

---

<div class="post-metadata">

**Author:** ![mrsimpson](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/mrsimpson/32/11464_2.png) [@mrsimpson](https://discuss.circleci.com/u/mrsimpson)\
**Post date:** [March 22, 2018, 12:16pm UTC](https://discuss.circleci.com/t/building-and-running-a-new-docker-image/20928/9 "2018-03-22T12:16:56Z")

</div>

> [@halfer](#):
>
> Not if you use the Docker base image I mentioned, it’s already installed. You can do things like docker build and login and push.

Alright, how can I make CircleCI use that image?

I might venture into docker compose, thanks for the hint! 👍

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [March 22, 2018, 12:27pm UTC](https://discuss.circleci.com/t/building-and-running-a-new-docker-image/20928/10 "2018-03-22T12:27:43Z")

</div>

> [@mrsimpson](#):
>
> Alright, how can I make CircleCI use that image?

That’s one of the first things in the configuration file:

```
version: 2
jobs:
  build:
    working_directory: /app
    docker:
      - image: docker:17.05.0-ce-git
    steps:
.... rest of your file here

```

Then you can do a `checkout` and maybe a `docker build ...` depending on your requirements. Note that there is no “step by step” guide for this, CI is not trivial to learn! 😺

---

<div class="post-metadata">

**Author:** ![mrsimpson](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/mrsimpson/32/11464_2.png) [@mrsimpson](https://discuss.circleci.com/u/mrsimpson)\
**Post date:** [March 22, 2018, 12:30pm UTC](https://discuss.circleci.com/t/building-and-running-a-new-docker-image/20928/11 "2018-03-22T12:30:54Z")

</div>

Thanks a ton!  
👍

The difficulty in learning is the variety and the small differences between the platforms. Travis != CircleCi != Jenkins != …

I consider this solved now and would revert with new questions in case of new issues.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [June 20, 2018, 12:30pm UTC](https://discuss.circleci.com/t/building-and-running-a-new-docker-image/20928/12 "2018-06-20T12:30:56Z")

</div>

Closed on June 20, 2018, 12:30pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
