Docker deploy_container sends literal None command when command is omitted

Aperta Adatta ai principianti
#2,226 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
docker, python
Ambito
cloud

Direzione di ricerca

Inizia in DockerContainerDriver.deploy_container() in libcloud/container/drivers/docker.py, dove command = shlex.split(str(command)) viene eseguito prima di creare il payload di creazione. Esegui lo script di riproduzione nell’issue per confermare che Cmd è ['None'] quando l’argomento viene omesso. Il lavoro sarà completato quando omettere command o passare None lascerà Cmd fuori dalla richiesta e le stringhe esplicite come 'echo "hello world"' continueranno a essere suddivise in argomenti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
2.1k
Fork
935
Merge medio
5g 3h
PR unite (30g)
15

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/libcloud

Tutte le issue di apache/libcloud

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.