Accessing host's api from inside a container

I’m trying to make a build env with docker and i want to make this automatic. i’ve written a custom go binary to handle build stuff and i’ve built an image which has the go binary, maven and java8 sdk installed.

The steps that binary does are:

  • How to add PRE deployment script to AWS Elastic Beanstalk Docker EC2 instance, custom AMI not working
  • Using a shared MySQL container
  • Docker mysql cant connect to container
  • mounting data volumes to another container
  • Citrus-Framework: How to start/stop docker container in doFinally()?
  • Getting code inside the Docker container
    • Clone a git repo
    • Run build command
    • Extract build artifacts to host. (which hasnt done yet.)

    I’m passing repo url as parameter to binary while running container and it does build.

    But the problem is i need those artifacts in order to run builted app.

    I know i can use volumes, but i dont want to use them because when build has done volumes are becoming dangle and it needs a job for deleting those dangling volumes.

    I thought i can create an api for saving files into host (that means i have to run that api inside host machine) and my custom go binary can send files to the api and api will do the saving.

    But when it comes to calling host from inside a container i’ve got a problem. i’m getting connection refused to port xx error.

    Is there a better way to do it , or should i change my approach?

  • Cannot connect to PostgreSQL in Docker through PHP
  • Docker compose with Drone and Gitlab, Gitlab errors “The redirect URI included is not valid.”
  • How can I make `avahi` work outside when `netatalk` running inside docker on `ubuntu`?
  • Edit configuration file for running Docker instance of Kong
  • Development workflow for docker-compose: run a dev-version container
  • SSL: how to get access to HTTPS in docker container
  • 2 Solutions collect form web for “Accessing host's api from inside a container”

    found an answer on accessing-host-machine-as-localhost-from-a-docker-container-thats-also-inside

    Running container with --add-host option is the answer.

    While you could use

    docker cp CONTAINER:SRC_PATH DEST_PATH
    

    to get the files out of your container, I still believe using a volume is the better idea. Instead of using an anonymous volume use a named one:

    docker run -v /local/host/dir:/build/output YOURIMAGE
    

    This allows you to pick up the artefacts on your host from the /local/host/dir

    https://docs.docker.com/engine/tutorials/dockervolumes/#locate-a-volume

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.