Configuring the test of Docker container hosted on GoogleContainerEngine

I’m setting up a continuous deployment process with CircleCI, targeting Google Container Engine. I’m following this documentation.

I’m stucked at this stage:

test:
  post:
    - docker run -d -p 3000:3000 -e "SECRET_KEY_BASE=${SECRET_KEY}" eu.gcr.io/${PROJECT_NAME}/${MAIN_CONTAINER_NAME}:latest; sleep 10
    - curl --retry 10 --retry-delay 5 -v http://localhost:3000

I get this result after the curl:

* Rebuilt URL to: http://localhost:3000/
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* connect to 127.0.0.1 port 3000 failed: Connection refused
* Failed to connect to localhost port 3000: Connection refused
* Closing connection 0
curl: (7) Failed to connect to localhost port 3000: Connection refused

curl --retry 10 --retry-delay 5 -v http://localhost:3000 returned exit code 7

The same command works if i’m trying it in my local shell. I get this result locally:

* Rebuilt URL to: http://localhost:3000/
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 3000 (#0)
> GET / HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.51.0
> Accept: */*
>
* Curl_http_done: called premature == 0
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server

I don’t get the reason of this difference.

(I also asked this question on stackoverflow)

I just connected in ssh to the container after a build, and docker ps returns:

CONTAINER ID        IMAGE                                               COMMAND                  CREATED             STATUS              PORTS                    NAMES
f9ff1843ec8b        eu.gcr.io/[PROJECT_NAME]/[MAIN_CONTAINER_NAME]:latest   "/bin/sh -c 'bundle e"   2 minutes ago       Up 2 minutes        0.0.0.0:3000->3000/tcp   tiny_wescoff

exactly what I expected, which leave me even more confused.

I couldn’t curl in ssh either, as expected.

I’m facing the same issue:

#!/bin/sh -eo pipefail
docker run -d --env-file .env.sample -p 3000:3000 eu.gcr.io/${GOOGLE_PROJECT_NAME}/${IMAGE_NAME}:${VERSION}.${CIRCLE_BUILD_NUM}; sleep 10
curl --retry 10 --retry-delay 5 -v http://localhost:3000/ping
c84ff6a270d2d8748c9bb21a25eb2f60c0d52ad08f259b511374100ca86db45e
*   Trying 127.0.0.1...
* TCP_NODELAY set
* connect to 127.0.0.1 port 3000 failed: Connection refused
*   Trying ::1...
* TCP_NODELAY set
* Immediate connect fail for ::1: Network unreachable
*   Trying ::1...
* TCP_NODELAY set
* Immediate connect fail for ::1: Network unreachable
* Failed to connect to localhost port 3000: Connection refused
* Closing connection 0
curl: (7) Failed to connect to localhost port 3000: Connection refused
Exited with code 7

Can someone please take a look at this? I’m using circleci 2.0. With 1.0 the same command works perfectly.

@RemyMaucourt this is how i solved the problem:

- run:
      name: Test Docker container
      command: |
        docker run -d --name ${IMAGE_NAME} --env-file .env.sample -p 3000:3000 eu.gcr.io/${GOOGLE_PROJECT_NAME}/${IMAGE_NAME}:${VERSION}.${CIRCLE_BUILD_NUM}
        docker exec ${IMAGE_NAME} curl --retry-delay 5 --retry 10  --retry-connrefused http://localhost:3000/ping

This does require you to install curl in your image though :frowning: