Docker container using Machine executor

Hi Team,

I am trying to access my spring boot application using docker container and that I am trying to do using Circle CI 2.0. I have read some discussions on this forum that there are some issues using setup_remote_docker and even I have also tried it is not working and I am not able curl to the localhost.

Now that I am using machine executor, I am able to curl to the localhost and get a response, but that is only if I am doing ssh to the machine. However, this is not working from the config.yml file. curl is not giving me correct response, even though the container is up and running.

Please see below my config.yml and the corresponding error -

version: 2
jobs:
  build:
    machine: true
    working_directory: ~/rbsmicroservices/services/productservice
    environment:
      TEST_REPORTS: /tmp/test-reports
      HOST_PORT: 8190
      CONTAINER_PORT: 8190
      SERVICE_NAME: productservice
    steps:
      - checkout:
          path: ~/rbsmicroservices
      - run: mvn clean install
      - run: |
          docker image build -t microservices/${SERVICE_NAME} .
          docker run -d -p ${HOST_PORT}:${CONTAINER_PORT} --name ${SERVICE_NAME} microservices/${SERVICE_NAME}
          docker ps -all
          sleep 10
          curl --retry 10 --retry-delay 5 -v http://localhost:8190/productIds?id=2
          curl -s -o /dev/null -I -w "%{http_code}" http://localhost:8190/productIds?id=2

Error -

CONTAINER ID        IMAGE                          COMMAND                  CREATED                  STATUS                  PORTS                    NAMES
6e4f38c792e0        microservices/productservice   "/usr/bin/java -ja..."   Less than a second ago   Up Less than a second   0.0.0.0:8190->8190/tcp   productservice
*** Hostname was NOT found in DNS cache**
***   Trying 127.0.0.1...**
*** Connected to localhost (127.0.0.1) port 8190 (#0)**
**> GET /productIds?id=2 HTTP/1.1**

**> User-Agent: curl/7.35.0**

**> Host: localhost:8190**

**> Accept: */***

**> **

*** Recv failure: Connection reset by peer**
*** Closing connection 0**
**curl: (56) Recv failure: Connection reset by peer**
**Exited with code 56**

However, when I am ssh to the machine, I am able to curl on the localhost and getting a 200 response.

Could you please help me here, what details are wrong in my config.yml file and why I am unable to curl to the local host.

Thanks, Sujit

1 Like

@halfer I have now formatted correctly. Please see if it is ok now.

It looks like you’ve done everything right on the outside. I was going to recommend a sleep delay, but you already have that.

I’d suggest a few things to try:

  • Write the simplest possible endpoint in your API that you can call, and try that. Maybe your real endpoints are failing because of an internal server error
  • Add some logging in your container and then query that before your build exits
  • Run a ps aux inside your container from the build machine (using docker exec) to see if the listener is still alive

@halfer I don’t think there is any issue in the endpoint as I am able to curl that in the machine itself. Not sure why it is not giving me the results when the curl is invoked from config.yml. However, the docker commands are working in both scenarios.

See the output after I am logging to the machine by doing the ssh.

UKLOMACSPTK:rbsmicroservices sptk$ ssh -p 54782 35.231.213.146

circleci@default-f67731db-7714-45e3-a475-accd895009fd:~$ docker ps -a
CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS              PORTS                    NAMES
7fece97737c9        microservices/productservice   "/usr/bin/java -ja..."   35 seconds ago      Up 34 seconds       0.0.0.0:8190->8190/tcp   productservice
circleci@default-f67731db-7714-45e3-a475-accd895009fd:~$ curl --retry 10 --retry-delay 5 -v http://localhost:8190/productIds?id=2
* Hostname was NOT found in DNS cache
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8190 (#0)
> GET /productIds?id=2 HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:8190
> Accept: */*
> 
< HTTP/1.1 200 
< X-Application-Context: product:docker:8190
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Date: Fri, 29 Jun 2018 08:15:12 GMT
< 
* Connection #0 to host localhost left intact
[3,4,5]circleci@default-f67731db-7714-45e3-a475-accd895009fd:~$ curl -s -o /dev/null -I -w "%{http_code}" http://localhost:8190/productIds?id=2
200circleci@default-f67731db-7714-45e3-a475-accd895009fd:~$ curl -X http://localhost:8190/productIds?id=2
curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information
circleci@default-f67731db-7714-45e3-a475-accd895009fd:~$ curl http://localhost:8190/productIds?id=2
[3,4,5]circleci@default-f67731db-7714-45e3-a475-accd895009fd:~$

What is this error, and is it worth looking into?

I don’t know if that helps, since it works in SSH already. See my suggestions above - try them when it fails.

@halfer I managed to resolve the issue by increasing the sleep time. I verified this from the docker logs that my spring boot application is taking 16-20s to be up.
Thanks for your suggestion for verifying the logs.

1 Like

Excellent work :slight_smile:

For your new question, please remove it from the above post, by editing the post. You can then post that material in a new question, with a suitable title, so that the problem is more visible to all readers. There are some Markdown formatting issues anyway to repair (the error logs) so please do that too. Thanks!

Thanks @halfer

I have now created a new post for this, please see the below link -

1 Like

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