29

I am trying to set a few sysctl values.
Basically the following

sysctl -w \
   net.ipv4.tcp_keepalive_time=300 \
   net.ipv4.tcp_keepalive_intvl=60 \
   net.ipv4.tcp_keepalive_probes=9

in a docker container.
When log into to the container directly and execute the command, I get the following error

sysctl: cannot stat /proc/sys/net/ipv4/tcp_keepalive_time: No such file or directory
sysctl: cannot stat /proc/sys/net/ipv4/tcp_keepalive_intvl: No such file or directory
sysctl: cannot stat /proc/sys/net/ipv4/tcp_keepalive_probes: No such file or directory

Then I found out the --sysctl option in docker run in here But I did not find the equivalent option via docker-compose. I have few services that start by default so using docker run instead of docker-compose is not an option for me.

Anyone knows of a way to supply --sysctl options to the container via compose?

Keshava
  • 702
  • 1
  • 7
  • 20

2 Answers2

52

This option is now available in docker-compose 1.10.0-rc1, you'll need to upgrade to that version (pip install docker-compose==1.10.0-rc1) and also update your docker-compose.yml file to version 2.1 per docs

Example docker-compose.yml:

version: '2.1'
services:
    app:
        build: .
        sysctls:
            - net.ipv6.conf.all.disable_ipv6=1
d3ming
  • 8,496
  • 5
  • 31
  • 33
  • This is great, but it doesn't seem possible to specify it for builds... I need it at build time to disable IPv6, otherwise building images based on old Debian versions takes forever. :( – imiric Apr 15 '21 at 10:06
  • If you build the container you must disable it on the building host. – os_1 Sep 01 '23 at 11:19
1

docker-compose lacks many of the CLI options. In general, you have to head over to the github issues for compose and search there. In the case of sysctl, it's in the process of being added. Someone has made a branch with the addition. You could start with that until it gets added to the master branch.

Bernard
  • 16,149
  • 12
  • 63
  • 66