Docker Compose: Multi-Container Aikace-aikacen Orchestrate

Docker Compose kayan aiki ne mai ƙarfi da dacewa don tsara multi-container aikace-aikace a cikin yanayin Docker. Yana ba ku damar ayyana da sarrafa ayyuka da sigogi masu alaƙa a cikin fayil ɗin YAML, yana sauƙaƙa turawa da sarrafa aikace-aikace masu rikitarwa waɗanda suka ƙunshi kwantena da yawa.

Ga misali don nuna yadda ake amfani da shi Docker Compose don tsara multi-container aikace-aikacen:

 

Ƙirƙiri fayil ɗin docker-compose.yml

Fara da ƙirƙirar fayil ɗin docker-compose.yml don ayyana daidaitawar aikace-aikacen ku.

Misali:

version: '3'  
services:  
  web:  
    image: nginx:latest  
    ports:  
   - 80:80  
  db:  
    image: mysql:latest  
    environment:  
   - MYSQL_ROOT_PASSWORD=password  

A cikin wannan misali, mun ayyana ayyuka guda biyu: "web" da "db". Sabis na "web" yana amfani da hoton nginx da tashar taswira 80 na akwati zuwa tashar jiragen ruwa 80 akan na'ura mai masauki. Sabis na "db" yana amfani mysql image da kuma saita tushen kalmar sirri zuwa "password".

 

Fara aikace-aikacen

Da zarar kun ayyana fayil ɗin docker-compose.yml, zaku iya fara aikace-aikacen ta amfani da umarni mai zuwa:

docker-compose up

Wannan umarnin zai ƙirƙira kuma ya fara container  bisa tsarin daidaitawa a cikin fayil ɗin docker-compose.yml.

 

Sarrafa aikace-aikacen

Kuna iya amfani da Docker Compose umarni don sarrafa aikace-aikacen ku.

  • Dakatar da aikace-aikacen: docker-compose stop
  • Sake kunna aikace-aikacen: docker-compose restart
  • Rushe aikace-aikacen: docker-compose down

 

Docker Compose za ta ƙirƙiri cibiyoyin sadarwa ta atomatik don haɗa container cikin aikace-aikacen kuma ta taimaka muku sarrafa container ayyuka da sauƙi cikin sauƙi.

Docker Compose yana ba da hanya mai dacewa da ƙarfi don tsara multi-containe aikace-aikacen r. Ta amfani da fayil ɗin docker-compose.yml da madaidaitan umarni, zaku iya turawa, sarrafa, da daidaita aikace-aikacenku cikin sauƙi a cikin yanayin Docker.