Docker deploy_container sends literal None command when command is omitted

Offen Anfängerfreundlich
#2,226 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
76/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
docker, python
Bereich
cloud

Rechercherichtung

Beginne in DockerContainerDriver.deploy_container() in libcloud/container/drivers/docker.py, wo command = shlex.split(str(command)) ausgeführt wird, bevor der Create-Payload erstellt wird. Führe das Reproduktionsskript im Issue aus, um zu bestätigen, dass Cmd ['None'] ist, wenn das Argument weggelassen wird. Fertig ist es, wenn beim Weglassen von command oder bei Übergabe von None Cmd nicht in der Anfrage enthalten ist und explizite Zeichenfolgen wie 'echo "hello world"' weiterhin in Argumente aufgeteilt werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Summary

DockerContainerDriver.deploy_container() turns its default command=None into the literal command ['None'] in the container-create request. Omitting the argument therefore sends an explicit command override rather than leaving the image's default command alone.

The documented Docker example calls deploy_container('tomcat', image) without a command.

Detailed Information

Observed on unchanged trunk 8a0ef6260680625d54fce5093d2315e0926a7dc9, Libcloud 4.0.0.dev0, Python 3.12/Linux. This is a request-serialization reproduction using the actual driver method with API-version negotiation and response transport substituted. No Docker daemon/container was started.

import json
from types import SimpleNamespace
from unittest.mock import patch
from libcloud.container.drivers.docker import DockerContainerDriver
from libcloud.container.base import ContainerImage

with patch.object(DockerContainerDriver, '_get_api_version', return_value='1.24'):
    driver = DockerContainerDriver()
image = ContainerImage('i', 'test-image', 'test-image', 'latest', driver)

for kwargs in ({}, {'command': None}, {'command': ''},
               {'command': 'echo "hello world"'}):
    requests = []
    def request(action, **options):
        requests.append((action, options))
        body = {'Id': 'local-probe'} if action.endswith('/create') else {
            'Id': 'local-probe', 'Name': '/local-probe',
            'Image': 'test-image', 'Status': 'Created', 'Ports': []}
        return SimpleNamespace(object=body)
    driver.connection = SimpleNamespace(request=request, driver=driver)
    driver.deploy_container('local-probe', image, start=False, **kwargs)
    print(kwargs, json.loads(requests[0][1]['data'])['Cmd'])

Output:

{} ['None']
{'command': None} ['None']
{'command': ''} []
{'command': 'echo "hello world"'} ['echo', 'hello world']

The cause is command = shlex.split(str(command)) before building the payload. The optional absent value is converted to text before splitting. Expected: preserve the no-command-override case while retaining parsing of explicit command strings.

Docker's CMD documentation describes the image command as a default, overridden by supplied command arguments. This report establishes the incorrect outgoing Cmd, not a live-daemon startup error or full-suite result. No production code change yet.

AI assistance: ChatGPT helped investigate, reproduce, and draft this report.

Vorherrschende Sprache
Python
Sterne
2.1k
Forks
935
Ø Merge
5 T. 3 Std.
Gemergte PRs (30 T.)
15

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus apache/libcloud

Alle Issues in apache/libcloud

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.