Wennn
Wennn

Reputation: 129

How to use docker remote api to create a container using another container's network namespace

I can run the following command to make a container using another container's network namespace:

docker run -it --net=container:<container_name> ubuntu:14.04

After running it, the two container have the same IP address. I want to know how to use the docker remote api or other client api to do it.

My docker server&client version is 1.10.3

Upvotes: 1

Views: 1761

Answers (1)

thaJeztah
thaJeztah

Reputation: 28987

docker run is basically docker create followed by docker start. You can find the documentation for the /containers/create endpoint in the API reference.

The property you're looking for is the NetworkMode in the HostConfig;

NetworkMode - Sets the networking mode for the container. Supported standard values are: bridge, host, none, and container:<name|id>. Any other value is taken as a custom network’s name to which this container should connect to.

Upvotes: 5

Related Questions