mysql docker容器的性能问题

时间:2019-01-02 13:21:02

标签: mysql docker

我将mysql数据库迁移到docker,并恢复了转储文件。我的mysql服务器直接安装在Linux上,没有问题。在docker容器上,我的查询速度降低了30倍。有人有类似的问题吗?我在Ubuntu 16上运行docker,并且正在使用以下docker compose:

version: '3'
services:
  db:
    image: mysql:5.7
    environment:
      - MYSQL_ROOT_PASSWORD=root
    volumes:
      - ~/mysql/:/var/lib/mysql/
    ports:
      - "3306:3306"

  web:
    build: .
    volumes:
       - .:/var/www/html/app/
    ports:
      - "80:80"
    depends_on:
      - db

3 个答案:

答案 0 :(得分:0)

感谢您的帮助。

Docker信息:

 Containers: 2
 Running: 2
 Paused: 0
 Stopped: 0
Images: 13
Server Version: 18.09.0
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runcInit Binary: docker-initcontainerd version: c4446665cb9c30056f4998ed953e6d4ff22c7c39runc     version: 4fc53a81fb7c994640722ac585fa9ca548971871init version: fec3683Security Options: apparmor seccomp      Profile: defaultKernel Version: 4.15.0-1021-awsOperating System: Ubuntu 18.04.1 LTSOSType: linuxArchitectu    re:     x86_64CPUs: 1Total Memory: 983.9MiB    
Name: ip-172-31-73-156    
ID: VESU:SBIN:X434:OXL    Q:X3OX:ZUAZ:SQKU:XHH7:5WJ7:C6F2:P4GE:SZLV    
Docker Root Dir: /var/    lib/docker    
Debug Mode (client): f    alse    
Debug Mode (server): f    alse    
Registry: https://inde    x.do    cker.io/v1/    
Labels:    
Experim    ental: false    
Insecur    e Registries:    
 127.0.0.0/8    
Live Restore Enabled: false
Product License: Community Engine

文件系统:

GNU Parted 3.2
Using /dev/xvda1
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: Unknown (unknown)
Disk /dev/xvda1: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:

Number  Start  End     Size    File system  Flags
 1      0.00B  21.5GB  21.5GB  ext4

答案 1 :(得分:0)

不知道它是否还能为您提供帮助。面对同样的问题,因此我试图弄清楚。从主机文件系统到容器的卷显然会大大降低它的速度。尝试对您的音量使用以下设置:

~/mysql/:/var/lib/mysql:delegated

唯一的缺点是,写入/ var / lib / mysql内部的数据可能需要一些时间才能写入本地文件系统。

答案 2 :(得分:0)

我在台式机上没有遇到过这样的问题,但是mysql容器在我的笔记本电脑上以一种我无法理解的方式运行得很慢。 This solution 解决了我的问题。