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
能够看到详细信息
我根据我本身的体验,给出几点须要注意的