To be able to run your test container into the pipeline you need to run the job as a docker container (see Running inside Docker), so you need Docker-In-Docker (docker:dind) service and mount the docker's socket. Also if you have "Permission denied" you need to run your container as root user:
# to improve performance
variables:
DOCKER_DRIVER: overlay2
# we need DinD service
services:
- docker:dind
test:
image: docker:latest
stage: test
script:
- >
docker run -t --rm
-v /var/run/docker.sock:/var/run/docker.sock
-v "$(pwd)":"$(pwd)"
-w "$(pwd)"
-u 0:0
gradle:3.4 ./gradlew test
only:
- masterIn this job we run in a multiline command a docker container:
- using the official gradle image
- to be delete when finished
- use the root user if you are running a Shared Runner
Your CircleCI configuration should use a dedicated VM for testcontainers to work. You can achieve this by specifying the
executor type in your .circleci/config.yml to be machine instead of the default docker executor ( see Choosing an Executor Type for more info ).
Here is a sample CircleCI configuration that does a checkout of a project and runs maven:
# Check https://circleci.com/docs/2.0/language-java/ for more details
#
version: 2
executorType: machine
jobs:
build:
steps:
- checkout
- run: mvn -B clean install