title: Mysql in Docker container never releases memory and regularly crashes cause out of memory
body: <p>Host with 32GB RAM. Mysql 5.7.21 works in Docker container, runs with the following command:<br>
  <code>docker run --restart=always --name mydb5721 -v ... -e MYSQL_ROOT_PASSWORD=... -e MYSQL_USER=... -e MYSQL_PASSWORD=... -p ...:3306 --memory 14G --memory-swap 14G --health-interval=10s --health-timeout=10s --health-retries=3 --health-cmd='/bin/bash /var/lib/mysql/healthcheck.sh' mysql:5.7.21 --verbose &amp;</code><br>
  so without swap and with 14GB RAM.<br>
  Memory usage almost always grows and is never cleared, even after my large requests are completed. And it crashes when exceeds limit 14GB. "Flush query cache" never changes this graph, "flush tables" usually not greatly affected and then grows fast again. When the db-requests are large and heavy, the limit is reached quickly, otherwise - slowly.<br>
  <a href="https://i.stack.imgur.com/QSvZ1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QSvZ1.png" alt="enter image description here"></a>
  /etc/mysql/mysql.conf.d:</p>
  
  <pre><code>[mysqld]
  innodb_force_recovery = 6
  user=root
  max_allowed_packet=1500M
  bind-address=0.0.0.0
  key_buffer_size=1024M
  max_connections=200
  table_open_cache=64
  query_cache_limit=4M
  query_cache_size=512M
  innodb_buffer_pool_size=7G
  server-id=2
  log-slave-updates=1
  
  innodb_log_buffer_size          = 16M
  innodb_log_file_size            = 250M
  
  pid-file        = /var/run/mysqld/mysqld.pid
  socket          = /var/run/mysqld/mysqld.sock
  datadir         = /var/lib/mysql
  log-error      = /var/log/mysql/error.log
  symbolic-links=0
  skip-host-cache
  skip-name-resolve
  
  sql-mode="NO_AUTO_VALUE_ON_ZERO"
  
  innodb_file_per_table = 1
  table_open_cache = 2048
  innodb_open_files = 2048
  sort_buffer_size = 128M
  read_buffer_size = 128M
  read_rnd_buffer_size = 1M
  thread_stack = 128M
  query_cache_type = 0
  thread_cache_size = 32
  max_heap_table_size = 256M
  tmp_table_size = 1G
  innodb_buffer_pool_instances = 4
  innodb_read_io_threads = 8
  innodb_write_io_threads = 8
  
  performance_schema = 0
  innodb_flush_log_at_trx_commit = 2
  
  slow_query_log=1
  long_query_time=40
  slow-query-log-file=/var/log/mysql/slow_queries.log
  general_log=0
  
  innodb_flush_method=O_DIRECT
  innodb_tmpdir=/tmp
  
  secure-file-priv = ""
  </code></pre>
  
  <p>My main questions:<br>
  - is the Docker guilty or Mysql (cause I never have this problem with mysql without docker)?<br>
  - why memory never releases even after my queries are completed?<br>
  - will the solution migration to MariaDB?</p>