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'

      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  
      - '80:80'
    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

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
  • docker-compose up



Josephrarma @MYOAK 12 月前

research paper [url=]research essay[/url]

CharlesvoG @Josephrarma 9 月,1 周前

wh0cd814540 [url=]amoxicillin[/url]

MichaelDaw @CharlesvoG 9 月,2 周前

wh0cd370742 [url=]paxil anxiety[/url]

MichaelDaw @MichaelDaw 9 月,2 周前

wh0cd814540 [url=]lisinopril2019[/url]

homeinsurance @MichaelDaw 9 月,2 周前

best home insurance home insurance aarp insurance homeowners [url=]home insurance[/url]

CharlesvoG @MichaelDaw 9 月,3 周前

wh0cd814540 [url=]levitra online canada[/url]

DavidHausa @Chatgirl 1 年前

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

Jordanriz @DavidHausa 1 年前

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

PLUTSBUH @Jordanriz 8 月,3 周前

buy cheap cialis online cialis [url=]buy cheap cialis[/url] cheap cialis generic canada buy cheap cialis online

MichaelDaw @PLUTSBUH 9 月,2 周前

wh0cd592641 [url=]propecia[/url]

CharlesvoG @MichaelDaw 9 月,2 周前

wh0cd592641 [url=]tetracycline[/url]

CharlesvoG @MichaelDaw 9 月,1 周前

wh0cd148843 [url=]prednisolone buy online[/url]

Alfredwaids @PLUTSBUH 9 月,2 周前

wh0cd814540 [url=]lasix[/url]

CharlesvoG @Alfredwaids 8 月,4 周前

wh0cd1191996 [url=]propranolol[/url] [url=]antabuse[/url] [url=]buy amoxicillin without prescription[/url] [url=]lasix[/url] [url=]synthroid 0.05 mg[/url] [url=]motrin 600[/url] [url=]azithromycin 250 mg price[/url] [url=]NEURONTIN MEDICATION[/url] [url=]synthroid 125 mcg[/url] [url=]how much is retin a[/url]

AntoninRuila @PLUTSBUH 9 月,3 周前

a24f cialis suggested use [url=]buy cialis[/url] generic cialis online prix cialis en belgique

MichaelDaw @AntoninRuila 9 月,1 周前

wh0cd370742 [url=]tetracycline 250 mg[/url]

Markgog @AntoninRuila 10 月,1 周前

generic viagra made in usa female viagra pills buy viagra uk yahoo news [URL= ]viagra 100mg[/URL]

BorislavaRuila @Markgog 9 月,3 周前

eb1a online sur le net order online online 100 mg

ThozasZit @BorislavaRuila 10 月,3 周前

viagra online yabb [url=]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 10 月,2 周前

easiest payday loans to get [url=]fast personal loans[/url] payday loan companies not brokers fast personal loans

Richardnit @Jordanriz 12 月前
CharlesvoG @Richardnit 9 月,2 周前

wh0cd370742 [url=]buy lasix 40 mg[/url]

MichaelCok @Jordanriz 12 月前

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

AlibinaRuila @MichaelCok 9 月,3 周前

5dc1 viagra para hipertensos online viagra alternating use viagra cialis

Aaronclait @AlibinaRuila 9 月前

wh0cd1191996 [url=]neurontin online[/url] [url=]azithromycin[/url] [url=]bonuses[/url] [url=]motrin[/url] [url=]order antabuse no prescription[/url] [url=]example[/url] [url=]lasix[/url] [url=]buy amoxicillin without prescription[/url] [url=]retin a 0.05[/url] [url=]synthroid[/url]

CharlesvoG @CharlesvoG 9 月,2 周前

wh0cd592641 [url=]celebrex[/url]

Kennethdic @CharlesvoG 7 月,2 周前


Joaquincrefe @Brianfup 1 年前
ApAtte @Brianfup 11 月前

buy cialis online canada buy [url=]buy generic cialis online[/url] cheap cialis no prescription generic cialis online

uyokayaus @AlibinaRuila 9 月,2 周前


baigeor @uyokayaus 8 月,4 周前

viagra pills canada buy cialis online [url=]cheap cialis[/url] lowest price generic cialis online pharmacy cheap cialis