Commands: build Build or rebuild services bundle Generate a Docker bundle from the Compose file config Validate and view the compose file create Create services down Stop and remove containers, networks, images, and volumes events Receive real time events from containers exec Execute a command in a running container help Get help on a command kill Kill containers logs View output from containers pause Pause services port Print the public port for a port binding ps List containers pull Pull service images push Push service images restart Restart services rm Remove stopped containers run Run a one-off command scale Set number of containers for a service start Start services stop Stop services top Display the running processes unpause Unpause services up Create and start containers version Show the Docker-Compose version information
解釋一下php
build 構建或重建服務 help 命令幫助 kill 殺掉容器 logs 顯示容器的輸出內容 port 打印綁定的開放端口 ps 顯示容器 pull 拉取服務鏡像 restart 重啓服務 rm 刪除中止的容器 run 運行一個一次性命令 scale 設置服務的容器數目 start 開啓服務 stop 中止服務 up 建立並啓動容器
先看看我本身寫的一個 docker-compose.ymlnginx
version: '2' services: nginx: image: bitnami/nginx:latest ports: - '80:80' - '1443:443' volumes: - /root/wp_yunlan/nginx/:/bitnami/nginx/ mariadb: image: bitnami/mariadb:latest volumes: - /root/wp_yunlan/mariadb:/bitnami/mariadb wordpress: image: bitnami/wordpress:latest depends_on: - mariadb - nginx environment: - WORDPRESS_USERNAME=neptunemoon #這個帳戶你是本身設定的 - WORDPRESS_PASSWORD=123123 #這個密碼是你本身設定的 ports: - '8080:80' - '8081:443' volumes: - /root/wp_yunlan/wordpress:/bitnami/wordpress - /root/wp_yunlan/apache:/bitnami/apache - /root/wp_yunlan/php:/bitnami/php
nginx 和 mariadb,wordpress 是要啓動的三個服務docker
順序不是重要的,咱們看見wordpress中有個 depends_on:
的屬性apache
表明wordpress 依賴於服務器
- mariadb - nginx
兩個服務, 因此他們兩個會先啓動markdown
就是你的 docker 鏡像wordpress
這個是在好理解不過的了。
不過這和咱們程序語言設計層面的仍是不同的,這個是容器層面的環境變量。
若是咱們寫程序作一些邏輯判斷的時候,確定會使用
好比咱們判斷如今的編譯器,咱們會使用#if __GNUC__
或者 #if _MSC_VER
相應的,咱們的容器裏面確定也有這樣的邏輯,咱們常常使用環境變量來傳值,或者定義一個行爲。寫過程序的人都懂。ui
映射本機還有鏡像的端口。這個沒有什麼好說的。spa
有兩種格式,
能夠對應 docker 操做中的 -v my/path/:/docker/path
還可使用單方面的 -v /path
這樣的話 就至關於 一個匿名映射, 其實仍是在本機有對應目錄的。設計
使用docker inspect -f {{.Volumes}} /path
能夠看到詳細信息
我根據我本身的體驗,給出幾點須要注意的