How to curl running container



I am trying to do the following:

- setup_remote_docker:
      docker_layer_caching: true
- run:
      name: "Build image"
      command: docker build --rm -t andreacab/commowand-api-gin:$CIRCLE_SHA1 .
- run:
      name: "Check image runs"
      command: |
        docker run -d -p 8084:80 --name commowand andreacab/commowand-api-gin:$CIRCLE_SHA1
        docker exec commowand curl --retry 10 --retry-connrefused http://localhost:8084

But this fails with the following output:

Error response from daemon: Container 7bb319d26c0d7ea9f0953285b7b9962a4ad1e1d3048ab1785d8c3d7e1ed346fc is not running
Exited with code 1

I have been following the indication on the circleci documentation -> Accessing services and don’t get why it wouldn’t be working, any idea is appreciated!


What is the entrypoint of this container?


The entrypoint is ENTRYPOINT [/commowand-api-gin]
It is just a binary file. I had an error in the app which made the container exits which I noticed once I tried running it locally and the error was displayed in stdout (not the case on circleci, not sure why). I also realized my image had not curl installed. Sorry I am new to docker.

Now the container runs properly and I am trying to curl it from a secondary container, both being part of the same network, like so:

$ docker network create cmwd-net
$ docker run --network cmwd-net -d -p 8084:80 --name web andreacab/commowand-api-gin:$CIRCLE_SHA1


docker inspect cmwd-net

I can see that the container web is part of the network with the right name.
Also with:

$ docker container ls

Shows the container web is running.

Then I do:

$ docker run --network cmwd-net -i -t alpine:3.7 apk add --no-cache curl && curl http://web:8084/ping

And get the following error from curl:

curl: (6) Could not resolve host: web


It looks like that should work - you have joined each container to a common network, and each container should get a network name equivalent to their container name.

To debug this, I’d suggest a couple of things to try:

  • Get your containers running in Docker Compose - this does the network joining automagically
  • Consider getting each container to run in a long-running fashion without giving them commands to run, and then use SSH to drop into a container you want to exec commands in. This will give you an environment to test stuff in dynamically.
  • Try pinging one container from another using the container’s name - that should work
  • Try getting this working in Docker locally to see if it is a CircleCI-specific issue


Hey Halfer thanks for your message, ssh’ing into it proved it worked!
I did run the second container with the option --entrypoint /bin/sh, ssh’ed into it as suggested, and ran the curl commands in there and perfectly worked. The web host was successfully resolved. It seems the container does not get the host names mapping in /etc/hosts straight away.


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