How to link multiple docker swarm services? -


i'm huge fan of docker philosophy (or @ least think am). so, i'm still quite novice in sense don't seem grasp intended way of using docker.

as see currently, there 2 ways of using docker.

  1. create container need app in it.
    • for example, drupal site. put nginx, php, mysql , code container. run service in swarm mode , scale needed. if need drupal site, run second container/service holds nginx, php , mysql , (slightly) different code. need 2 images run container or service off.
    • pro's - easy, need in single container
    • con's - cannot run each container on port 80 (so need reverse proxy or something). (not sure @ imagine) server load higher since there multiple containers/services running nginx, php , mysql.
  2. create 4 separate containers. 1 nginx container, 1 php container, 1 mysql container , 1 code/data container.
    • for example, same drupal site. run them separate service , scale them across servers amount of code containers (drupal sites or other sites) increases. need 1 image per container/service instead of separate image each site.
    • pro's - modular, single responsibility per service (1 database, 1 webserver etc), easy scale area needs scaling (scale database if requests increase, nginx if traffic increases etc).
    • con's - don't know how make work :).

personally opt make setup according second option. have database container/service, nginx container/service etc. seems more flexible me , makes more sense.

i struggling on how make work. how make nginx service @ php service , point nginx config code folder in data service etc. have read stuff overlay network not make clear me how nginx php in separate container/service.

i therefore have 2 (and half) questions:

  1. how docker meant used (option 1 or 2 above or totally different)?
  2. how can link services (make nginx php in different service)?
  3. (half) know beginner trying grasp concept setting simple webserver , running websites seems basic task (at least, me in conventional ways) can't seem find answers online anywhere. totally off par in way think use docker or have not been looking enough?

how docker meant used (option 1 or 2 above or totally different)?

upto you, prefer using option #2, have @ times used mix of option #1 , options #2 also. depends on use case , options looks better use case. @ 1 of our client needed have ssh , nginx, php in same container. mixed #1 , #2. mysql, redis on own container , app on 1 container

how can link services (make nginx php in different service)?

use docker-compose define services , docker stack deploy them. won't have worry names of services

version: '3' services:   web:     image: nginx   db:     image: mysql     environment:       - "mysql_root_password=root" 

now deploy using

docker stack deploy --compose-file docker-compose.yml myapp 

in nginx container can reach mysql using it's service name db. linking happens automatically , need not worry.

i know beginner trying grasp concept setting simple webserver , running websites seems basic task (at least, me in conventional ways) can't seem find answers online anywhere. totally off par in way think use docker or have not been looking enough

there lot of resources available in forms of articles, need look


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -