title: Increasing mysql max_connections to 1024 in a docker container
body: <p>I want to increase <code>max_connections</code> to 1024 in a docker container of <a href="https://hub.docker.com/_/mysql" rel="nofollow noreferrer">mysql 5.6</a> hosted on <a href="https://aws.amazon.com/tw/ec2/" rel="nofollow noreferrer">AWS EC2</a>. The instance type of the EC2 is <code>m4.large</code>.</p>
  
  <p>I've set max_connections to 1024 by adding <code>max_connections=1024</code> in <code>my.cnf</code>, but I only saw 214 when typing <code>show varialbes like 'max_connections';</code> mysql command. Here is the <code>my.cnf</code> I have.:</p>
  
  <p><em>my.cnf</em></p>
  
  <pre><code>[client]
  port            = 3306
  socket          = /var/run/mysqld/mysqld.sock
  
  [mysqld_safe]
  pid-file        = /var/run/mysqld/mysqld.pid
  socket          = /var/run/mysqld/mysqld.sock
  nice            = 0
  
  [mysqld]
  skip-host-cache
  skip-name-resolve
  user            = mysql
  pid-file        = /var/run/mysqld/mysqld.pid
  socket          = /var/run/mysqld/mysqld.sock
  port            = 3306
  basedir         = /usr
  datadir         = /var/lib/mysql
  tmpdir          = /tmp
  lc-messages-dir = /usr/share/mysql
  explicit_defaults_for_timestamp
  
  max_connections=1024
  max_connect_errors=100000
  
  # Instead of skip-networking the default is now to listen only on
  # localhost which is more compatible and is not less secure.
  #bind-address   = 127.0.0.1
  
  #log-error      = /var/log/mysql/error.log
  
  # Recommended in standard MySQL setup
  sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES                                                                                                                                                                       
  
  # Disabling symbolic-links is recommended to prevent assorted security risks
  symbolic-links=0
  
  # * IMPORTANT: Additional settings that can override those from this file!
  #   The files must end with '.cnf', otherwise they'll be ignored.
  #
  !includedir /etc/mysql/conf.d/
  </code></pre>
  
  <p>I've tried the solution mentioned in <a href="https://codepoets.co.uk/2015/mysql-max_connections-stuck-on-214/" rel="nofollow noreferrer">MySQL Max_connections stuck on 214 ?</a>. But this one doesn't work in my case. The following are my settings:</p>
  
  <p><em>common-session</em></p>
  
  <pre><code># here are the per-package modules (the "Primary" block)
  session [default=1]         pam_permit.so
  # here's the fallback if no module succeeds
  session requisite           pam_deny.so
  # prime the stack with a positive return value if there isn't one already;
  # this avoids us returning an error just because nothing sets a success code
  # since the modules above will each just jump around
  session required            pam_permit.so
  # and here are more per-package modules (the "Additional" block)
  session required    pam_unix.so 
  
  session required    pam_limits.so
  # end of pam-auth-update config
  </code></pre>
  
  <p><em>limits.conf</em></p>
  
  <pre><code>#&lt;domain&gt;      &lt;type&gt;  &lt;item&gt;         &lt;value&gt;
  * soft  nofile 65536
  * hard  nofile 65536
  * soft  nproc  100000
  * hard  nproc  127466
  </code></pre>
  
  <p>I've also tried the solution <a href="https://stackoverflow.com/questions/30901041/can-not-increase-max-open-files-for-mysql-max-connections-in-ubuntu-15">here</a>.</p>
  
  <p><em>mysql.service</em></p>
  
  <pre><code>[Unit]
  Description=MySQL Community Server
  After=network.target
  
  [Install]
  WantedBy=multi-user.target
  
  [Service]
  User=mysql
  Group=mysql
  PermissionsStartOnly=true
  ExecStartPre=/usr/share/mysql/mysql-systemd-start pre
  ExecStart=/usr/bin/mysqld_safe
  ExecStartPost=/usr/share/mysql/mysql-systemd-start post
  TimeoutSec=600
  Restart=on-failure
  
  LimitNOFILE=infinity
  LimitMEMLOCK=infinity
  </code></pre>
  
  <p>This solution doesn't work for me either.</p>
  
  <p>I pass the above files from the host machine into the docker container by using <code>mountPoints</code> and <code>volumes</code> in task definition of ECS.</p>
  
  <p>Here are the mountPoints and volumes of my ECS task definition:</p>
  
  <pre><code>"mountPoints": [
  {
    "containerPath": "/docker-entrypoint-initdb.d/user.sql",
    "sourceVolume": "user",
    "readOnly": true
  },
  {
    "containerPath": "/etc/mysql/my.cnf",
    "sourceVolume": "mysql_config",
    "readOnly": false
  },
  {
    "containerPath": "/etc/security/limits.conf",
    "sourceVolume": "limits_conf",
    "readOnly": null
  },
  {
    "containerPath": "/etc/systemd/system/mysql.service",
    "sourceVolume": "mysql_service",
    "readOnly": null
  },
  {
    "containerPath": "/etc/pam.d/common-session",
    "sourceVolume": "common_session",
    "readOnly": null
  }
  ],
  
  "volumes": [
  {
    "host": {
      "sourcePath": "/home/docker/mysql/user.sql"
    },
    "name": "user"
  },
  {
    "host": {
      "sourcePath": "/home/docker/mysql/my.cnf"
    },
    "name": "mysql_config"
  },
  {
    "host": {
      "sourcePath": "/home/docker/mysql/limits.conf"
    },
    "name": "limits_conf"
  },
  {
    "host": {
      "sourcePath": "/home/docker/mysql/mysql.service"
    },
    "name": "mysql_service"
  },
  {
    "host": {
      "sourcePath": "/home/docker/mysql/common-session"
    },
    "name": "common_session"
  }
  ],
  </code></pre>
  
  <p>What else can I do so that <code>max_connections</code> can reach 1024?</p>
  
  <p>If you need to know more information of my docker container, just let me know.</p>