Can reach localhost using curl either inside or outside docker container

docker
circle.yml
dotnet
cci-20

#1

Environment

  • Circle CI version 2 w/ workflows
  • docker (as opposed to machine)
  • image: microsoft/aspnetcore-build

All I am trying to do is something that was really easy to do in CircleCI version 1.

curl -X GET http://localhost/api/values/5

I tried a few different approaches and none is working. The first is this

    steps:
      - checkout
      - attach_workspace:
          at: ~/my-folder
      - run:
          name: Run the API
          command: dotnet app/app.dll
          background: true
      - run:
          name: Execute Integration Tests
          command: |
            curl -X GET http://localhost/api/values/5

The step Run the API was cancelled (due to background: true) and the curl connection was rejected / refused on port 80.

Another thing that I tried was

    steps:
      - checkout
      - attach_workspace:
          at: ~/my-folder
      - run:
          name: Execute Integration Tests
          command: |
            dotnet publish/Infrastructure.WebApi.dll &
            curl -X GET http://localhost/api/values/5

didn’t work either.

Then I tried

    steps:
      - checkout
      - attach_workspace:
          at: ~/my-folder
      - run:
          name: Execute Integration Tests
          command: |
            SERVER=$(hostname -i)
            dotnet publish/Infrastructure.WebApi.dll &
            curl -X GET http://$SERVER/api/values/5

Still no love.

Finally, I tried setting up a remote docker so that I could run the container and try to call the URL externally as opposed to inside the container. And that didn’t work, either.

    steps:
      - setup_remote_docker
      - checkout
      - attach_workspace:
          at: ~/my-workspace
      - run:
          name: Install Docker Client
          command: |
            set -x
            VER="17.03.0-ce"
            curl -L -o /tmp/docker-$VER.tgz https://get.docker.com/builds/Linux/x86_64/docker-$VER.tgz
            tar -xz -C /tmp -f /tmp/docker-$VER.tgz
            mv -u /tmp/docker/* /usr/bin

      # build and push Docker image
      - run:
          name: Build Container for Testing
          command: |
            TAG=0.1.0_build_$CIRCLE_BUILD_NUM
            docker build --rm=false --no-cache -t my-container .
            docker run -itd -p 8080:80 my-container
      - run:
          name: Run Integration Tests
          command: |
            SERVER=$(hostname -i)
            curl -X GET http://localhost:8090/api/values
            curl -X GET http://localhost:8090/api/values/5
            curl -X GET http://$SERVER:8090/api/values
            curl -X GET http://$SERVER:8090/api/values/5

In CircleCI 1.0, I used to be able to do this all day

test:
  override:
    - docker run -itd -p 8080:80 my-container; sleep 10
    - curl --retry 10 --retry-delay 5 -v http://localhost:8080
    - curl --retry 10 --retry-delay 5 -v http://localhost:8080/home

Any insights, here, would be greatly appreciated.

Thanks,
-wp


#2

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.