What is the difference between Docker Service and Docker Container?

前端 未结 5 2038
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-23 19:04

When do we use a docker service create command and when do we use a docker run command?

5条回答
  •  旧巷少年郎
    2020-12-23 19:11

    In short: Docker service is used mostly when you configured the master node with Docker swarm so that docker containers will run in a distributed environment and it can be easily managed.

    Docker run: The docker run command first creates a writeable container layer over the specified image, and then starts it using the specified command.

    That is, docker run is equivalent to the API /containers/create then /containers/(id)/start

    source: https://docs.docker.com/engine/reference/commandline/run/#parent-command

    Docker service: Docker service will be the image for a microservice within the context of some larger application. Examples of services might include an HTTP server, a database, or any other type of executable program that you wish to run in a distributed environment.

    When you create a service, you specify which container image to use and which commands to execute inside running containers. You also define options for the service including:

    • the port where the swarm will make the service available outside the swarm
    • an overlay network for the service to connect to other services in the swarm
    • CPU and memory limits and reservations
    • a rolling update policy
    • the number of replicas of the image to run in the swarm

    source: https://docs.docker.com/engine/swarm/how-swarm-mode-works/services/#services-tasks-and-containers

提交回复
热议问题