Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking Containers via Docker Remote API

Tags:

docker

I'm trying to link a child mongo container to a parent node container using the Docker remote API v1.7.

I see the Links property in HostConfig which I'm guessing is passed to the
POST /containers/<id>/start request like

{
  "Links": ["<container-name>:<alias>", ...]
}

I don't see how to name the mongo container to use when starting the node container. Is there an API analogy to the CLI -name flag for docker run?

Do I need to make a separate GET /containers/<id>/json request and live with the auto-generated name?

like image 810
twirkman Avatar asked Dec 03 '13 23:12

twirkman


People also ask

Can Docker containers communicate with each other?

A Docker network lets your containers communicate with each other. If you are running more than one container, you can let your containers communicate with each other by attaching them to the same network.

What is Docker remote API?

Docker Engine API (1.41) It is the API the Docker client uses to communicate with the Engine, so everything the Docker client can do can be done with the API. Most of the client's commands map directly to API endpoints (e.g. docker ps is GET /containers/json ).


1 Answers

In the current (1.8) API, the -name flag is passed as a query string to POST /v1.8/containers/create – i.e. like this:

POST /v1.8/containers/create?name=redis_ambassador

(POST body left out for brevity)

I figured this out by using Geoffrey Bachelet's excellent suggestion of using socat as a proxy for all of my docker CLI commands using the following commands:

# on one terminal  
sudo socat -t100 -v UNIX-LISTEN:/tmp/proxysocket.sock,mode=777,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sock

# on a second terminal  
export DOCKER_HOST="unix:///tmp/proxysocket.sock"  

Subsequent docker cli commands will be proxied through socat and their CLI calls will be displayed on the other terminal

like image 89
Joshua Conner Avatar answered Sep 19 '22 05:09

Joshua Conner