I start a container from a docker image using docker run
command + many arguments, like:
docker run -d --name=ubu2 --restart=always --pids-limit 400 --memory=3g --memory-swap=6g --cpus="2.0" -p 127.0.0.1:8585:8585 -v /apps:/apps ubuImage
when I execute
docker inspect ubu2
I can correctly see my settings in the description of the container.
When I restart the container using simply docker restart ubu2
, I can still see my settings. Is this the expected behaviour? Shouldn't the container start fresh, without the settings from the run command arguments?
In general what is the best way to keep such kind of settings in the definition of the container?
More - if I want to change the value of any of them, let's say memory to 4GB - what is the appropriate way to do this? docker container update
?
A Docker container wraps a single process.
docker restart
restarts the process, without recreating the container environment; that's why the container settings are preserved across a container restart.In general I don't usually bother stopping and starting containers; just delete and recreate them. Then you're sure of starting from a clean environment.
If you have a consistent set of
docker run
options you use, you can put them in a shell script (like any other shell command), or use a tool like Docker Compose that encapsulates a set of container options in a file. The command you show could be written in Compose syntax like:If you run
docker-compose up -d
, it will create a container (in the background) matching this template. If you change one of these values, and rundocker-compose up -d
again, it will delete and recreate containers as required to have the updated settings.