Docker - Docker Compose

Docker compose is a combination of a command line tool and a configuration file. It configures relationships between containers. It can save all "docker container run" settings in an easy-to-read file. You can spin all container up and tear them down using one command.

Docker compose is comprised of 2 things:

  • YAML-formatted file - specify all containers to run, the networks and volumes you need, environment variables, images and all sorts of other configuration

  • a CLI tool docker-compose used for local dev/test automation with those YAML files


1.YAML-formatted file

Here is an example of docker-compose.yml file, the name of it is by default, if you want to use your own name, your can use command docker-compose -f to specify a YAML file with particular name

# Compose YAML format has its own versions: 1, 2, 2.1, 3, 3.1, at least 2 is recommended
version: '2'

services:
  proxy:
    build:
      context: .   # use dot to represent the current direcotry
      dockerfile: nginx.Dockerfile
      image: nginx-custom # name you image, but if you name it, you cannot use '--rmi local' to remove the image when use docker-compose down  
    ports:
      - '80:80'
  web:
    image: httpd  # key-value format
    volumes:     # key list format
      - ./html:/usr/local/apache2/htdocs/

Compose can also build your custom images. you need to run docker-compose build to rebuild images if you make some changes of the Dockerfile. The above code is also an example.

Here is a YAML file template:

version: '3.1'  # if no version is specificed then v1 is assumed. Recommend v2 minimum
# the indentation can be 2 or 4 spaces but it does need to be consistent

services:  # containers. same as docker run
  servicename: # a friendly name. this is also DNS name inside network
    image: # Optional if you use build:
    command: # Optional, replace the default CMD specified by the image
    environment: # Optional, same as -e in docker run
    volumes: # Optional, same as -v in docker run
  servicename2:

volumes: # Optional, same as docker volume create

networks: # Optional, same as docker network create


2.Docker-compose CLI

It is not a production-grade tool but ideal for local development and test

docker-compose up setup volumes/networks and start all containers. Add -d to run in background

docker-compose down stop all containers and remove containers/volumes/networks. use -v to remove volumes as well.

docker-compose logs to show the log info

docker-compose ps who all the running containers

docker-compose top to show all the services running inside the containers

docker-compose --help to check all the commands you can run

This is very easy to setup a complex environment instead of using a VM. If all your projects had a Dockerfile and docker-compose.yml, then "new developer onboarding" would be:

  • git clone github.com/some/software
  • docker-compose up

登录注册后参与评论

22人参与,35条评论

Josephrarma @MYOAK 10 月,1 周前

research paper [url=http://writeresearchpaper.us.com]research essay[/url]

CharlesvoG @Josephrarma 7 月,2 周前

wh0cd814540 [url=http://amoxicillin.team/]amoxicillin[/url]

MichaelDaw @CharlesvoG 7 月,3 周前

wh0cd370742 [url=http://paxilbest.us.com/]paxil anxiety[/url]

MichaelDaw @MichaelDaw 7 月,3 周前

wh0cd814540 [url=http://lisinopril2019.com/]lisinopril2019[/url]

homeinsurance @MichaelDaw 7 月,3 周前

best home insurance home insurance aarp insurance homeowners [url=https://homeinsurance.us.com]home insurance[/url]

CharlesvoG @MichaelDaw 8 月前

wh0cd814540 [url=http://levitra2019.com/]levitra online canada[/url]

DavidHausa @Chatgirl 10 月,2 周前

I apologize for off-topic, I am considering about creating an informative website as a student. Will probably commence with submitting interesting facts like"Flies jump backwards during takeoff."Please let me know if you know where I can find some related information and facts like here http://www.dengerulo.com/finishing-a-clinical-dissertation-is-probably-the/

Jordanriz @DavidHausa 10 月,2 周前

keno online indonesia free roulette game best casino game app for ipad roulette online us online casino ipad

PLUTSBUH @Jordanriz 7 月前

buy cheap cialis online cialis [url=http://www.cialischgftx.com]buy cheap cialis[/url] cheap cialis generic canada buy cheap cialis online

MichaelDaw @PLUTSBUH 7 月,3 周前

wh0cd592641 [url=http://propecia2019.com/]propecia[/url]

CharlesvoG @MichaelDaw 7 月,3 周前

wh0cd592641 [url=http://tetracycline2019.com/]tetracycline[/url]

CharlesvoG @MichaelDaw 7 月,2 周前

wh0cd148843 [url=http://prednisolonepills.video/]prednisolone buy online[/url]

Alfredwaids @PLUTSBUH 7 月,4 周前

wh0cd814540 [url=http://lasix2019.com/]lasix[/url]

CharlesvoG @Alfredwaids 7 月前

wh0cd1191996 [url=http://propranolol.guru/]propranolol[/url] [url=http://antabuse.network/]antabuse[/url] [url=http://amoxicillinpills.doctor/]buy amoxicillin without prescription[/url] [url=http://lasix.network/]lasix[/url] [url=http://synthroid.bio/]synthroid 0.05 mg[/url] [url=http://motrin.icu/]motrin 600[/url] [url=http://azithromycin.network/]azithromycin 250 mg price[/url] [url=http://neurontinbest.us.org/]NEURONTIN MEDICATION[/url] [url=http://synthroidpills.doctor/]synthroid 125 mcg[/url] [url=http://retinapills.in.net/]how much is retin a[/url]

AntoninRuila @PLUTSBUH 8 月前

a24f cialis suggested use [url=http://cialisuyit.com/]buy cialis[/url] generic cialis online prix cialis en belgique

MichaelDaw @AntoninRuila 7 月,2 周前

wh0cd370742 [url=http://tetracyclinebest.us.com/]tetracycline 250 mg[/url]

Markgog @AntoninRuila 8 月,2 周前

generic viagra made in usa female viagra pills buy viagra uk yahoo news [URL=http://viagrafanlux.com#generic+viagra ]viagra 100mg[/URL]

BorislavaRuila @Markgog 7 月,4 周前

eb1a online sur le net http://ph-f63f6-3-1.com/ order online online 100 mg

ThozasZit @BorislavaRuila 8 月,4 周前

viagra online yabb [url=http://viagrawithoutdoctorprescr.com]viagra without a doctor prescription[/url] natural alternative ti viagra viagra without a doctor prescription - viagra 10mg or 20mg log me on automatically each visit viagra online safety

Enlaceaf @Jordanriz 8 月,3 周前

easiest payday loans to get [url=http://personalloansx1.com/#]fast personal loans[/url] payday loan companies not brokers fast personal loans

Richardnit @Jordanriz 10 月,1 周前
CharlesvoG @Richardnit 7 月,3 周前

wh0cd370742 [url=http://lasix2019.com/]buy lasix 40 mg[/url]

MichaelCok @Jordanriz 10 月,1 周前

online poker gambling us free casino slots slots online real money usa vegas slots online free popular casino games list

AlibinaRuila @MichaelCok 8 月前

5dc1 viagra para hipertensos online viagra alternating use viagra cialis

Aaronclait @AlibinaRuila 7 月,1 周前

wh0cd1191996 [url=http://neurontinbest.us.org/]neurontin online[/url] [url=http://azithromycin.network/]azithromycin[/url] [url=http://propranolol.guru/]bonuses[/url] [url=http://motrin.icu/]motrin[/url] [url=http://antabuse.network/]order antabuse no prescription[/url] [url=http://synthroid.bio/]example[/url] [url=http://lasix.network/]lasix[/url] [url=http://amoxicillinpills.doctor/]buy amoxicillin without prescription[/url] [url=http://retinapills.in.net/]retin a 0.05[/url] [url=http://synthroidpills.doctor/]synthroid[/url]

CharlesvoG @CharlesvoG 7 月,3 周前

wh0cd592641 [url=http://celebrexbest.us.org/]celebrex[/url]

Kennethdic @CharlesvoG 5 月,3 周前

[url=http://cheapestsildenafilonline.com/]Sildenafil[/url]

Joaquincrefe @Brianfup 10 月,1 周前
ApAtte @Brianfup 9 月,1 周前

buy cialis online canada buy [url=http://cialisdelta.com/#]buy generic cialis online[/url] cheap cialis no prescription generic cialis online

uyokayaus @AlibinaRuila 7 月,3 周前

[url=http://doxycycline-cheapbuy.site/]doxycycline-cheapbuy.site.ankor[/url] onlinebuycytotec.site.ankor

baigeor @uyokayaus 7 月前

viagra pills canada buy cialis online [url=http://cialischgftx.com]cheap cialis[/url] lowest price generic cialis online pharmacy cheap cialis