0

I have a Laravel application which has some Integration Tests and this project has Dockerized using Docker Compose and it's consisted of 5 containers: php-fpm, mysql, redis, nginx and the workspace which have php-cli and composer installed in itself (just like Laradock). I want to run the tests while the test stage is running in my CI process. I have to mention that my CI Server is GitLab CI.

Basically, I run the tests on my local system by running the following commands in my terminal:

$ docker-compose up -d
Creating network "docker_backend" with driver "bridge"
Creating network "docker_frontend" with driver "bridge"
Creating redis     ... done
Creating workspace ... done
Creating mysql     ... done
Creating php-fpm   ... done
Creating nginx     ... done

$ docker-compose exec workspace bash
// now, I have logged in to workspace container

$ cd /var/www/app
$ phpunit
PHPUnit 6.5.13 by Sebastian Bergmann and contributors.

........                                                            8 / 8 (100%)

Time: 38.1 seconds, Memory: 28.00MB

OK (8 tests, 56 assertions)

Here is my question: How I can run these tests in test stage while there is no running container? What're the Best Practices in this case?

I also followed this documentation of GitLab, but it seems that is not OK to use Docker-in-Docker or Docker Socket Binding.

Erfun
  • 1,079
  • 2
  • 11
  • 26
  • Do your tests use resources from the other containers? I.e. do they connect to the database? – Constantin Galbenu Feb 03 '19 at 06:35
  • @ConstantinGalbenu Yes, they do. Some of the tests need a testing database to run migrations and working with dummy data. Also, redis container should be accessible. – Erfun Feb 03 '19 at 07:34

1 Answers1

0

First, it is absolutely ok to run docker-in-docker with gitlab ci. This is a greate way if you dont want or dont need to dive into kubernetes. Sharing docker socket of course somehow lowers the isolation level, but as far as you mostly run your jobs on your VPS containers, I personally dont find this issue critical.

I've answered similar question some time ago in this post.

grapes
  • 8,185
  • 1
  • 19
  • 31
  • I read about this in one of Docker-in-Docker contributor's blog that we should not use DinD for CI or testing environment. https://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/ – Erfun Feb 02 '19 at 11:38
  • When you **share socket**, I mean `/var/run/docker.sock`, it is not pure **docker in docker**, and it is exactly what is written in that article. You are using host's docker daemon. – grapes Feb 02 '19 at 11:55
  • And you dont need priviledged mode when sharing a socket – grapes Feb 02 '19 at 11:55
  • It was about the DinD, so it's not OK to use `docker-in-docker`. On the other hand, I have some containers that are running on the host machine and mounting the socket may affect them. I want to know what're the best practices about the running tests in multi-containers projects. – Erfun Feb 02 '19 at 12:03