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,520 points
3,606 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
• 52,350 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,700 points
897 views
+1 vote
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,460 points
6,758 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
• 10,620 points
3,544 views
+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,020 points
2,735 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,220 points

edited Oct 16, 2018 by lina 34,230 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,620 points
8,894 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP