docker-compose怎么用

这篇文章给大家分享的是有关docker-compose怎么用的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

成都创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于成都网站设计、成都网站建设、外贸网站建设、西工网络推广、成都小程序开发、西工网络营销、西工企业策划、西工品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;成都创新互联公司为所有大学生创业者提供西工建站搭建服务,24小时服务热线:13518219792,官方网址:www.cdcxhl.com

The Compose file is a YAML file defining services, networks and volumes. A service definition contains configuration that is applied to each container started for that service, much like passing command-line parameters to docker run. Likewise, network and volume definitions are analogous to docker network create and docker volume create.As with docker run, options specified in the Dockerfile, such as CMD, EXPOSE, VOLUME, ENV, are respected by default - you don’t need to specify them again in docker-compose.yml.

文档上这段话已经概括了docker-compose编排文件的写法。一个yaml的编排文件定义了 services, networks and volumes,service定义的配置其实就是docker run命令的参数,同理network and volume定义的是docker network createdocker volume create命令,在dockerfile文件中有的诸如CMD, EXPOSE, VOLUME, ENV命令则不需要重新定义。剩下的需要什么找什么命令就好了。

一个例子:

创建一个名为kong-net,桥接模式的network,将3个容器加入进来,其中kong容器是使用dockerfile构建,db和konga使用远程仓库镜像,kong的启动在db之后,konga的启动在kong之后。

version: '3'
services:
  kong:
    container_name: kong-dapeng
    environment:
      - KONG_DATABASE=postgres
      - KONG_PG_HOST=kong-database
      - KONG_PG_PASSWORD=kong
      - KONG_PROXY_ACCESS_LOG=/dev/stdout
      - KONG_ADMIN_ACCESS_LOG=/dev/stdout
      - KONG_PROXY_ERROR_LOG=/dev/stderr
      - KONG_ADMIN_ERROR_LOG=/dev/stderr
      - KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl
      - KONG_PLUGINS=bundled,router-by-jwt-claim,jwt-dapeng,kafka-log
    build: .
    ports:
      - "80:8000"
      - "8001:8001"
    networks:
      - kong-net
    depends_on:
      - db
  db:
    container_name: kong-database
    image: "postgres:9.6"
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_USER=kong
      - POSTGRES_DB=kong
      - POSTGRES_PASSWORD=kong
    volumes:
      - /dockerV/postgres:/var/lib/postgresql/data
    networks:
      - kong-net
  konga:
    container_name: konga
    image: "pantsel/konga"
    ports:
      - "1337:1337"
    environment:
      - DB_ADAPTER=postgres
      - DB_HOST=kong-database
      - DB_PORT=5432
      - DB_USER=kong
      - DB_PASSWORD=kong
      - DB_DATABASE=konga
    networks:
      - kong-net
    depends_on:
      - kong
networks:
  kong-net:
    driver: bridge

感谢各位的阅读!关于“docker-compose怎么用”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!


网站题目:docker-compose怎么用
转载注明:http://azwzsj.com/article/jecisp.html