Hello friends,
Today I would like to share how to increase perfomance when running Docker on OS.
Hardware:
- MacOS (any operating system)
Software:
- Docker for MAC
- Internet
- IDE Visutal Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | version: '3' # service services: # mysql: Định nghĩa cơ sở dữ liệu MySQL mysql: image: mysql:5.7 ports: - "3306:3306" environment: MYSQL_ROOT_PASSWORD: root volumes: - ./db/mysql_data:/var/lib/mysql # phpadmin: sử dụng phần mềm PHPADMIN để giao tiếp với database thông qua http://localhost:8080/ trên local PC. phpadmin: depends_on: - mysql image: phpmyadmin/phpmyadmin restart: always ports: - '8080:80' environment: PMA_HOST: mysql MYSQL_ROOT_PASSWORD: root # proxy proxy: image: jwilder/nginx-proxy:latest volumes: - /var/run/docker.sock:/tmp/docker.sock:ro ports: - "80:80" # www www: image: atsu666/ioncube:7.2 privileged: true volumes: - ./www:/var/www/html - ~/etc/timezone:/etc/localtime:ro links: - mysql:mysql environment: - VIRTUAL_HOST=localhost # cấu hình máy chủ mysql |
Start initializing and starting container containers:
1 2 | $ docker-compose up -d |
When copying source code (such as wordpress) into the www directory and check to see how? Some operations become very slow! This is because the communication between the host machine (MacOS) and the virtual machine takes place directly and without going through the cache.
To fix this, we add a cached constant to the volumes of the definition section of www:
1 2 3 4 5 6 7 8 9 10 11 12 | www: image: atsu666/ioncube:7.2 privileged: true volumes: - ./www:/var/www/html:cached #Thêm vào định nghĩa cache để làm docker chạy nhanh hơn tren MacOS - ~/etc/timezone:/etc/localtime:ro links: - mysql:mysql environment: - VIRTUAL_HOST=localhost # cấu hình máy chủ mysql |
Restart docker-compose:
$docker-compose down
$docker-compose up -d
Cheer!
Docker has become as fast as a Linux virtual machine.