- Yes, it is possible only while using certain docker-defined policies while using the docker run command. Following are the available policies:
1. Off: In this, the container won’t be restarted in case it’s stopped or it fails.
2. On-failure: Here, the container restarts by itself only when it experiences failures not associated with the user.
3. Unless-stopped: Using this policy, ensures that a container can restart only when the command is executed to stop it by the user.
4. Always: Irrespective of the failure or stopping, the container always gets restarted in this type of policy.
These policies can be used as:
docker run -dit — restart [restart-policy-value] [container_name]