Docker 服务和 Docker 容器有什么区别? [英] What is the difference between Docker Service and Docker Container?

查看:61
本文介绍了Docker 服务和 Docker 容器有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么时候使用 docker service create 命令,什么时候使用 docker run 命令?

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

推荐答案

简而言之: Docker 服务主要用于在您使用 Docker swarm 配置主节点以便 docker 容器运行时在分布式环境中并且易于管理.

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: docker run 命令首先在指定的镜像上创建一个可写的容器层,然后使用指定的命令启动它.

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

即docker run相当于API/containers/create then/containers/(id)/start

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

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

Docker 服务:Docker 服务将成为某些大型应用程序上下文中微服务的映像.服务示例可能包括 HTTP 服务器、数据库或您希望在分布式环境中运行的任何其他类型的可执行程序.

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:

  • swarm 将使服务在 swarm 外部可用的端口
  • 服务连接到群中其他服务的覆盖网络
  • CPU 和内存限制和预留
  • 滚动更新政策
  • 要在 swarm 中运行的镜像副本数

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

这篇关于Docker 服务和 Docker 容器有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆