Error installing docker on machine executor


#1

Hello,

When testing the machine executorType, I got an error when installing the Docker Engine (screenshot below).
Any idea what the problem can be ?

stages:
build:
workDir: ~/app
steps:
- type: checkout
name: Checkout application code
- type: shell
name: Install Docker Engine
command: |
curl -L -o /tmp/docker.tgz https://get.docker.com/builds/Linux/x86_64/docker-1.12.3.tgz
tar -xz -C /tmp -f /tmp/docker.tgz
mv /tmp/docker/docker* /usr/bin/
- type: setup-docker-engine
- type: shell
name: Verify Docker Works
command: |
docker --version
docker run hello-world


Getting Started: Docker Engine
Getting Started: Docker Engine
Docker machine executor cache workaround
#2

You should not need to install it. But if you want/have to, just rsync the directory over to /usr/bin. You won’t have much success with mv if there are files to be replaced in the way you encountered it.


#3

From what I understand, if going with “docker” executorType, I need to install Docker Engine to build an image, or I need to use a docker-in-docker image, correct ?
When installing the Docker Engine, I use the same command that the one in the example, is there something I’m missing ?
Thanks a lot for your help,
Luc


#4

That is correct. But when using the machine executorType, docker should already be installed.


#5

Thanks, I have the following approach going with the machine executorType,

For the test of one of my service to be done, I need to have running instances of RabbitMQ, Mongo and Redis. In CircleCI version 1.0, those service are running on localhost and can be accessed by the service that is beeing tested (very convenient).
It seems it required some more setup when running on the 2.0 infrastructure.

Below is the path I went through to setup my tests. Any feedback is more than welcome.

Defining a docker-compose file with the dependencies my application uses

As my application depends on Rabbit, Mongo and Redis, I came up with the following compose file in which each service publishes its port onto the host.

$ cat docker-compose.yml
version: '2'
  services:
    # Data store
    db:
      image: mongo:3.2
      ports:
        - "27017:27017"
    # Session store
    kv:
      image: redis:3.0.7-alpine
      ports:
        - "6379:6379"
    # RabbitMQ server
    mq:
      image: 'rabbitmq:3.6'
      ports:
        - "5672:5672"

The idea is to run “docker-compose up -d” to launch the services and then run the application and the test, connecting to the services through localhost.

The problem encountered here is that MongoDB is already running on the dedicated VM created at the beginning of the build. Removing Mongo from the compose file would be a solution but not really portable though.

Run the application and the test within the same compose stack as the dependencies

Instead of relying on external dependencies, I’ve made the application and the test 2 additional services of the compose stack.

$ cat docker-compose.yml
version: '2'
  services:
    db:
      image: mongo:3.2
    kv:
      image: redis:3.0.7-alpine
    mq:
      image: 'rabbitmq:3.6'
    # Application to test
    app:
      build: .
      depends_on:
        - db
        - kv
        - mq
    # Test to run against the application
    test:
      build:
        context: .
        dockerfile: Dockerfile-test
      depends_on:
        - app 

The circle.yml file is something like:

version: 2
executorType: machine
stages:
  build:
    workDir: ~/app
    steps:
      - type: checkout
      - type: shell
        name: build application image
        shell: /bin/bash
        command: docker-compose build app
      - type: shell
        name: build application test image
        shell: /bin/bash
        command: docker-compose build test
      - type: shell
        name: run test
        shell: /bin/bash
        command: docker-compose run test
      - type: shell
        name: build image
        shell: /bin/bash
        command: |
          docker build --rm=false -t USER/REPO:$CIRCLE_BRANCH .
          docker tag USER/REPO:$CIRCLE_BRANCH USER/REPO:$CIRCLE_SHA1
      - type: shell
        name: push image to Docker Hub
        shell: /bin/bash
        command: |
          docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS
          docker push USER/REPO:$CIRCLE_BRANCH
          docker push USER/REPO:$CIRCLE_SHA1

On each commit to GitHub, I basically:

  • build the app image
  • build the test image
  • run the test image against the whole stack

Instead of building the application image (for the second time) once the tests are done, I should probably tag the first image created as it seems the image’s layers are not cached.

Another approach could maybe be to only run de dependencies in compose and to “attach” the app and test in the network created (something like WORKDIR_default).

Any feedback / though on this approach ?


#6

Can you stop the Mongo service on the host before bringing up the Mongo container? That should solve the overlap.

Attaching the app makes sense to me; I’d just test it to make sure there is no performance hit.


#7