Publish docker image using docker-compose

I’m trying to create a simple build which checks out a project runs docker-compose build && docker-compose push. Here’s my config.

version: 2.1
   working_directory: /app
     - image: docker:20.10.3
     - checkout
     - setup_remote_docker:
         docker_layer_caching: false
     - run:
         name: Setup env
         command: ln -s env.template .env
     - run: 
         name: loginto docker
         command: |
           echo "$DOCKER_PASS" | docker login --username $DOCKER_USER --password-stdin
     - run: 
         name: Install Docker Compose 
         command: | 
            set -x curl -L`uname -s`-`uname -m` > /usr/local/bin/docker-compose &&  chmod +x /usr/local/bin/docker-compose
     - run: 
        name: Setup docker-compose alias
        command: ln -s production.yml docker-compose.yml
     - run: 
        name: build docker
        command: docker-compose build        
     - run:
         name: Docker Push
         command: docker-compose push ghost

      - build: 
            - DOCKER
              only: master          

All the steps that involve docker-compose are behaving as if they worked but they provide no output.

case in point:

#!/bin/sh -eo pipefail
docker-compose build
CircleCI received exit code 0

It obviously didn’t do the job, the image isn’t published but not sure how to debug this. What am I doing wrong here?

1 Like

Looks like you are making use of setup_remote_docker. The first thing I would do would be to make use of the most recent version of docker on the remote docker instance:

- setup_remote_docker:
    docker_layer_caching: false
    version: 19.03.12

I’m not sure about the contents of your docker-compose.yml, but that does look like it should work as written. What is the output of your docker-compose build command? Also, the output of the docker-compose push ghost command?

One thing to keep in mind is that Remote Docker makes use of a remote instance. The docker daemon is actually running on separate instance. If you SSH into your job, you can actually ssh into that via

ssh remote-docker

This can confuse some people when they first use remote docker as they expect things to work the same as if it was running locally. One common issue is with things like volume mounts. These behave differently because the daemon is not running on the same instance as the docker cli client.