Some images tell you to tweak a kernel setting, and my first reflex is to edit /etc/sysctl.conf on the host. That changes it for everything. For a few settings Docker can scope it to one container instead.
docker run --rm --sysctl net.ipv4.ip_forward=1 alpine cat /proc/sys/net/ipv4/ip_forward
The --sysctl flag takes key=value and can be repeated. In a Compose file it’s a sysctls entry on the service, which the Compose reference allows either as a list of key=value strings or as a map. Typical uses are network settings such as net.ipv4.ip_forward for a container that routes traffic, or net.ipv4.ping_group_range for ping without root.
The caveat is that only namespaced sysctls are allowed. That means the net.* family and a few IPC ones like some kernel.sem and kernel.shm* entries. Settings that are global to the host, like vm.swappiness, are refused, and those still need to be set on the host. The flag also can’t be combined with --network=host or --ipc=host, because then the container would share the host’s namespace and would be changing the host’s value.
This example was not run against a live Docker daemon. It follows the Docker documentation, so no output is shown; check it on your own host first.
Further reading: docker run, runtime constraints and sysctl