I'm setting up a continuous deployment process with CircleCI, targeting Google Container Engine. I'm following this documentation, alongside this example.
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
This is a simple test, verifying that my docker image is able to answer to an http request. 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.
A way of doing this would be first to start your container with a name as well:
docker run -d -p 3000:3000 -e "SECRET_KEY_BASE=${SECRET_KEY}" --name ${MAIN_CONTAINER_NAME} eu.gcr.io/${PROJECT_NAME}/${MAIN_CONTAINER_NAME}:latest; sleep 10
Then replace the curl task with this run of a curl container:
docker run --network container:${MAIN_CONTAINER_NAME} appropriate/curl --retry 10 --retry-delay 5 -v http://172.17.0.2
Additional explanations:
--network container:${MAIN_CONTAINER_NAME}
- will attach the curl container to the network of the MAIN_CONTAINER_NAME container, which by default would be in the range of 172.17.0.0/16
http://172.17.0.2
- since the MAIN_CONTAINER_NAME is the first container created within that Docker network, it will have the 172.17.0.2
IP address, with the host machine being on .1
and the curl container on .3