Running a script using docker compose



I managed to replicate my development environment using docker-compose in circleci using a docker/docker-compose image. It really works great :slight_smile:

version: 2
     # using custom image, see .circleci/images/primary/Dockerfile
     - image: docker/compose:1.16.1
   working_directory: ~/tfm

     TEST_RESULTS: /tmp/test-results

     - checkout

     - setup_remote_docker

     - run:
         name: Build docker-compose containers
         command: |
           docker-compose build

     - run:
         name: Start containers
         command: |
           docker-compose up -d

     - run:
         name: Verify it's working
         command: |
           docker-compose run app ./

But I have hit a wall when trying to execute a script inside one of the containers.

I have tried running a command using docker-compose.yml specifying the command option for a specific container using

comand: ./

But I get the follwing error:

ERROR: Cannot start service app: oci runtime error: container_linux.go:265: starting container process caused "exec: \"./\": stat ./ no such file or directory"

If I try running the script in .circleci/config.yml (as in the code above)

  - run:
      name: Verify it's working
      command: |
        docker-compose run app ./

I still get the same error (even when I specify the full path to the script).

Any ideas on how to execute a script inside a container using docker-compose?


Yep. Docker Compose will select predictable container names when starting up your container set, so you can just use one of those (see docker ps to get the names).

For example if you have a container called app_widget_server then you can use:

docker exec -it app_widget_server /path/to/

The -it is to get a console, so you can interact with it if necessary, but experiment here.

Or if you prefer using service names rather than container names, look at docker-compose exec, which is pretty much the same thing.


Hi @halfer, thank you for your reply.

I did check and I did get the name correctly, by executing this command:

docker-compose config --services`

The problems seems to be that the files from the repository are not visible in the app container.

This is a bit strange as on the development environment the files are accessible in the app container, but not on CircleCI.

On the docker-compose.yml file the volumes are set this way (this works in the development environment):

  build: .
    - '.:/var/www/rails'
  working_dir: /var/www/rails 

Any suggestions on how to properly mount the repository files on the docker-compose service app using the CircleCI environment?


I suspect you’re bumping into the Docker volume problem:

If you just want to do a checkout in /var/www/rails inside that container, then one option is to build that container in another CircleCI build process, and then pull the image from your registry before starting DC.

Also, you could try mounting a container volume instead of an on-host volume - I think I have that working somewhere :smile_cat:


Thank you for your quick reply :slight_smile:

Could you give me a bit more guidance on how to mount a container volume instead of a on-host volume?


I’m happy to help if you get stuck, but do please search first! I just typed “How to mount a container volume in Docker?” into a search engine, and the Docker docs on volumes were the second result.


No problem, thanks, I will keep looking. If I get stuck I will let you know :slight_smile:


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