I was able to solve the problem by following these steps:
build the docker images as part of the circleci config file instead of having them in docker-compose.
Then, instead of using localhost, I used the docker image name as the address (e.g. postgres, hasura).