2

I'm trying to setup CI with GitHub Actions. My project is using docker & docker-compose (Laradock actually, but that does not matter). It is the first time I'm setting up a workflow/ action with GitHub. I'm used to gitlab-ci... however

In one step I'm running the docker containers:

  • docker-compose up -d nginx mariadb
Creating laradock_mariadb_1 ... 
Creating laradock_docker-in-docker_1 ... 

Creating laradock_mariadb_1          ... done

Creating laradock_docker-in-docker_1 ... done
Creating laradock_workspace_1        ... 

Creating laradock_workspace_1        ... done
Creating laradock_php-fpm_1          ... 

Creating laradock_php-fpm_1          ... done
Creating laradock_nginx_1            ... 

Creating laradock_nginx_1            ... done

And in the next step I want to use the containers:

  • docker-compose exec workspace composer install

This fails with the message: No container found for workspace_1

I am assuming I need to do something like creating an artifact for the first step and use it in the second step. At least that's something you'd do in GitLab CI.

I have not found any examples or solutions on the internet. I guess because GitHub's Actions is still a very new feature. So hopefully this thread will help other beginners as well.

EDIT

Cutaraca
  • 2,069
  • 3
  • 14
  • 21
  • Can you post your actual `docker-compose.yml` and workflow yml file. Github action steps do not run in separate environments – smac89 Jan 12 '20 at 21:08
  • @smac89 I attached them to the post. – Cutaraca Jan 12 '20 at 21:19
  • See if this link helps: https://forums.docker.com/t/solved-docker-compose-exec-error-no-container-found-for-web-1/25828 It seems the problem is that you needed to do `docker-compose up -d workspace` before running this step – smac89 Jan 12 '20 at 21:47
  • @smac89 Thank you but it is definetely up, as you can see from the logs of the previous step. This works perfectly on my local machine. – Cutaraca Jan 12 '20 at 23:43
  • I just tested the ability to run a command in a Docker-Compose container started by a GitHub Actions step earlier - and it works [as this build log shows](https://github.com/jonashackt/traefik-cache-nginx-spring-boot/runs/1595836431?check_suite_focus=true). I have a slightly different Docker-Compose setup ([here's the full project](https://github.com/jonashackt/traefik-cache-nginx-spring-boot/tree/docker-compose-test)), so I guess it has something to do with specific configuration or directory structure of yours? An example project on GitHub solely for this would help... – jonashackt Dec 22 '20 at 16:23
  • 1
    Just be sure to `exec` into the containers with the `-T` parameter like this: `docker-compose exec -T workspace composer install`. With this parameter you can switch off the default pseudo-tty allocation by Compose. Otherwise you'll run into errors like `the input device is not a TTY`. Also you could use a `docker ps -a` to show all running containers, so you should see if there's really no `workspace_1`... ([example build here](https://github.com/jonashackt/traefik-cache-nginx-spring-boot/runs/1595930505?check_suite_focus=true)) – jonashackt Dec 22 '20 at 16:29

0 Answers0