Worrisome that this has been open for this long without resolution.
I wish Docker would add a “recommended database and performance optimizations” section to their docs.
For the benefit of anyone finding this issue via Google, and where you are using Docker Desktop for Mac, the following are worth a read: https://docs.docker.com/compose/compose-file/#caching-options-for-volume-mounts-docker-desktop-for-mac and https://docs.docker.com/docker-for-mac/osxfs-caching/.
By adding the delegated
option to the end of your volume specification in docker-compose (or via the docker run
command), you reduce the consistency requirements between container and host (which is generally fine for the database). Here’s an example from my docker-compose file:
version: '3.7'
services:
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: example
volumes:
- ~/Projects/Mike/mysql:/var/lib/mysql:delegated
Making this change resulted in a substantial speed improvement.
I have same problem. Docker container much slower run on host machine with python script use large memory (10GB) or with sqlite3.
Looks like adding --skip-name-resolve
resolved the issue for me. Full command:
docker run -p 3306:3306 \
--name global-mysql \
-v $PWD/conf:/etc/mysql/conf.d \
-v $PWD/logs:/logs \
-v $PWD/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql:5.7 \
--skip-name-resolve
Thank you @renomarx this change fix the issue on my side
It’s Great, work well