difference between docker service and docker container












0















I can create a docker container by command



docker run <<image_name>>


I can create a service by command



docker service create <<image_name>>


What is the difference between these two in behaviour?



When would I need to create a service over container?










share|improve this question



























    0















    I can create a docker container by command



    docker run <<image_name>>


    I can create a service by command



    docker service create <<image_name>>


    What is the difference between these two in behaviour?



    When would I need to create a service over container?










    share|improve this question

























      0












      0








      0








      I can create a docker container by command



      docker run <<image_name>>


      I can create a service by command



      docker service create <<image_name>>


      What is the difference between these two in behaviour?



      When would I need to create a service over container?










      share|improve this question














      I can create a docker container by command



      docker run <<image_name>>


      I can create a service by command



      docker service create <<image_name>>


      What is the difference between these two in behaviour?



      When would I need to create a service over container?







      docker docker-swarm






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 1 at 11:59









      secret super starsecret super star

      1,025115




      1,025115
























          2 Answers
          2






          active

          oldest

          votes


















          2














          docker service command in a docker swarm replaces the docker run. docker run has been built for single host solutions. Its whole idea is to focus on local containers on the system it is talking to. Whereas in a cluster the individual containers are irrelevant. We simply use swarm services to manage the multiple containers in a cluster. Swarm will orchestrate the containers of the services for us.



          docker service create is mainly to be used in docker swarm mode. docker run does not have the concept of scaling up/down. With docker service create you can specify the number of replicas to be created using the --replicas command. This will create and manage multiple replicas of a containers in many different nodes. There are several such options for managing multiple containers using docker service create and other commands under docker service ...



          One more note: docker services are for container orchestration systems(swarm). It has built in facility for failure recovery. ie. it recreates a container on failure. docker runwould never recreate a container if it fails. When the docker service commands are used we are not directly asking to perform action like "create a single container", rather we are saying to the orchestration system to "put this job in your queue and when you can get to it perform that action on the swarm". This means it has rollback facilities, failure mitigation and lots of intelligence built in.



          You need to consider using docker service create when in swarm mode and docker run when not in swarm mode. You can lookup on docker swarms to understand docker services.






          share|improve this answer


























          • Can I make the service to join sworm while creating one?

            – secret super star
            Jan 1 at 14:27











          • Swarm is deactivated by default. You need to initialize by docker swarm init then services created will be in the swarm. Please lookup on swarm to understand services.

            – Riyafa Abdul Hameed
            Jan 1 at 14:42











          • Got it, thanks.. this is what I am looking for.

            – secret super star
            Jan 1 at 14:54



















          0














          There is no real difference. In the official documentation you can read "Services are really just containers in production".



          Services can be declared in "docker-compose.yml" and can be started from it. Once started, they will run as containers.



          It is just a common way to name parts of your stack.






          share|improve this answer
























          • Agreed with that part, but those are created through docker stack deploy. I am having more specific that I can create a service through command too. So, is there use-case I would use the docker service create command directly?

            – secret super star
            Jan 1 at 12:32











          • docker stack deploy would run on cluster swarm. If you don't have any cluster swarm, it wouldn't run. But if you have many services in your docker-compose file, you can just start them by calling docker-compose command which will create services for you. However, you can not do everything in docker-compose. For example, if you want to declare how many replicas to be started for one service, it won't run. docker stack is required for that.

            – OlivierTerrien
            Jan 1 at 12:34













          • Let's have a look into the official documentation : docs.docker.com/compose/overview. The sample docker-compose file declares 2 services "web" and "redis". To start them all together or one by one, you can use docker-compose command. But if you want to create services yourself, your command is also right.

            – OlivierTerrien
            Jan 1 at 12:39













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53995240%2fdifference-between-docker-service-and-docker-container%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          docker service command in a docker swarm replaces the docker run. docker run has been built for single host solutions. Its whole idea is to focus on local containers on the system it is talking to. Whereas in a cluster the individual containers are irrelevant. We simply use swarm services to manage the multiple containers in a cluster. Swarm will orchestrate the containers of the services for us.



          docker service create is mainly to be used in docker swarm mode. docker run does not have the concept of scaling up/down. With docker service create you can specify the number of replicas to be created using the --replicas command. This will create and manage multiple replicas of a containers in many different nodes. There are several such options for managing multiple containers using docker service create and other commands under docker service ...



          One more note: docker services are for container orchestration systems(swarm). It has built in facility for failure recovery. ie. it recreates a container on failure. docker runwould never recreate a container if it fails. When the docker service commands are used we are not directly asking to perform action like "create a single container", rather we are saying to the orchestration system to "put this job in your queue and when you can get to it perform that action on the swarm". This means it has rollback facilities, failure mitigation and lots of intelligence built in.



          You need to consider using docker service create when in swarm mode and docker run when not in swarm mode. You can lookup on docker swarms to understand docker services.






          share|improve this answer


























          • Can I make the service to join sworm while creating one?

            – secret super star
            Jan 1 at 14:27











          • Swarm is deactivated by default. You need to initialize by docker swarm init then services created will be in the swarm. Please lookup on swarm to understand services.

            – Riyafa Abdul Hameed
            Jan 1 at 14:42











          • Got it, thanks.. this is what I am looking for.

            – secret super star
            Jan 1 at 14:54
















          2














          docker service command in a docker swarm replaces the docker run. docker run has been built for single host solutions. Its whole idea is to focus on local containers on the system it is talking to. Whereas in a cluster the individual containers are irrelevant. We simply use swarm services to manage the multiple containers in a cluster. Swarm will orchestrate the containers of the services for us.



          docker service create is mainly to be used in docker swarm mode. docker run does not have the concept of scaling up/down. With docker service create you can specify the number of replicas to be created using the --replicas command. This will create and manage multiple replicas of a containers in many different nodes. There are several such options for managing multiple containers using docker service create and other commands under docker service ...



          One more note: docker services are for container orchestration systems(swarm). It has built in facility for failure recovery. ie. it recreates a container on failure. docker runwould never recreate a container if it fails. When the docker service commands are used we are not directly asking to perform action like "create a single container", rather we are saying to the orchestration system to "put this job in your queue and when you can get to it perform that action on the swarm". This means it has rollback facilities, failure mitigation and lots of intelligence built in.



          You need to consider using docker service create when in swarm mode and docker run when not in swarm mode. You can lookup on docker swarms to understand docker services.






          share|improve this answer


























          • Can I make the service to join sworm while creating one?

            – secret super star
            Jan 1 at 14:27











          • Swarm is deactivated by default. You need to initialize by docker swarm init then services created will be in the swarm. Please lookup on swarm to understand services.

            – Riyafa Abdul Hameed
            Jan 1 at 14:42











          • Got it, thanks.. this is what I am looking for.

            – secret super star
            Jan 1 at 14:54














          2












          2








          2







          docker service command in a docker swarm replaces the docker run. docker run has been built for single host solutions. Its whole idea is to focus on local containers on the system it is talking to. Whereas in a cluster the individual containers are irrelevant. We simply use swarm services to manage the multiple containers in a cluster. Swarm will orchestrate the containers of the services for us.



          docker service create is mainly to be used in docker swarm mode. docker run does not have the concept of scaling up/down. With docker service create you can specify the number of replicas to be created using the --replicas command. This will create and manage multiple replicas of a containers in many different nodes. There are several such options for managing multiple containers using docker service create and other commands under docker service ...



          One more note: docker services are for container orchestration systems(swarm). It has built in facility for failure recovery. ie. it recreates a container on failure. docker runwould never recreate a container if it fails. When the docker service commands are used we are not directly asking to perform action like "create a single container", rather we are saying to the orchestration system to "put this job in your queue and when you can get to it perform that action on the swarm". This means it has rollback facilities, failure mitigation and lots of intelligence built in.



          You need to consider using docker service create when in swarm mode and docker run when not in swarm mode. You can lookup on docker swarms to understand docker services.






          share|improve this answer















          docker service command in a docker swarm replaces the docker run. docker run has been built for single host solutions. Its whole idea is to focus on local containers on the system it is talking to. Whereas in a cluster the individual containers are irrelevant. We simply use swarm services to manage the multiple containers in a cluster. Swarm will orchestrate the containers of the services for us.



          docker service create is mainly to be used in docker swarm mode. docker run does not have the concept of scaling up/down. With docker service create you can specify the number of replicas to be created using the --replicas command. This will create and manage multiple replicas of a containers in many different nodes. There are several such options for managing multiple containers using docker service create and other commands under docker service ...



          One more note: docker services are for container orchestration systems(swarm). It has built in facility for failure recovery. ie. it recreates a container on failure. docker runwould never recreate a container if it fails. When the docker service commands are used we are not directly asking to perform action like "create a single container", rather we are saying to the orchestration system to "put this job in your queue and when you can get to it perform that action on the swarm". This means it has rollback facilities, failure mitigation and lots of intelligence built in.



          You need to consider using docker service create when in swarm mode and docker run when not in swarm mode. You can lookup on docker swarms to understand docker services.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 1 at 13:29

























          answered Jan 1 at 12:46









          Riyafa Abdul HameedRiyafa Abdul Hameed

          2,57622633




          2,57622633













          • Can I make the service to join sworm while creating one?

            – secret super star
            Jan 1 at 14:27











          • Swarm is deactivated by default. You need to initialize by docker swarm init then services created will be in the swarm. Please lookup on swarm to understand services.

            – Riyafa Abdul Hameed
            Jan 1 at 14:42











          • Got it, thanks.. this is what I am looking for.

            – secret super star
            Jan 1 at 14:54



















          • Can I make the service to join sworm while creating one?

            – secret super star
            Jan 1 at 14:27











          • Swarm is deactivated by default. You need to initialize by docker swarm init then services created will be in the swarm. Please lookup on swarm to understand services.

            – Riyafa Abdul Hameed
            Jan 1 at 14:42











          • Got it, thanks.. this is what I am looking for.

            – secret super star
            Jan 1 at 14:54

















          Can I make the service to join sworm while creating one?

          – secret super star
          Jan 1 at 14:27





          Can I make the service to join sworm while creating one?

          – secret super star
          Jan 1 at 14:27













          Swarm is deactivated by default. You need to initialize by docker swarm init then services created will be in the swarm. Please lookup on swarm to understand services.

          – Riyafa Abdul Hameed
          Jan 1 at 14:42





          Swarm is deactivated by default. You need to initialize by docker swarm init then services created will be in the swarm. Please lookup on swarm to understand services.

          – Riyafa Abdul Hameed
          Jan 1 at 14:42













          Got it, thanks.. this is what I am looking for.

          – secret super star
          Jan 1 at 14:54





          Got it, thanks.. this is what I am looking for.

          – secret super star
          Jan 1 at 14:54













          0














          There is no real difference. In the official documentation you can read "Services are really just containers in production".



          Services can be declared in "docker-compose.yml" and can be started from it. Once started, they will run as containers.



          It is just a common way to name parts of your stack.






          share|improve this answer
























          • Agreed with that part, but those are created through docker stack deploy. I am having more specific that I can create a service through command too. So, is there use-case I would use the docker service create command directly?

            – secret super star
            Jan 1 at 12:32











          • docker stack deploy would run on cluster swarm. If you don't have any cluster swarm, it wouldn't run. But if you have many services in your docker-compose file, you can just start them by calling docker-compose command which will create services for you. However, you can not do everything in docker-compose. For example, if you want to declare how many replicas to be started for one service, it won't run. docker stack is required for that.

            – OlivierTerrien
            Jan 1 at 12:34













          • Let's have a look into the official documentation : docs.docker.com/compose/overview. The sample docker-compose file declares 2 services "web" and "redis". To start them all together or one by one, you can use docker-compose command. But if you want to create services yourself, your command is also right.

            – OlivierTerrien
            Jan 1 at 12:39


















          0














          There is no real difference. In the official documentation you can read "Services are really just containers in production".



          Services can be declared in "docker-compose.yml" and can be started from it. Once started, they will run as containers.



          It is just a common way to name parts of your stack.






          share|improve this answer
























          • Agreed with that part, but those are created through docker stack deploy. I am having more specific that I can create a service through command too. So, is there use-case I would use the docker service create command directly?

            – secret super star
            Jan 1 at 12:32











          • docker stack deploy would run on cluster swarm. If you don't have any cluster swarm, it wouldn't run. But if you have many services in your docker-compose file, you can just start them by calling docker-compose command which will create services for you. However, you can not do everything in docker-compose. For example, if you want to declare how many replicas to be started for one service, it won't run. docker stack is required for that.

            – OlivierTerrien
            Jan 1 at 12:34













          • Let's have a look into the official documentation : docs.docker.com/compose/overview. The sample docker-compose file declares 2 services "web" and "redis". To start them all together or one by one, you can use docker-compose command. But if you want to create services yourself, your command is also right.

            – OlivierTerrien
            Jan 1 at 12:39
















          0












          0








          0







          There is no real difference. In the official documentation you can read "Services are really just containers in production".



          Services can be declared in "docker-compose.yml" and can be started from it. Once started, they will run as containers.



          It is just a common way to name parts of your stack.






          share|improve this answer













          There is no real difference. In the official documentation you can read "Services are really just containers in production".



          Services can be declared in "docker-compose.yml" and can be started from it. Once started, they will run as containers.



          It is just a common way to name parts of your stack.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 1 at 12:24









          OlivierTerrienOlivierTerrien

          972819




          972819













          • Agreed with that part, but those are created through docker stack deploy. I am having more specific that I can create a service through command too. So, is there use-case I would use the docker service create command directly?

            – secret super star
            Jan 1 at 12:32











          • docker stack deploy would run on cluster swarm. If you don't have any cluster swarm, it wouldn't run. But if you have many services in your docker-compose file, you can just start them by calling docker-compose command which will create services for you. However, you can not do everything in docker-compose. For example, if you want to declare how many replicas to be started for one service, it won't run. docker stack is required for that.

            – OlivierTerrien
            Jan 1 at 12:34













          • Let's have a look into the official documentation : docs.docker.com/compose/overview. The sample docker-compose file declares 2 services "web" and "redis". To start them all together or one by one, you can use docker-compose command. But if you want to create services yourself, your command is also right.

            – OlivierTerrien
            Jan 1 at 12:39





















          • Agreed with that part, but those are created through docker stack deploy. I am having more specific that I can create a service through command too. So, is there use-case I would use the docker service create command directly?

            – secret super star
            Jan 1 at 12:32











          • docker stack deploy would run on cluster swarm. If you don't have any cluster swarm, it wouldn't run. But if you have many services in your docker-compose file, you can just start them by calling docker-compose command which will create services for you. However, you can not do everything in docker-compose. For example, if you want to declare how many replicas to be started for one service, it won't run. docker stack is required for that.

            – OlivierTerrien
            Jan 1 at 12:34













          • Let's have a look into the official documentation : docs.docker.com/compose/overview. The sample docker-compose file declares 2 services "web" and "redis". To start them all together or one by one, you can use docker-compose command. But if you want to create services yourself, your command is also right.

            – OlivierTerrien
            Jan 1 at 12:39



















          Agreed with that part, but those are created through docker stack deploy. I am having more specific that I can create a service through command too. So, is there use-case I would use the docker service create command directly?

          – secret super star
          Jan 1 at 12:32





          Agreed with that part, but those are created through docker stack deploy. I am having more specific that I can create a service through command too. So, is there use-case I would use the docker service create command directly?

          – secret super star
          Jan 1 at 12:32













          docker stack deploy would run on cluster swarm. If you don't have any cluster swarm, it wouldn't run. But if you have many services in your docker-compose file, you can just start them by calling docker-compose command which will create services for you. However, you can not do everything in docker-compose. For example, if you want to declare how many replicas to be started for one service, it won't run. docker stack is required for that.

          – OlivierTerrien
          Jan 1 at 12:34







          docker stack deploy would run on cluster swarm. If you don't have any cluster swarm, it wouldn't run. But if you have many services in your docker-compose file, you can just start them by calling docker-compose command which will create services for you. However, you can not do everything in docker-compose. For example, if you want to declare how many replicas to be started for one service, it won't run. docker stack is required for that.

          – OlivierTerrien
          Jan 1 at 12:34















          Let's have a look into the official documentation : docs.docker.com/compose/overview. The sample docker-compose file declares 2 services "web" and "redis". To start them all together or one by one, you can use docker-compose command. But if you want to create services yourself, your command is also right.

          – OlivierTerrien
          Jan 1 at 12:39







          Let's have a look into the official documentation : docs.docker.com/compose/overview. The sample docker-compose file declares 2 services "web" and "redis". To start them all together or one by one, you can use docker-compose command. But if you want to create services yourself, your command is also right.

          – OlivierTerrien
          Jan 1 at 12:39




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53995240%2fdifference-between-docker-service-and-docker-container%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          'app-layout' is not a known element: how to share Component with different Modules

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          WPF add header to Image with URL pettitions [duplicate]