Skip to content

'link' parameter does not work with client.containers.create(...) #1857

Open
@kocsob

Description

If I set the 'links' parameter it does not give an error, but it does not work as well. I think this issue comes from: https://stackoverflow.com/questions/37144357/link-containers-with-the-docker-python-api

But in High level API I cannot put the host_config parameter in create(), because

TypeError: run() got an unexpected keyword argument 'host_config'.

SDK version, Docker version and python version

docker==2.7.0

Python 3.6.4

Client:
 Version:	17.12.0-ce
 API version:	1.35
 Go version:	go1.9.2
 Git commit:	486a48d270
 Built:	Fri Dec 29 12:13:10 2017
 OS/Arch:	linux/amd64
 Experimental:	false

Server:
 Engine:
  Version:	17.12.0-ce
  API version:	1.36 (minimum version 1.12)
  Go version:	go1.9.2
  Git commit:	486a48d270
  Built:	Fri Dec 29 12:13:27 2017
  OS/Arch:	linux/amd64
  Experimental:	false

If possible, steps or a code snippet to reproduce the issue:

import docker
import docker.errors

NETWORK_NAME = 'test-network'
CONTAINER_NAME = 'test'
DOMAIN = 'example.com'

client = docker.from_env()

try:
    network = client.networks.get(NETWORK_NAME)
except docker.errors.NotFound:
    network = client.networks.create(NETWORK_NAME)

links = {CONTAINER_NAME: CONTAINER_NAME + '.' + DOMAIN}

container = client.containers.create(
    image='alpine:latest',
    command='/bin/sleep 3600',
    network=network.name,
    name=CONTAINER_NAME,
    links=links,
)
container.start()

The same functionality with docker command:

 docker run --name=test --link=test:test.example.com --network test-network alpine:latest /bin/sleep 3600

Relevant diff of the docker inspect:

              "Networks": {
                  "test-network": {
                      "IPAMConfig": null,
 -                    "Links": null,
 +                    "Links": [
 +                        "test:test.example.com"
 +                    ],

The problem is that "Link" is 'null'. This works good with command line '--link' parameter.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions