在Docker撰写文件中设置localstack资源会导致连接中止失败

时间:2019-12-18 10:26:11

标签: docker-compose localstack

我有一个docker compose文件,如下所示:

version: "3"

services:
  localstack:
    image: localstack/localstack:latest
    ports:
      - "4567-4597:4567-4597"
      - "${PORT_WEB_UI-8080}:${PORT_WEB_UI-8080}"
    environment:
      - SERVICES=s3
      - DOCKER_HOST=unix:///var/run/docker.sock
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
      - "/private${TMPDIR}:/tmp/localstack"
    networks:
      - my_awesome_network

  setup-resources:
    image: mesosphere/aws-cli
    volumes:
      - ./dev_env:/project/dev_env
    environment:
      - AWS_ACCESS_KEY_ID=dummyaccess
      - AWS_SECRET_ACCESS_KEY=dummysecret
      - AWS_DEFAULT_REGION=us-east-1
    entrypoint: /bin/sh -c
    command: >
      "
        sleep 10;
        # aws kinesis create-stream --endpoint-url=http://localstack:4568 --stream-name my_stream --shard-count 1;
        aws --endpoint-url=http://localhost:4572 s3 mb s3://demo-bucket
      "
    networks:
      - my_awesome_network
    depends_on:
      - localstack
networks:
  my_awesome_network:
已从我发现的this个博客文章中复制的

,但是当我运行docker-compose up时,存储桶无法创建,并出现以下错误:('Connection aborted.', error(99, 'Address not available'))

3 个答案:

答案 0 :(得分:2)

我运行时进行了很小的更改,并且它可以正常工作,将localhost更改为localstack

version: "3"

services:
  localstack:
    image: localstack/localstack:latest
    ports:
      - '4568-4576:4568-4576'
      - '8055:8080'
    environment:
      - SERVICES=s3
      - DOCKER_HOST=unix:///var/run/docker.sock
      - DEFAULT_REGION=us-east-1
      - DEBUG=1
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
      - "/private${TMPDIR}:/tmp/localstack"
    networks:
      - my_awesome_network

  setup-resources:
    image: mesosphere/aws-cli
    volumes:
      - ./dev_env:/project/dev_env
    environment:
      - AWS_ACCESS_KEY_ID=dummyaccess
      - AWS_SECRET_ACCESS_KEY=dummysecret
      - AWS_DEFAULT_REGION=us-east-1
    entrypoint: /bin/sh -c
    command: >
      "
        sleep 10;

        aws --endpoint-url=http://localstack:4572 s3 mb s3://demo-bucket
      "
    networks:
      - my_awesome_network
    depends_on:
      - localstack
networks:
  my_awesome_network:

答案 1 :(得分:0)

此处的详细信息很小,但不应为aws --endpoint-url=http://localhost:4572 s3 mb s3://demo-bucket 它应该改为aws --endpoint-url=http://localstack:4572 s3 mb s3://demo-bucket,对了,localhost变成了localstack

答案 2 :(得分:-1)

从版本0.11.0开始, 所有API均通过单一边缘服务公开, 可以在

上访问

http://localhost:4566 by default

和EDGE_PORT = 4566。

基于此 Article