Connection error accessing a container running REST on port :8080

I can’t get Docker running with my Travis CI runner.

I am running a REST API in a Docker container with a public port 8080. I can verify the container launches without fault and that the container is running at 0.0.0.0:8080.

I have a script that contains Newman (from Postman.)

When using curl I get this error curl: (56) Recv failure: Connection reset by peer.

Are container ports not accessible within the job/worker?

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

Any idea?

Hello again @howtotalktogirls,

Something you have to keep in mind, the way Travis was designed is that mapped container ports are accessible on Travis in the same way they are accessible elsewhere. Are the test commands pass without a problem on your local machine? Also another suggestion - if you already have a docker-compose file, make the tests run as another container, this is sometimes called logical container separation and then on Travis you just run something like docker-compose run tests.

1 Like

Hey @montana,

after adding docker-compose-run tests, this seemed to do the trick. im very grateful.

Thanks for providing perfect and accurate solution to the problem, This give me a valuable knowledge to me.

1 Like

Had to re-find this, thanks again @Montana

Thank you for the kind words everyone!

1 Like