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
• 14,960 points
86 views

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
metadata:
  name: nginx
  labels:
    app: my-app
spec:
  nodeSelector:
    podwants: feature1-nodea
  container:
    - name: nginx
      image: nginx:1.8
      ports:
      - containerPort: 80

And a define a service in the following manner:

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

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

 WEB_SVC_SERVICE_HOST=x.x.x.x
 WEB_SVC_SERVICE_PORT=80
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

also,

  • 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
• 41,170 points

Related Questions In Docker

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 19, 2018 in Docker by Tyrion anex
• 8,270 points
46 views
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
• 9,850 points
352 views
0 votes
1 answer
0 votes
1 answer

How to remove old Docker containers

There is a new feature in Docker 1.13.x called Docker ...READ MORE

answered Jul 18, 2018 in Docker by Kalgi
• 2,620 points
37 views
0 votes
1 answer
0 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
• 56,580 points
185 views
+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,110 points

edited Oct 16, 2018 by lina 4,702 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 16, 2018 in Docker by Sophie may
• 9,850 points
578 views