MacOs 中的 Docker 非常慢 [英] Docker in MacOs is very slow
问题描述
我有这个 docker-compose.yml:
I have this docker-compose.yml:
version: "3.1"
services:
memcached:
image: memcached:alpine
container_name: universal-memcached2
redis:
image: redis:alpine
container_name: universal-redis2
mariadb:
image: mariadb:10.4
container_name: universal-mariadb2
working_dir: /application
volumes:
- .:/application
- "../data/db:/var/lib/mysql" # skasowac
environment:
- MYSQL_ROOT_PASSWORD=Haslo
- MYSQL_DATABASE=sample
- MYSQL_USER=user
- MYSQL_PASSWORD=Haslo
ports:
- "8083:3306"
webserver:
image: nginx:alpine
container_name: universal-webserver2
working_dir: /application
volumes:
- .:/application
- ./phpdocker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8080:80"
php-fpm:
build: phpdocker/php-fpm
container_name: universal-php-fpm2
working_dir: /application
volumes:
- .:/application
- ./phpdocker/php-fpm/php-ini-overrides.ini:/etc/php/7.3/fpm/conf.d/99-overrides.ini
volumes:
generated:
var:
static:
phpmyadmin:
image: phpmyadmin/phpmyadmin
links:
- mariadb
environment:
PMA_HOST: mariadb
PMA_PORT: 3306
ports:
- '8081:80'
当我在 symfony 4 上运行我的最新项目时,它运行得很慢... :(
When I run my newest project in symfony 4 on it, it works very slowly... :(
我有新的 MacO 和 Docker 桌面.我目前正在学习 Symfony 和 Laravel 框架,但这对于 Docker 来说非常慢.它甚至没有工作.
I have new MacOs and Docker Desktop. I'm currently learning the Symfony and Laravel framework, but this is very slow for Docker. It is not even working on it.
我该如何修复它?
推荐答案
事实上,Docker 需要一个普通的 Linux 内核才能运行.不幸的是,Mac OS 和 Windows 无法提供此功能.因此,Mac OS 上有一个客户端来运行 Docker.除此之外,Mac OS 内核和应用程序(Docker 容器)之间还有一个抽象层,文件系统也不一样.因此,Docker 在 Mac OS 上运行缓慢.您无法像在 Linux 上那样在 Mac OS 上运行 Docker.
As a matter of fact, Docker needs a plain Linux kernel to run. Unfortunately, Mac OS and Windows cannot provide this. Therefore, there is a client on Mac OS to run Docker. In addition to this, there is an abstraction layer between Mac OS kernel and applications (Docker containers) and the filesystems are not the same. Because of that, Docker runs on Mac OS slowly. You are not able to run the Docker on Mac OS like on Linux.
如果我需要给出一些关于真实用例的实例.我有同样的机器.所以,我在 Mac OS Mojave 上的 Docker v18 上使用 Symfony 4.这是我在 Docker 上的 Symfony 总执行时间.(显然,这取决于您的前端和数据库查询,但我会尝试为您提供主要逻辑的启发.)
If I need to give some instances about real use-cases. I have the same machine. So, I use Symfony 4 on Docker v18 on Mac OS Mojave. This is my Symfony total execution time on Docker. (Obviously, it depends on your frontend and database queries but I try to enlighten you for main logic.)
- 第一次渲染 12000 毫秒
- 使用 Symfony 缓存:344 毫秒
- 使用 Docker 缓存(:用于卷的 Docker 缓存属性):195 毫秒
只要我在没有 Docker 的情况下使用 Symfony,以下是我的总执行时间.
As long as I use Symfony without Docker, the following is my total execution time.
- 不使用 Docker,使用 Symfony 缓存:82 毫秒
然而,我们可以做一些改进以获得更好的工作空间.例如,您可以使用这样的卷,
Whereas, we could do some improvements to get better workspace. For example, you can use volumes like this,
volumes:
- .:/application:cached
这篇关于MacOs 中的 Docker 非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!