Travis CI连接错误访问在端口8080上运行REST API的Docker容器

时间:2019-06-01 12:40:37

标签: docker docker-compose postman travis-ci newman

我在连接Travis CI作业/工作人员内部的Docker容器时遇到问题。

我正在具有公共端口8080的Docker容器中运行REST API。我可以验证容器是否正常启动以及容器是否以0.0.0.0:8080运行。

在脚本编写过程中,我正在运行邮递员/纽曼测试,并且每次运行测试时,我都会不断收到socket hang upread ECONNRESET。我尝试了端点上localhost,127.0.0.1、0.0.0.0的每种组合,但都失败了。

使用curl时,尝试访问这些端点curl: (56) Recv failure: Connection reset by peer时也出现连接错误。

在工作/工作人员内部无法访问容器端口吗?

docker-compose.yml

version: "2"
services:
  db:
    container_name: api-db
    image: mysql:5.7.22
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: api_db
      MYSQL_USER: devadmin
      MYSQL_PASSWORD: password
    volumes:
     - db_data:/var/lib/mysql
    ports:
      - 3366:3306/tcp
    networks:
     - web    
  rest-api:
    container_name: rest-api
    build: .
    depends_on:
      - db
    command: "python manage.py runserver 0.0.0.0:8000"
    privileged: true
    restart: always
    ports:
      - 8080:8000/tcp
    networks:
      - web
    links:
     - db:mysql
    volumes:
      - ../../app:/app
networks:
  web:
    driver: bridge
volumes:
  db_data:
    driver: local

.travis.yml

language: node_js
node_js:
  - "8.2.1"

services:
  - docker

before_install:
  - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  - sudo apt-get update
  - sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce

install:
  - docker-compose -f docker/dev/docker-compose.yml up -d
  - npm install newman

before_script:
  - node --version
  - npm --version
  - node_modules/.bin/newman --version
  - docker ps

script:
  - curl localhost:8080/testendpoint/
  - node_modules/.bin/newman run tests/postman/API.postman_collection.json -e tests/postman/Testing.postman_environment.json

0 个答案:

没有答案