1

I am trying to change the value of somaxconn in a running docker container. I am using this command:

docker run --net=container:redis --sysctl net.core.somaxconn=65535 bash

I have checked that this command changes the value of somaxconn from 128 to 65535 in the running docker container.

Because docker run command creates and starts a new container, so, does this command recreates and starts my existing conatiner? Does it restart my running container with the somaxconn changes or does it change the value in the running docker docker container?

But one thing I would like to add is that after running the above command, the value of somaxconn was changed and when I did docker ps, it showed that the same container was up and running from long time ago, so, does that mean it changed the value in an already running container?

2 Answers2

2

docker run will always start a new container. If you already have a container running, it will not be affected by the docker run command.

You could look at the docker exec command. This allows you to execute a command in an existing container. However, this will not allow you to change the parameters with which the original container was started (e.g. changing the --sysctl param). To change these kind of parameters you must remove and recreate the container with the desired parameters.

See the docs for docker run and docker exec here: https://docs.docker.com/engine/reference/commandline/run/ https://docs.docker.com/engine/reference/commandline/exec/

olambert
  • 1,075
  • 2
  • 7
  • 10
  • But after I had run this command 'docker run --net=container:redis --sysctl net.core.somaxconn=65535 bash' and I checked, the value for somaxconn had changed and after running docker ps, it was showing the docker container up and running from hours before, so, It wasn't restarted. So, how did the value of somaxconn change? – Arpan Gupta Apr 12 '18 at 09:29
1

docker run command will always create a new container.

So you can do one thing. Execute following commands to change value in running container.

#>docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED                 STATUS              PORTS                     NAMES
80eb3dc8438b        abcxyz               "docker-entrypoint.sâ¦"   22 hours     ago      Up 22 hours                     abcxyzfriendlyname

Look for container-name or id (e.g. 80eb3dc8438b) Then launch the following command : (Make sure your container is running at this moment).

#>docker exec 80eb3dc8438b   sysctl net.core.somaxconn=65535

I am not sure whether it will persist data in the container or is it just available in session only.

fly2matrix
  • 2,351
  • 12
  • 13
  • As I have said in the below reply, I saw the state of docker container using docker ps, and I saw that the docker was running for many hours, since last I had restarted it, so, run command didn't restart my running container but it did update the value of somaxconn. Can you explain how did it do that? – Arpan Gupta Apr 12 '18 at 11:41
  • docker exec is to execute any command in the running container. If you want to see what's there inside the container - you can login using #> docker exec -it sh :: You will get a shell inside the container and then simply check for the configurations that you want to. – fly2matrix Apr 12 '18 at 12:42