Docker extremely slow, on linux and windows

Hi guys, I was working with Docker on a Win11 machine and the application run very very slow, around 30 seconds or even 1 minute to load a single page (not easy to work like this :frowning: ).
I have the same application running in Elastic Beanstalk (AWS) smoothly and fast, even I tried to run a Xamp server and everything worked fine, the problem is when I use Docker. Currently, I am working on Ubuntu 22.04 LTS but I have the same problem. I also installed Docker desktop, but it does not matter what I do, the result is always the same (very very slow responses), is there something I can do?

The application is a PHP 7.4.

This is how I configurated the ā€œResourcesā€
CPUs: 10
Memory: 26Gb (the host machine has 32Gb)
Swap: 2.5GB ( I tried many different configurations but it does not make any difference)
Disk Image size: 64Gb

And the host machine:

SO: Ubuntu 22.04 LTS
Memory: 32Gb
Processor Inter Core i7 CPU 2.60ghz
Disk: 1Tb

Thanks in advance.

1 Like

One of the more common problems for Developers that use Windows is that the projects with Docker configuration work really slowly, to a point when sometimes a single browser request needs to wait 30-60 seconds to be completed. This is obviously a problem, one that negatively affects project progression and generally makes the life of developers more difficult.
Picsart for window & Pc 2022

Why is Docker so slow? The root of the issue is that Windows 10 is (was) using WSL (Windows Subsystem for Linux), which is a layer between Windows and Linux. Communication between these two (Hard Drive operations) can be quite slow.

It is odd that the slowness occurs on a bare metal Ubuntu installation as well. Please share how you install docker and the exact commands and or image you used to create your containers. Additionaly please add the output of docker info

In case you use bind-volumes (-v /host/path:/container/path), try if using named volumes (-v volume-name:/container/path) makes a difference. Personally I have never experienced docker being slow.

Hi mate,
I am on Linux now. I tried many different configurations, but nothing changes. The same code is working very fast in AWS, but in local it goes very very slow with Docker. I really donā€™t know what I can do, I already tried many things.

Ok , here is the docker info.

 docker info
Client:
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Docker Buildx (Docker Inc., v0.9.1-docker)
  compose: Docker Compose (Docker Inc., v2.10.2)
  extension: Manages Docker extensions (Docker Inc., v0.2.9)
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
  scan: Docker Scan (Docker Inc., v0.19.0)

Server:
 Containers: 2
  Running: 2
  Paused: 0
  Stopped: 0
 Images: 2
 Server Version: 20.10.17
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runtime.v1.linux runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.10.124-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 10
 Total Memory: 25.46GiB
 Name: docker-desktop
 ID: ZXOQ:5FED:TV2Y:KX5O:L7TF:Q626:4COZ:NWJO:WAJH:72ST:KBGC:X7NI
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: true
 Insecure Registries:
  hubproxy.docker.internal:5000
  127.0.0.0/8
 Live Restore Enabled: false

And this is my docker file


FROM php:7.4.8-apache
ENV NVM_DIR=/root/.nvm
ENV NODE_VERSION=16.17
ENV USER=www-data
#set our application folder as an environment variable
ENV APP_HOME /var/www/html
ENV PATH="/root/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
# # Add cake and composer and cake command to system path
ENV PATH="${PATH}:/var/www/html/lib/Cake/Console"
ENV PATH="${PATH}:/var/www/html/vendor/bin"

# COPY apache site.conf file
COPY ./config-dev-server/apache/* /etc/apache2/
COPY ./config-dev-server/php/conf.d/* /usr/local/etc/php/conf.d/
COPY ./config-dev-server/php/php.ini-development.ini /usr/local/etc/php/php.ini

# Project structure.
COPY . $APP_HOME

#install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer \

    #change uid and gid of apache to docker user uid/gid
    && usermod -u 1000 www-data && groupmod -g 1000 www-data \
    && mkdir -p  /var/www/html/logs \
    && mkdir -p  /var/www/html/tmp \
    ## Clear cache
    && apt-get clean && apt-get autoclean && apt-get autoremove && rm -rf /var/lib/apt/lists/* \
    # Install system dependencies
    && apt-get -o Acquire::Check-Valid-Until="false" update \
    && apt-get update && apt-get install --no-install-recommends -y \
        # git \
        curl \
        npm \
        libpng-dev \
        libonig-dev \
        libxml2-dev \
        zip \
        unzip \
        
        # Install PHP extensions
        && docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd intl \
        && pecl install xdebug \
        && docker-php-ext-enable xdebug \
        
        # fix npm - not the latest version installed by apt-get && install amplify
        && npm install -g \
            npm@8.15 \
            @aws-amplify/cli \
        && a2enmod rewrite \
        && curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash \
        && . "$NVM_DIR/nvm.sh" && nvm install ${NODE_VERSION} \
        && . "$NVM_DIR/nvm.sh" && nvm use v${NODE_VERSION} \
        && . "$NVM_DIR/nvm.sh" && nvm alias default v${NODE_VERSION} \
        && node --version \  
        && npm rebuild node-sass \
        && groupadd docker \
        && usermod -aG docker $USER \
        && chown -R www-data:www-data $APP_HOME/  \
        # Changing log owner:group and permissions.
        && chown -R www-data:www-data /var/log/* \
        # change permissions
        && chmod 755 -R $APP_HOME/  \
        && chmod 777 -R /var/log/*  

WORKDIR  $APP_HOME/webroot
EXPOSE 8 8080

And this is the docker-compose.yml

version: "3.1"
services:
  cakephp:
    image: my-cakephp:2.1
    build: .
    container_name: my-webserver
    ports:
      - "${APP_PORT}:80"

    volumes:
      - .:/var/www/html/
      - ./logs/apache2:/var/log/apache2
      - ./logs/xdebug:/var/log/xdebug
    
    environment:
      - HOSTNAME= *my ${ENVIRONMENT} server*
      - WEB_DOCUMENT_ROOT=/var/www/html/webroot/
      - SECURITY_SALT= *some salt here*  
      - MYSQL_URL=mysql
      - MYSQL_USERNAME=root
      - MYSQL_PASSWORD=${MYSQL_ROOT_PASSWORD}
 
    depends_on:
      - mysql
    links:
      - mysql

  mysql:
    image: mysql:5.7.32
    container_name: my-mysql
    ports:
      - "${PORT}:3306"
    volumes:
      - ./db:/docker-entrypoint-initdb.d
      - mysql-data:/var/lib/mysql
    environment:      
      - MYSQL_DATABASE=${MYSQL_DATABASE}
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_USER=${MYSQL_USER}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
      - MYSQL_ROOT_HOST=${MYSQL_ROOT_HOST}

volumes:
  mysql-data:

Well, it seems that my post was hidden again, a shame. I sent you all the details you asked me. About the ā€œDisk image locationā€ is it important? Anyway, before I changed it, I was using the default one and it was running very slow as well. Thanks

Any plans on sharing the exact commands of what you tried? Judged by the shared information, the only thing we know is that containers are running slow on Windows and Linux, even though the machines they are running on are not slow.

After many tries, the system still baning my posts, so I give up. Thanks anyway guys. I was able to post all the info here linux - Docker very slow in Ubuntu 22.04 - Stack Overflow .

Make sure you format your post properly so links in the code will not be interpreted and made clickable.

Since you did that on stack overflow, I would think that you did that here too, so the forum should not have banned your post.

The only reason I can think of to make Docker slow on Linux without using Docker Desktop is the fact that it uses a special filesystem. Usually overlay2. When you run Xampp on your machine, it will just use the filesystem of your host directly. If Docker data root is on a local HDD or SSD, it should not matter. In case you mount your data root from a network filesystem or some other special drive which is not compatible with overlay2 that can make Docker slower if it works at all.

In case of Docker Desktop, your local files would be mounted into the virtual machine using VirtioFS so those files would not be used directly. I think VirtioFS should be faster that other solutions, but I have never used Docker Desktop for Linux in a situation in which I would notice the speed difference. I use My Docker Desktop for Mac frequently (not for write-intensive or read-intensive applications) and it works fine. So in case of Docker Desktop you can take @meyayā€™s advice and use volumes instead of bind mounts whenever it is possible. In case of Docker CE running on the host directly on a local disk it should be as fast as running the application without containers since the process inside the container actually runs on your host, it is just isolated from the rest of the environment.

Since you shared your docker info on stackoverflow showing that you use Docker Desktop for Linux, you will most likely get answers to tell you the cause is that Docker Desktop uses a virtual machine to run your containers, so I recommend you to share the result of docker info running directly on your host not on Docker Desktop.

Hi, thanks for your answer.
Before I tried the desktop version I worked with Docker CE and I got the same results, very slowā€¦
On the other hand, I already use volumes for Mysql but not for the app, because I need to be able to sync with my host machine in order to work with the code, thatā€™s why I use ā€œhost volumesā€ (I think it is the same than bind right?). I will try today in a MAC and check the differences.

update: you gave an idea mate, I am moving outside the host volume (to volumes) all the code that not need to be bind with the host, for example, vendors and node_modules, will see what happens :slight_smile:
Regards.

Yes, I got that. I thatā€™s why I say you should share the output of Docker CE so nobody will say that it is slow because of the Desktop.

Probably, but I never heard to say that in case of Docker. I searched for it now and it looks like many articles refer to bind mounts as host volumes but I donā€™t think it is mentioned this way in the documentation. Kubernetes has ā€œhostPathā€ volume meaning the same.

After removing everything in my ubuntu 22.04 and installing Docker from scratch, I still have the same problem.
This is the docker info without docker desktop.


Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Docker Buildx (Docker Inc., v0.9.1-docker)
  compose: Docker Compose (Docker Inc., v2.10.2)
  scan: Docker Scan (Docker Inc., v0.17.0)

Server:
 Containers: 3
  Running: 2
  Paused: 0
  Stopped: 1
 Images: 18
 Server Version: 20.10.18
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.15.0-43-generic
 Operating System: Ubuntu 22.04.1 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 31.19GiB
 Name: r0buntu
 ID: CZQE:UUB7:RFC3:BLNY:3INI:2CEH:CESQ:J3JN:XAHO:EEMZ:EFRS:QAMK
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

This is from Chome dev tools, about how long a page takes for loading.

40 requests

258 kB transferred

5.3 MB resources

Finish: 24.49 s

DOMContentLoaded: 24.19 s

Load: 25.14 s

Most of the dashboard pages take more than 20secs, I do not find a big improvement after:
1 Remove Docker desktop and use Docker CE.
2 Move node_modules and vendors to volumes.

Thanks

Questions:

  • Just to be sure, you donā€™t store /var/lib/docker or the mounted fodlers on a network filesystem or any special device, right?
  • Can you tell us anything about the disk on which you store the data? SSD, HDD? Frankly I am not sure what I should ask, so I am trying to ask for any information that at least can give us an idea.
  • Is the container slow all the time or is a page faster when you load it the second time?

Ideas

Using process isolation canā€™t slow PHP down, so it must be something with the filesystem or some special hardware that we donā€™t know so we canā€™t even ask about that.

I would also make sure not to save any large file in the Docker image that should be changed after running the container. When the a process changes a file in a container that was on image filesystem layer, first it will copy the whole file to the containerā€™s filesystem which can take time at the first time.

I used PHP (Symfony Framework) in Docker containers and I never had any problem like you have.

Hi, I will try to answer all your questions.

The docker is in an ssd partition, it is not a network system or any special device.
size: 923 GB ā€” 886 GB free (4.0% full)
Contents: Ext4 (version 1.0) ā€” Mounted at /media/xulin/home
Device: /dev/nvme0n1p7
Partition Type: Linux Filesystem (System)

  • Is the container slow all the time or is a page faster when you load it the second time?
    Same time, the cache does not help, thatā€™s why I think it is more related to the Mysql container, but it is kind of weird because this Mysql container is a volume and I am using a mysql 5.7 official image.
    In the dashboard does not matteri if it is the first or the number 10 load, the pages take always around 20/30 seconds.

I am working on a Cakephp 3 application.
Note: I realized that the frontend is loading a bit faster (I can say near to normal) than the dashboard, and this is why I start thinking that it is related to the MySQL container because the dashboard has more queries, results etcā€¦ And the frontend it is React based (with less Mysql queries).

Here is again the docker info just in case (I moved docker to a bigger partition, in the same ssd)

Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Docker Buildx (Docker Inc., v0.9.1-docker)
compose: Docker Compose (Docker Inc., v2.10.2)
scan: Docker Scan (Docker Inc., v0.17.0)


Server:
 Containers: 2
  Running: 2
  Paused: 0
  Stopped: 0
 Images: 17
 Server Version: 20.10.18
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runtime.v1.linux runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.15.0-43-generic
 Operating System: Ubuntu 22.04.1 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 31.19GiB
 Name: Xulintu
 ID: CZQE:UUB7:RFC3:BLNY:3INI:2CEH:CESQ:J3JN:XAHO:EEMZ:EFRS:QAMK
 Docker Root Dir: /media/xulin/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Or maybe it is the speed of PHP. What happens when you disable XDebug? If you have XDebug in Xampp with better speed it is still not normal to be so slow in Docker, but it could be because of some extensions or the XDebug version and using overlay filesystem together.

Hi, I tried two things.

1 Move to a mysql 8 image instead of the 5.7
2 Remove Xdebug

and this is what I get now

50 requests

15.5 kB transferred

5.6 MB resources

Finish: 12.43 s

Thanks for your help mate, I think Xdebug was the problem, at least the big one, the loading time passed from 25.15s to 12.43s (but in AWS (EB) it is half, around 6s), and this is a big improvement!!! Anyway possible there are more things I can do to improve the velocity, but this is a big change, thanks again.

Same issue , I run a mysql on docker , this feature is ok last few months. Yesterday I found my docker data is deleted and I update new docker desktop windows. Now when I run mysql on ssd disk , write sql performence is OK, but I move docker data to mechanical hard drive ļ¼Œ I write sql very slowly . A 2mb sql file import mysql will spend half-hour .I donā€™t know why.

I know about multiple confirmed and suspected issues related to Docker Desktop, which is unfortunate, I find it hard to believe that it would let you lose data. This is itself something that you could report in a separate topic or directly on GitHub:

BEfore you do that, make sure you have only one Docker instance, only Docker Desktop for Linux or only Docker CE, because some users thought they lost volumes but they just created a volume in an other Docker context. An other reason could be that you stored the data on a containerā€™s filesystem, not on a volume and when the container was recreated, it did not have the data.

Of course, losing data is not impossible so if you have important data it is recommended to create a backup before upgrading Docker Desktop. Even if you do that, I think this issue could get a higher priority then the fact that Docker Desktop is very slow for some people. Unless it is extremely slow for everyone, but I did not have that experience yet. Due to the virtualization and communication between the host and the VM it can be slow, but it should not be extremely slow. Although it depends on the exact case.

Can you share a demo application that does not contain any sensitive data but demonstrates how slow a query is so I can try it on my machine?

Try following How to make MySQL run fast with EXT4 on UBUNTU | PHP For Us see if it makes a difference. Iā€™ve been using docker to test my application and it takes 10-20 minutes to finish. But recently it takes an hour. After following this, my tests are fast again.

I sure hope Iā€™m reading this wrong. Are you saying you installed docker desktop on Linux?

I did so too, and have same problem with entire system getting very slow when docker is running.