Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to speed up mysql docker container for tests?

I use docker/docker-compose to run services and tests. One of the services is mysql:

db:
    image: mysql:5.6
    environment:
      - MYSQL_ALLOW_EMPTY_PASSWORD=yes
    expose:
      - "3306"

Is there any way I can optimize the container's speed specifically for tests (e.g. keep everything in memory, etc.) ?

like image 526
planetp Avatar asked Oct 24 '25 14:10

planetp


1 Answers

Well, you could run your database in RAM if you have enough space to do so. That might speed things up a bit.

services:
  db:
    image: mysql:5.6
    environment:
      - MYSQL_ALLOW_EMPTY_PASSWORD=yes
    expose:
      - "3306"
    tmpfs:
      - /var/lib/mysql

Source

  • https://docs.docker.com/v17.09/engine/admin/volumes/tmpfs/#differences-between---tmpfs-and---mount-behavior
  • https://docs.docker.com/compose/compose-file/#tmpfs
  • https://www.stefanproell.at/2019/02/08/lightning-fast-integration-tests-with-docker-mysql-and-tmpfs/
like image 87
ckaserer Avatar answered Oct 26 '25 17:10

ckaserer