Docker deploy_container sends literal None command when command is omitted

オープン 初心者向け
#2,226 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
76/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
docker, python
領域
cloud

調査の方向性

libcloud/container/drivers/docker.py の DockerContainerDriver.deploy_container() から始めます。ここでは、create payload が構築される前に command = shlex.split(str(command)) が実行されます。issue の再現スクリプトを実行し、引数を省略したときに Cmd が ['None'] になることを確認します。command を省略するか None を渡したときに Cmd がリクエストから除外され、'echo "hello world"' のような明示的な文字列は引き続き引数に分割される状態になれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Python
スター
2.1k
フォーク
935
平均マージ
5日 3時間
マージ済み PR(30日)
15

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/libcloud のほかの issue

apache/libcloud の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。