'link' parameter does not work with client.containers.create(...)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.7k
- Avg merge
- 13d 8h
- Merged PRs (30d)
- 2
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the high-level client.containers.create path and compare how its links argument is translated with the docker run --link behavior shown in the report. Reproduce the example against the stated Docker and SDK versions, then verify that inspecting the created container shows the expected network Links entry.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100