I am having issues when trying to connect to a docker-compose network from inside of a container. These are the files I am working with. The whole thing runs when I
FROM docker/compose:latest WORKDIR . # EXPOSE 8228 RUN apk update RUN apk add py-pip RUN apk add jq RUN pip install anchorecli COPY dockertest.sh ./dockertest.sh COPY docker-compose.yaml docker-compose.yaml CMD ["./dockertest.sh"]
services: # The primary API endpoint service engine-api: image: anchore/anchore-engine:v0.6.0 depends_on: - anchore-db - engine-catalog #volumes: #- ./config-engine.yaml:/config/config.yaml:z ports: - "8228:8228" .................. ## A NUMBER OF OTHER CONTAINERS THAT ANCHORE-ENGINE USES ## .................. networks: default: external: name: anchore-net
echo "------------- INSTALL ANCHORE CLI ---------------------" engineid=`docker ps | grep engine-api | cut -f 1 -d ' '` engine_ip=`docker inspect $engineid | jq -r '..NetworkSettings.Networks."cws-anchore-net".IPAddress'` export ANCHORE_CLI_URL=http://$engine_ip:8228/v1 export ANCHORE_CLI_USER='user' export ANCHORE_CLI_PASS='pass' echo "System status" anchore-cli --debug system status #This line throws error (see below)
#!/bin/bash docker build . -t anchore-runner docker network create anchore-net docker-compose up -d docker run --network="anchore-net" -v //var/run/docker.sock:/var/run/docker.sock anchore-runner #docker network rm anchore-net
INFO:anchorecli.clients.apiexternal:As Account = None
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): 172.19.0.6:8228
Error: could not access anchore service (user=user url=http://172.19.0.6:8228/v1): HTTPConnectionPool(host=’172.19.0.6′, port=8228): Max retries exceeded with url: /v1
(Caused by NewConnectionError(‘: Failed to establish a new connection: [Errno 111] Connection refused’,))
- run.sh builds container image and creates network
- the container has an entrypoint script, which does multiple things
- firstly, it brings up the docker-compose network as detached FROM inside the container
- secondly, nstalls anchore-cli so I can run commands against container network
- lastly, attempts to get a system status of the anchore-engine (d.c network) but thats where I am running into HTTP request connection issues.
I am dynamically getting the IP of the api endpoint container of anchore-engine and setting the URL of the request to do that. I have also tried passing those variables from command line such as:
anchore-cli --u user --p pass --url http://$engine_ip/8228/v1 system status but that throws the same error.
For those of you who took the time to read through this, I highly appreciate any input you can give me as to where the issue may be lying. Thank you very much.