docker articles---restart strategy + run container common parameters

docker restart strategy + run container common parameters


restart strategy

container runctime is responsible for the life cycle management of the container

OCI : (open container initiative) open source container protocol,

Contains two specifications: run specification (runctime spec) - container status, creation, deletion, view definition

image-spec - how to create an OCI runtime system package

CRI (container run interface) container running interface

It separates the differences between various container engines, and introduces the pod concept of k8s through a unified interface as the underlying runtime.

no : When the docker service is restarted, the container will not be started. This is the default policy.

docker container run -itd --restart no alpine:latest
     
systemctl restart docker

always : When the docker service is restarted, the container will start accordingly.

docker container run -itd --restart  always  alpine:latest

unless-stopped : Always restart the container when the container exits, but does not consider containers that have been stopped when the Docker daemon starts

docker container run -itd --restart unless-stopped alpine:latest

on-failture [:max-retries]: Unexpected exit status will restart the service. You can specify the number of restarts for abnormal exits.

docker container run -itd --restart on-failture:2 alpine:latest

privileged container

Sometimes, the application needs to modify the kernel parameters, but the container does not support modifying the kernel parameters by default. If there is such a need, you need to use a privileged container.

docker container run -itd --privileged alpine:latest

Note: Modifying the kernel parameters of the privileged container can change the kernel parameters of the host machine accordingly, so use it with caution in the production environment.

custom container name

docker container run -itd --name  firstcon  alpine:latest

When creating, no container name is specified, and it can also be modified with docker container rename

Deleted when the container exits

docker container run -itd --name  firstcon --rm alpine:latest

Note: often used for testing

Custom container hostname

docker container run -itdh   firstcon  alpine:latest
     
docker container exec -it   nginx:latest  sh
     
#hostname

Common parameters

docker run -it nginx:latest /bin/bash
 
root@b8573233d675:/# 
 
#说明:
 
docker run:启动一个容器。
 
-it:以交互模式启动(进入容器中),通常跟解释器一起用
 
nginx:latest:镜像来源:nginx:latest
 
/bin/bash:进入容器后要执行的命令,这里是打开终端。
 
root@b8573233d675:/# :  已经进入了容器里面的终端,用户名变化。
 
 
注意:d 是后台运行,进入容器里面变化的终端是前台运行,
#https://blog.csdn.net/weixin_61015632/article/details/124819196

Guess you like

Origin blog.csdn.net/m0_46825740/article/details/131474798