2. docker 進階

 

 

 

 


 

 

 

 

 


Runtime metrics

 

docker stats

 

 


Restart policies (--restart)

 

# When a restart policy is active on a container,
# it will be shown as either Up or Restarting in

docker ps

 

Policy

no

Do not automatically restart the container when it exits. This is the default.

on-failure[:max-retries]    

Restart only if the container exits with a non-zero exit status.

unless-stopped    

Always restart the container regardless of the exit status, including on daemon startup,
except if the container was put into a stopped state before the Docker daemon was stopped.

#  to get the number of restarts for container “my-container”

docker inspect -f "{{ .RestartCount }}" my-container

# to get the last time the container was (re)started

docker inspect -f "{{ .State.StartedAt }}" my-container

 


live restore

 

Docker Engine Version > 1.12

By default, when the Docker daemon terminates, it shuts down running containers.

Keep containers alive during daemon downtime setting

/etc/docker/daemon.json

{
  "live-restore": true
}

systemctl reload docker