title: MySQL docker container crashes
body: <p>I'm a newbie with Docker and I'm working on a Symfony2 software development project that uses docker with MySQL, nginx and the web app containers in it. I'm constantly being disconnected from MySQL with the following error message : </p>
  
  <blockquote>
    <p>DriverException in AbstractMySQLDriver.php line 115:
    An exception occured in driver: SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'db' (113)</p>
  </blockquote>
  
  <p>When running the command <code>docker logs -f project_name_db_1</code>, it returns the following :</p>
  
  <pre><code>$ docker logs -f project_name_db_1
  170616  8:08:52 [Note] --secure-file-priv is set to NULL. Operations 
  related to importing and exporting data are disabled
  170616  8:08:52 [Note] mysqld (mysqld 5.5.54) starting as process 1 
  ...
  170616  8:08:52 [Note] Plugin 'FEDERATED' is disabled.
  170616  8:08:52 InnoDB: The InnoDB memory heap is disabled
  170616  8:08:52 InnoDB: Mutexes and rw_locks use GCC atomic builtins
  170616  8:08:52 InnoDB: Compressed tables use zlib 1.2.3
  170616  8:08:52 InnoDB: Using Linux native AIO
  170616  8:08:52 InnoDB: Initializing buffer pool, size = 128.0M
  170616  8:08:52 InnoDB: Completed initialization of buffer pool
  170616  8:08:52 InnoDB: highest supported file format is Barracuda.
  InnoDB: Log scan progressed past the checkpoint lsn 85948426202
  170616  8:08:52  InnoDB: Database was not shut down normally!
  InnoDB: Starting crash recovery.
  InnoDB: Reading tablespace information from the .ibd files...
  InnoDB: Restoring possible half-written data pages from the 
  doublewrite
  InnoDB: buffer...
  InnoDB: Doing recovery: scanned up to log sequence number 85948426476
  170616  8:08:58  InnoDB: Starting an apply batch of log records to the 
  database...
  InnoDB: Progress in percents: 63 64 65 66 67 68 69 70 71 72 73 74 75 
  76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 
  99 
  InnoDB: Apply batch completed
  170616  8:08:59  InnoDB: Waiting for the background threads to start
  170616  8:09:00 InnoDB: 5.5.54 started; log sequence number 
  85948426476
  170616  8:09:00 [Note] Server hostname (bind-address): '0.0.0.0'; 
  port: 3306
  170616  8:09:00 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
  170616  8:09:00 [Note] Server socket created on IP: '0.0.0.0'.
  170616  8:09:01  InnoDB: Assertion failure in thread 139850856617728 
  in file trx0purge.c line 840
  InnoDB: Failing assertion: purge_sys-&gt;purge_trx_no &lt;= purge_sys-&gt;rseg-    
  last_trx_no
  InnoDB: We intentionally generate a memory trap.
  InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
  InnoDB: If you get repeated assertion failures or crashes, even
  InnoDB: immediately after the mysqld startup, there may be
  InnoDB: corruption in the InnoDB tablespace. Please refer to
  InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-
  recovery.html
  InnoDB: about forcing recovery.
  08:09:01 UTC - mysqld got signal 6 ;
  This could be because you hit a bug. It is also possible that this 
  binary
  or one of the libraries it was linked against is corrupt, improperly 
  built,
  or misconfigured. This error can also be caused by malfunctioning 
  hardware.
  We will try our best to scrape up some info that will hopefully help
  diagnose the problem, but since we have already crashed, 
  something is definitely wrong and this may fail.
  
  key_buffer_size=8388608
  read_buffer_size=131072
  max_used_connections=0
  max_threads=151
  thread_count=0
  connection_count=0
  It is possible that mysqld could use up to 
  key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 
  338512 K  bytes of memory
  Hope that's ok; if not, decrease some variables in the equation.
  
  Thread pointer: 0x0
  Attempting backtrace. You can use the following information to find 
  out
  where mysqld died. If you see no messages after this, something went
  terribly wrong...
  stack_bottom = 0 thread_stack 0x40000
  mysqld(my_print_stacktrace+0x35)[0x7aa245]
  mysqld(handle_fatal_signal+0x403)[0x677123]
  /lib/x86_64-linux-gnu/libpthread.so.0(+0xf890)[0x7f31a5807890]
  /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x37)[0x7f31a493c067]
  /lib/x86_64-linux-gnu/libc.so.6(abort+0x148)[0x7f31a493d448]
  mysqld[0x7f8d78]
  mysqld[0x7f90f1]
  mysqld[0x8c4986]
  mysqld[0x8b9edd]
  mysqld[0x7f79e5]
  mysqld[0x7edaa8]
  /lib/x86_64-linux-gnu/libpthread.so.0(+0x8064)[0x7f31a5800064]
  /lib/x86_64-linux-gnu/libc.so.6(clone+0x6d)[0x7f31a49ef62d]
  The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html 
  contains
  information that should help you find out what is causing the crash.
  170616  8:31:44 [Note] --secure-file-priv is set to NULL. Operations 
  related to importing and exporting data are disabled
  170616  8:31:44 [Note] mysqld (mysqld 5.5.54) starting as process 1 
  ...
  170616  8:31:44 [Note] Plugin 'FEDERATED' is disabled.
  170616  8:31:44 InnoDB: The InnoDB memory heap is disabled
  170616  8:31:44 InnoDB: Mutexes and rw_locks use GCC atomic builtins
  170616  8:31:44 InnoDB: Compressed tables use zlib 1.2.3
  170616  8:31:44 InnoDB: Using Linux native AIO
  170616  8:31:44 InnoDB: Initializing buffer pool, size = 128.0M
  170616  8:31:44 InnoDB: Completed initialization of buffer pool
  170616  8:31:44 InnoDB: highest supported file format is Barracuda.
  InnoDB: Log scan progressed past the checkpoint lsn 85943235752
  170616  8:31:44  InnoDB: Database was not shut down normally!
  InnoDB: Starting crash recovery.
  InnoDB: Reading tablespace information from the .ibd files...
  InnoDB: Restoring possible half-written data pages from the 
  doublewrite
  InnoDB: buffer...
  InnoDB: Doing recovery: scanned up to log sequence number 85943236009
  170616  8:31:45  InnoDB: Error: page 134825 log sequence number 
  85943236282
  InnoDB: is in the future! Current system log sequence number 
  85943236009.
  InnoDB: Your database may be corrupt or you may have copied the InnoDB
  InnoDB: tablespace but not the InnoDB log files. See
  InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-
  recovery.html
  InnoDB: for more information.
  170616  8:31:45  InnoDB: Error: page 117255 log sequence number 
  85943236539
  InnoDB: is in the future! Current system log sequence number 
  85943236009.
  InnoDB: Your database may be corrupt or you may have copied the InnoDB
  InnoDB: tablespace but not the InnoDB log files. See
  InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-
  recovery.html
  InnoDB: for more information.
  170616  8:31:45  InnoDB: Error: page 103222 log sequence number 
  85943236812
  InnoDB: is in the future! Current system log sequence number 
  85943236009.
  InnoDB: Your database may be corrupt or you may have copied the InnoDB
  InnoDB: tablespace but not the InnoDB log files. See
  InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-
  recovery.html
  InnoDB: for more information.
  170616  8:31:45  InnoDB: Error: page 129676 log sequence number 
  85943237069
  InnoDB: is in the future! Current system log sequence number 
  85943236009.
  InnoDB: Your database may be corrupt or you may have copied the InnoDB
  InnoDB: tablespace but not the InnoDB log files. See
  InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-
  recovery.html
  InnoDB: for more information.
  170616  8:31:45  InnoDB: Error: page 125568 log sequence number 
  85943237342
  InnoDB: is in the future! Current system log sequence number 
  85943236009.
  InnoDB: Your database may be corrupt or you may have copied the InnoDB
  InnoDB: tablespace but not the InnoDB log files. See
  InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-
  recovery.html
  InnoDB: for more information.
  170616  8:31:45  InnoDB: Error: page 126217 log sequence number 
  85943237599
  InnoDB: is in the future! Current system log sequence number 
  85943236009.
  InnoDB: Your database may be corrupt or you may have copied the InnoDB
  InnoDB: tablespace but not the InnoDB log files. See
  InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-
  recovery.html
  InnoDB: for more information.
  170616  8:31:45  InnoDB: Error: page 117266 log sequence number 
  85943237872
  InnoDB: is in the future! Current system log sequence number 
  85943236009.
  InnoDB: Your database may be corrupt or you may have copied the InnoDB
  InnoDB: tablespace but not the InnoDB log files. See
  InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-
  recovery.html
  InnoDB: for more information.
  170616  8:31:45  InnoDB: Error: page 129677 log sequence number 
  85943238139
  InnoDB: is in the future! Current system log sequence number 
  85943236009.
  InnoDB: Your database may be corrupt or you may have copied the InnoDB
  InnoDB: tablespace but not the InnoDB log files. See
  InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-
  recovery.html
  InnoDB: for more information.
  170616  8:31:45  InnoDB: Error: page 123341 log sequence number 
  85943238412
  InnoDB: is in the future! Current system log sequence number 
  85943236009.
  InnoDB: Your database may be corrupt or you may have copied the InnoDB
  InnoDB: tablespace but not the InnoDB log files. See
  InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-
  recovery.html
  InnoDB: for more information.
  170616  8:31:45  InnoDB: Error: page 134834 log sequence number 
  85943238685
  InnoDB: is in the future! Current system log sequence number 
  85943236009.
  InnoDB: Your database may be corrupt or you may have copied the InnoDB
  InnoDB: tablespace but not the InnoDB log files. See
  InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-
  recovery.html
  InnoDB: for more information.
  170616  8:31:45  InnoDB: Error: page 134835 log sequence number 
  85943238942
  InnoDB: is in the future! Current system log sequence number 
  85943236009.
  InnoDB: Your database may be corrupt or you may have copied the InnoDB
  InnoDB: tablespace but not the InnoDB log files. See
  InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-
  recovery.html
  InnoDB: for more information.
  170616  8:31:45  InnoDB: Error: page 129678 log sequence number 
  85943239215
  InnoDB: is in the future! Current system log sequence number 
  85943236009.
  InnoDB: Your database may be corrupt or you may have copied the InnoDB
  InnoDB: tablespace but not the InnoDB log files. See
  InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-
  recovery.html
  InnoDB: for more information.
  170616  8:31:45  InnoDB: Error: page 120136 log sequence number 
  85943239472
  InnoDB: is in the future! Current system log sequence number 
  85943236009.
  InnoDB: Your database may be corrupt or you may have copied the InnoDB
  InnoDB: tablespace but not the InnoDB log files. See
  InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-
  recovery.html
  InnoDB: for more information.
  170616  8:31:45  InnoDB: Error: page 126223 log sequence number 
  85943240002
  InnoDB: is in the future! Current system log sequence number 
  85943236009.
  InnoDB: Your database may be corrupt or you may have copied the InnoDB
  InnoDB: tablespace but not the InnoDB log files. See
  InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-
  recovery.html
  InnoDB: for more information.
  170616  8:31:46  InnoDB: Starting an apply batch of log records to the 
  database...
  InnoDB: Progress in percents: 170616  8:31:46  InnoDB: Error: page 
  132382 
  log sequence number 85943239891
  InnoDB: is in the future! Current system log sequence number 
  85943236009.
  InnoDB: Your database may be corrupt or you may have copied the InnoDB
  InnoDB: tablespace but not the InnoDB log files. See
  InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-
  recovery.html
  InnoDB: for more information.
  63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 
  86 87 
  88 89 90 91 92 93 94 95 96 97 98 99 
  InnoDB: Apply batch completed
  170616  8:31:46  InnoDB: Waiting for the background threads to start
  170616  8:31:47 InnoDB: 5.5.54 started; log sequence number 
  85943236009
  170616  8:31:47 [Note] Server hostname (bind-address): '0.0.0.0'; 
  port: 
  3306
  170616  8:31:47 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
  170616  8:31:47 [Note] Server socket created on IP: '0.0.0.0'.
  170616  8:31:47 [Warning] 'proxies_priv' entry '@ root@8c2b747d6905' 
  ignored in --skip-name-resolve mode.
  170616  8:31:48 [Note] Event Scheduler: Loaded 0 events
  170616  8:31:48 [Note] mysqld: ready for connections.
  Version: '5.5.54'  socket: '/tmp/mysql.sock'  port: 3306  MySQL 
  Community 
  Server (GPL)
  170616  8:43:03  InnoDB: Assertion failure in thread 140615160387328 
  in 
  file trx0purge.c line 840
  InnoDB: Failing assertion: purge_sys-&gt;purge_trx_no &lt;= purge_sys-&gt;rseg-
  &gt;last_trx_no
  InnoDB: We intentionally generate a memory trap.
  InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
  InnoDB: If you get repeated assertion failures or crashes, even
  InnoDB: immediately after the mysqld startup, there may be
  InnoDB: corruption in the InnoDB tablespace. Please refer to
  InnoDB: http://dev.mysql.com/doc/refman/5.5/en/forcing-innodb-
  recovery.html
  InnoDB: about forcing recovery.
  08:43:03 UTC - mysqld got signal 6 ;
  This could be because you hit a bug. It is also possible that this 
  binary
  or one of the libraries it was linked against is corrupt, improperly 
  built,
  or misconfigured. This error can also be caused by malfunctioning 
  hardware.
  We will try our best to scrape up some info that will hopefully help
  diagnose the problem, but since we have already crashed, 
  something is definitely wrong and this may fail.
  
  key_buffer_size=8388608
  read_buffer_size=131072
  max_used_connections=5
  max_threads=151
  thread_count=2
  connection_count=2
  It is possible that mysqld could use up to 
  key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 
  338512 K  bytes of memory
  Hope that's ok; if not, decrease some variables in the equation.
  
  Thread pointer: 0x0
  Attempting backtrace. You can use the following information to find 
  out
  where mysqld died. If you see no messages after this, something went
  terribly wrong...
  stack_bottom = 0 thread_stack 0x40000
  mysqld(my_print_stacktrace+0x35)[0x7aa245]
  mysqld(handle_fatal_signal+0x403)[0x677123]
  /lib/x86_64-linux-gnu/libpthread.so.0(+0xf890)[0x7fe3998dc890]
  /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x37)[0x7fe398a11067]
  /lib/x86_64-linux-gnu/libc.so.6(abort+0x148)[0x7fe398a12448]
  mysqld[0x7f8d78]
  mysqld[0x7f90f1]
  mysqld[0x8c4986]
  mysqld[0x8b9edd]
  mysqld[0x7f79e5]
  mysqld[0x7ece0e]
  /lib/x86_64-linux-gnu/libpthread.so.0(+0x8064)[0x7fe3998d5064]
  /lib/x86_64-linux-gnu/libc.so.6(clone+0x6d)[0x7fe398ac462d]
  The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html 
  contains
  information that should help you find out what is causing the crash.
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>The content of my dockerfile is:</p>
  
  <pre><code>FROM debian:8
  
  # Install Requirements
  RUN apt-get update -qq &amp;&amp; apt-get install -qqy \
      sudo \
      wget \
      curl \
      git \
      apt-utils \
      netcat-openbsd \
      acl \
      &amp;&amp; echo "Europe/Paris" &gt; /etc/timezone &amp;&amp; dpkg-reconfigure -f 
  noninteractive tzdata \
      &amp;&amp; echo 'alias ll="ls -lah --color=auto"' &gt;&gt; /etc/bash.bashrc
  
  # Variables Apache
  ENV APACHE_RUN_USER  www-data
  ENV APACHE_RUN_GROUP www-data
  ENV APACHE_PID_FILE  /var/run/apache2.pid
  ENV APACHE_RUN_DIR   /var/run/apache2
  ENV APACHE_LOCK_DIR  /var/lock/apache2
  ENV APACHE_LOG_DIR   /var/log/apache2
  ENV APACHE_USER_UID 0
  
  ENV HOME /root
  
  RUN echo "deb http://packages.dotdeb.org jessie all" &gt;&gt; 
  /etc/apt/sources.list
  RUN echo "deb-src http://packages.dotdeb.org jessie all" &gt;&gt; 
  /etc/apt/sources.list
  RUN wget http://www.dotdeb.org/dotdeb.gpg
  RUN cat dotdeb.gpg | apt-key add -
  
  # Java, PHP &amp;&amp; Apache
  RUN apt-get update -qq &amp;&amp; apt-get install -qqy --force-yes \
     default-jre \
     php5 \
     php-apc \
     php5-cli \
     php5-xdebug \
     php5-intl \
     php5-mcrypt \
     php5-mysql \
     php5-curl \
     php5-gd \
     apache2 \
     #apache2-mpm-worker \
     apache2-utils \
     libapache2-mod-php5 \
     mysql-client
  
  # Config Apache
  ADD conf/apache/vhost.conf /etc/apache2/sites-available/web.conf
  RUN a2enmod rewrite \
      &amp;&amp; rm -f /etc/apache2/sites-enabled/default \
      &amp;&amp; rm -f /etc/apache2/sites-enabled/000-default.conf \
      &amp;&amp; rm -f /etc/apache2/sites-available/default \
      &amp;&amp; rm -f /etc/apache2/sites-enabled/default-ssl \
      &amp;&amp; rm -f /etc/apache2/sites-available/default-ssl \
      &amp;&amp; rm -rf /var/www/html \
      &amp;&amp; a2ensite web.conf
  
  # Config PHP
  ADD conf/php5/apc.ini /etc/php5/mods-available/apc.ini
  ADD conf/php5/php.ini /etc/php5/apache2/php.ini
  ADD conf/php5/php.ini /etc/php5/cli/php.ini
  
  # Logs
  RUN mkdir -p /var/log/apache2 \
      &amp;&amp; chown -R www-data:www-data /var/log/apache2
  
  # Alias
  RUN echo "alias sf='php app/console'" &gt;&gt; /root/.bashrc
  RUN echo "alias sfprod='php app/console --env=prod'" &gt;&gt; /root/.bashrc
  
  # Sources
  WORKDIR /var/www
  
  EXPOSE 80
  
  VOLUME ["/var/log/apache2", "/var/www"]
  
  ADD script/start.sh /root/start.sh
  RUN chmod +x /root/start.sh
  
  CMD []
  </code></pre>
  
  <p>My docker-compose-dev.yml looks like this:</p>
  
  <pre><code>web:
  extends:
      file: docker-compose-common.yml
      service: web
  links:
      - db
      - search
      - mailcatcher
  environment:
      SYMFONY__CRYPT__KEY:
      SYMFONY__MYAPP__PREFIX: /app_dev.php
      VIRTUAL_HOST: project.dev.domain.fr
  
  db:
      extends:
          file: docker-compose-common.yml
          service: db
      environment:
          VIRTUAL_HOST: db.project.dev.domain.fr
      ports:
          - "3310:3306"
  
  composer:
      extends:
          file: .namedev/name-common/compose/common.yml
          service: composer
  
  search:
      extends:
              file: docker-compose-common.yml
              service: search
      volumes:
          - "./elasticsearch/data:/usr/share/elasticsearch/data"
      environment:
          VIRTUAL_HOST: elk.project.dev.domain.fr
          VIRTUAL_PORT: 9200
  
  mailcatcher:
      image: web/docker-mailcatcher
      environment:
          VIRTUAL_HOST: mailcatcher.dev.domain.fr
          VIRTUAL_PORT: 1080
  </code></pre>
  
  <p>I have another file called docker-compose-common.yml containing this (for the database part):</p>
  
  <pre><code>web:
      build: docker
      working_dir: /var/www
      hostname: kgestion
      domainname: kgestion.dev.zol.fr
      command: /root/start.sh
      volumes:
          - ".:/var/www"
          - "./var/logs/web:/var/log/apache2"
      environment:
          CERT_NAME: project
          VIRTUAL_HOST: project.dev.domain.fr,something.dev.domain.fr
  
          SYMFONY__DATABASE__HOST: db
          SYMFONY__DATABASE__PORT: 3306
          SYMFONY__DATABASE__NAME: project
          SYMFONY__DATABASE__USER: root
          SYMFONY__DATABASE__PASSWORD: project
  
  
  
  db:
      image: mysql:5.5
      environment:
          MYSQL_ROOT_PASSWORD: project
      volumes:
          - "./data:/var/lib/mysql"
  
  search:
      build: docker/elasticsearch
  </code></pre>