Docker Community Forums

Share and learn in the Docker community.

Disable volumes declared in docker-compose file for testing, possible?


(Frondor) #1

I want to do docker-compose run --rm my-service npm run test;

In my docker-compose.yml, my-service depends_on on database service, which uses some local volumes that I don’t want to honor while executing the command above, because I may have created some data on development QA.
I know I could use just another database for testing, but it’s not only the database service that may be polluted with data, I got some other services (like s3 mocking) that may have some files I don’t want to see from within the test cases.

Is there any way I can “disable” local volumes for certain docker-compose run command? Like docker-compose run --rm --no-volumes my-service npm run test

The volumes of my docker-compose.yml

  database:
    container_name: database
    image: mariadb:10.3.6
    ports:
      - 3306
    volumes:
      - db_data:/var/lib/mysql

  redis:
    container_name: redis
    image: redis:3.2.11-alpine
    ports:
      - 6379
    volumes:
      - redis_data:/data

volumes:
  db_data:
    driver: local
  redis_data:
    driver: local

Do I need to create a docker-compose.testing.yml file? How can I override those volumes to “disable” them and run the tests?

Also, if I have this compose file

version: '3'
services:

  api:
    build: ./node-app
    depends_on:
      - database
    environment:
      - PORT=3001

  database:
    environment:
      - MYSQL_DATABASE=project

I can do docker-compose run --rm -e PORT=3002 api npm run test and properly override the PORT in the compose file, but how can I also provide an override to a dependency of that api service (database) if I want to provide a different MYSQL_DATABASE?