HiveBrain v1.2.0
Get Started
← Back to all entries
patterndockerMinor

Can I keep a container started with --rm option?

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
canstartedcontainerwithkeepoption

Problem

I started my docker container with --rm and -it options. I need to keep that container now because it has some important data. Can I cancel the --rm switch using the docker update command?

This answer from SO says it is possible, but I it doesn't say how exactly!

Solution

No, docker will delete the container when it stops, and there's no update option to change that behavior. You can see this in the help output:

$ docker container update --help

Usage:  docker container update [OPTIONS] CONTAINER [CONTAINER...]

Update configuration of one or more containers

Options:
      --blkio-weight uint16        Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
      --cpu-period int             Limit CPU CFS (Completely Fair Scheduler) period
      --cpu-quota int              Limit CPU CFS (Completely Fair Scheduler) quota
      --cpu-rt-period int          Limit the CPU real-time period in microseconds
      --cpu-rt-runtime int         Limit the CPU real-time runtime in microseconds
  -c, --cpu-shares int             CPU shares (relative weight)
      --cpus decimal               Number of CPUs
      --cpuset-cpus string         CPUs in which to allow execution (0-3, 0,1)
      --cpuset-mems string         MEMs in which to allow execution (0-3, 0,1)
      --kernel-memory bytes        Kernel memory limit
  -m, --memory bytes               Memory limit
      --memory-reservation bytes   Memory soft limit
      --memory-swap bytes          Swap limit equal to memory plus swap: '-1' to enable unlimited swap
      --pids-limit int             Tune container pids limit (set -1 for unlimited)
      --restart string             Restart policy to apply when a container exits


Trying to change the restart policy will result in an error:

$ docker run --rm --name test-rm -d busybox tail -f /dev/null                                                                                                                                                                                 
14a7d9bfebc3356652e3c3f060e92d9cebb9f3eb4490873540c9eb1c272f6612

$ docker update --restart=unless-stopped test-rm
Error response from daemon: Cannot update container 14a7d9bfebc3356652e3c3f060e92d9cebb9f3eb4490873540c9eb1c272f6612: Restart policy cannot be updated because AutoRemove is enabled for the container


You can try to copy your data out of the container with:

docker container cp $container_name:/path/in/container /path/on/host


If you don't know which files to save, list which files have changed in the container with:

docker container diff $container_name

Code Snippets

$ docker container update --help

Usage:  docker container update [OPTIONS] CONTAINER [CONTAINER...]

Update configuration of one or more containers

Options:
      --blkio-weight uint16        Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
      --cpu-period int             Limit CPU CFS (Completely Fair Scheduler) period
      --cpu-quota int              Limit CPU CFS (Completely Fair Scheduler) quota
      --cpu-rt-period int          Limit the CPU real-time period in microseconds
      --cpu-rt-runtime int         Limit the CPU real-time runtime in microseconds
  -c, --cpu-shares int             CPU shares (relative weight)
      --cpus decimal               Number of CPUs
      --cpuset-cpus string         CPUs in which to allow execution (0-3, 0,1)
      --cpuset-mems string         MEMs in which to allow execution (0-3, 0,1)
      --kernel-memory bytes        Kernel memory limit
  -m, --memory bytes               Memory limit
      --memory-reservation bytes   Memory soft limit
      --memory-swap bytes          Swap limit equal to memory plus swap: '-1' to enable unlimited swap
      --pids-limit int             Tune container pids limit (set -1 for unlimited)
      --restart string             Restart policy to apply when a container exits
$ docker run --rm --name test-rm -d busybox tail -f /dev/null                                                                                                                                                                                 
14a7d9bfebc3356652e3c3f060e92d9cebb9f3eb4490873540c9eb1c272f6612

$ docker update --restart=unless-stopped test-rm
Error response from daemon: Cannot update container 14a7d9bfebc3356652e3c3f060e92d9cebb9f3eb4490873540c9eb1c272f6612: Restart policy cannot be updated because AutoRemove is enabled for the container
docker container cp $container_name:/path/in/container /path/on/host
docker container diff $container_name

Context

StackExchange DevOps Q#7956, answer score: 3

Revisions (0)

No revisions yet.