如何将第三方go应用程序停靠

时间:2018-05-25 22:18:17

标签: docker docker-compose dockerfile

除了运行用go编写的微服务的Docker容器(每个微服务一个容器),我需要创建一个运行第三方提供的Service Registry服务的Docker容器框架(Koding的kontrol)。

话虽如此,我需要通过执行以下命令来创建一个运行此第三方go应用程序的单独容器。

  1. 检索应用程序:

    go get github.com/koding/kite/kontrol/kontrol

  2. 生成RSA密钥对:

    openssl genrsa -out key.pem 2048 openssl rsa -in key.pem -pubout > key_pub.pem

  3. 设置一些环境变量:

    KONTROL_PORT=6000 KONTROL_USERNAME="kontrol" KONTROL_STORAGE="etcd" KONTROL_KONTROLURL="http://127.0.0.1:6000/kite" KONTROL_PUBLICKEYFILE="certs/key_pub.pem" KONTROL_PRIVATEKEYFILE="certs/key.pem"

  4. 初始化Registry Service

    ./bin/kontrol -initial

  5. 启动Registry Service

    ./bin/kontrol

  6. 如何在项目中包含这些步骤?例如,我有一个docker-composer.yaml这样的文件:

    version: '3.3'
    services:
      api:
        container_name: 'api'
        build: './api'
        ports:
          - '8080:8080'
        volumes:
          - './api:/go/src/app'
        depends_on:
          - 'mongo'
      etcd0:
        container_name: 'etcd0'
        image: 'quay.io/coreos/etcd'
        command: >
          etcd -name etcd0
          -advertise-client-urls http://127.0.0.1:2379,http://127.0.0.1:4001
          -listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001
          -initial-advertise-peer-urls http://127.0.0.1:2380
          -listen-peer-urls http://0.0.0.0:2380
          -initial-cluster-token etcd-cluster-1
          -initial-cluster etcd0=http://127.0.0.1:2380
          -initial-cluster-state new
      mongo:
        container_name: 'mongo'
        image: 'mongo:latest'
        ports:
          - '27017:27017'
        volumes:
          - '/var/lib/mongodb:/var/lib/mongodb'
    

0 个答案:

没有答案