Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker container increase listen queue size beyond 128

How can I increase the listen queue size beyond 128 on a docker image with a read only file system?

When I run my container I get the following error:

uWSGI: - Listen queue size is greater than the system max net.core.somaxconn (128).

I have a Dockerfile with base image python:2.7. I am trying to increase system level limit on Unix socket and TCP connection listen queue so that uwsgi can set a listen queue limit of 1024, as described at uwsgi: your server socket listen backlog is limited to 100 connections.

I tried adding these RUN commands to the Dockerfile:

  • echo 4096 > /proc/sys/net/core/somaxconn
  • sysctl -w net.core.somaxconn=4096

But these both fail with the following errors respectively:

  • /bin/sh: 1: cannot create /proc/sys/net/core/somaxconn: Read-only file system
  • sysctl: setting key "net.core.somaxconn": Read-only file system

I also tried mounting a file to overwrite the /proc/sys/net/core/somaxconn and that failed with the error cannot be mounted because it is located inside "/proc"

I also tried running sudo sysctl -w net.core.somaxconn=4096 net.core.somaxconn = 4096 on the host before running, but it isn't reflected in the docker container; uwsgi still fails with the error uWSGI: - Listen queue size is greater than the system max net.core.somaxconn (128) and running cat /proc/sys/net/core/somaxconn shows 128 in the container while showing 4096 on the host.

like image 504
JDiMatteo Avatar asked Apr 05 '17 23:04

JDiMatteo


2 Answers

You either need to run Docker in privileged mode than you can modify the /proc file system after the container was started or you upgrade to a newer Docker release. run subcommand has the --sysctl option, which allows to make the change you envision:

$ docker run -ti --sysctl net.core.somaxconn=4096 --rm ubuntu /bin/bash root@9e850908ddb7:/# sysctl net.core.somaxconn net.core.somaxconn = 4096

like image 88
ovanes Avatar answered Oct 26 '22 18:10

ovanes


If you prefer using docker-compose. Here's the configuration that you want to adjust:

sysctls:
  net.core.somaxconn: 1024

Or

sysctls:
  - net.core.somaxconn=1024

Reference: https://github.com/compose-spec/compose-spec/blob/master/spec.md#sysctls

like image 34
kakilangit Avatar answered Oct 26 '22 18:10

kakilangit