Docker

Mint supports running and building Docker containers inside of tasks using the docker CLI. To enable support for Docker in a task, specify docker: true:

tasks:
  - key: container
    docker: true
    run: docker run hello-world

Mint's Docker functionality is most commonly used to run background services as part of a task:

tasks:
  - key: packages
    run: |
      sudo apt-get update
      sudo apt-get install netcat redis-tools
      sudo apt-get clean

  - key: ping-redis
    use: [packages]
    docker: true
    background-processes:
      - key: redis
        run: docker run -p 6379:6379 index.docker.io/library/redis:latest
        ready-check: nc -z localhost 6379
    run: |
      redis-cli ping

Preserving Docker data

By default, Mint deletes all data related to Docker at the end of a task. If you want to preserve the images you have pulled or the volumes used by your containers, you can specify docker: preserve-data. This is very useful for pulling and caching images ahead of the task that actually uses them:

tasks:
  - key: hello-world-image
    docker: preserve-data
    run: docker pull hello-world

  - key: container
    use: hello-world-image
    docker: true
    run: docker run hello-world

Mint's internal networking and cache layer management is faster than Docker's, so typically pre-pulling large images in a cached task will be faster than pulling them on-demand in the task that needs them.

Caching Docker volumes

You can also take advantage of preserved Docker data to cache Docker volumes needed by your task. For example, if your test suite relies on a Postgres database being set up a certain way, you can perform your database setup in one task and then have your testing task depend on that setup task:

tasks:
  - key: packages
    run: sudo apt-get update && sudo apt-get install netcat postgresql-client && sudo apt-get clean

  - key: postgres-image
    docker: preserve-data
    run: docker pull postgres

  - key: postgres-data
    use: [packages, postgres-image]
    docker: preserve-data
    background-processes:
      - key: postgres
        run: |
          docker volume create pgdata
          docker run -p '5432:5432' -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -v pgdata:/var/lib/postgresql/data postgres
        ready-check: nc -z localhost 5432
    run: |
      psql postgres://postgres:[email protected]:5432 -c "CREATE DATABASE db;"
      psql postgres://postgres:[email protected]:5432/db -c "CREATE TABLE users (id SERIAL PRIMARY KEY, email VARCHAR(255));"
      psql postgres://postgres:[email protected]:5432/db -c "INSERT INTO users (email) VALUES ('[email protected]');"

  - key: test
    use: postgres-data
    docker: true
    background-processes:
      - key: postgres
        run: docker run -p '5432:5432' -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -v pgdata:/var/lib/postgresql/data postgres
        ready-check: nc -z localhost 5432
    run: psql postgres://postgres:[email protected]:5432/db -c "SELECT * FROM users;"

Enabling incremental Docker builds

Preserving Docker data also allows you to enable incremental Docker builds inside your task. Using a tool cache, you can preserve the Docker build cache from a Docker build and restore it the next time the task attempts the same Docker build:

- key: dockerfile
  run: |
    cat << EOF > Dockerfile
    FROM ubuntu:22.04
    RUN apt-get update &&  apt-get install -y curl && apt-get clean && rm -rf /var/lib/apt/lists/*
    EOF
- key: docker
  use: dockerfile
  docker: preserve-data
  tool-cache: true
  cache: false
  run: docker build .

Running this sample run twice will show that the apt-get build step is a cache hit in the second run.