How to run docker containers on different machines

+1 vote

I've setup several docker containers for my application:

  1. container for mysql
  2. container for application server (tomcat7)
  3. container for nginx
  4. container for python tornado application

On my local machine, using docker-machine, I've tried all these containers and them interactive with each other. I created one virtualbox machine with boot2linux and setup all these containers on it.

Now, for production I am going to run each one of these containers on a separate server. Is there something docker provides to quickly/easily do this? Or should I set up docker on each server, copy relevant images to that server, and then start docker-images manually on all servers?

Jul 5, 2018 in Docker by Hannah
• 18,570 points

2 answers to this question.

0 votes
Best answer

You can use labels and selectors for this purpose.

First add labels to the nodes:

kubectl local nodes node-a podwants=feature1-nodea
kubectl local nodes node-b podwants=feature1-nodeb

A nodeSelector can then be set in the Pod definitions spec.

apiVersion: v1
kind: Pod
  name: nginx
    app: my-app
    podwants: feature1-nodea
    - name: nginx
      image: nginx:1.8
      - containerPort: 80

And a define a service in the following manner:

kind: Service
apiVersion: v1
  name: web-svc
    app: my-app
  - protocol: TCP
    port: 80
    targetPort: 80

Add CoreDNS to your cluster to discover the available Services in other Pods.

answered Oct 23, 2018 by Laila

selected Oct 23, 2018 by Kalgi
0 votes

set up docker on each server, copy relevant images to that server, and then start docker-images manually on all servers


  • create the relevant libnetworks in order for your containers to be registered in them
  • create as first container a KV one (Key-Value: Consul, etc, Zookeeper, ...) that will monitor each containers in each network(/machine), allowing them to see each others.
    Note: you might want to use a docker 1.10 for adding a network-scoped alias to your containers.

Then you can create your containers on your machines.

answered Jul 5, 2018 by Kalgi
• 52,370 points

Related Questions In Docker

0 votes
1 answer
0 votes
1 answer

How to run an image with volume on docker for windows?

Try : declaring the volume of container mounting the ...READ MORE

answered Sep 20, 2018 in Docker by Tyrion anex
• 8,690 points
0 votes
1 answer

How to write ansible play book to install docker and start docker container with docker image on multiple host machines

Hi@Shashi, You can do this task easily with ...READ MORE

answered Oct 22, 2020 in Docker by MD
• 95,320 points
0 votes
1 answer

How to run a docker command from inside the container?

You must have come across the /var/run/docker.sock file, ...READ MORE

answered Jun 28, 2018 in Docker by Sophie may
• 10,550 points
+2 votes
1 answer
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,140 points
+4 votes
4 answers

How To Access a Service on Host From a Docker Container?

Adding to kalgi's answer, You can also ...READ MORE

answered Oct 16, 2018 in Docker by lina
• 8,220 points

edited Oct 16, 2018 by lina 24,589 views
0 votes
1 answer

How to obtain the Docker container's IP address from the host?

This can be done by executing the ...READ MORE

answered Jul 17, 2018 in Docker by Sophie may
• 10,550 points