Docker GUI-mini: "AttributeError: 'ContainerCollection' object has no attribute 'remove'"

Приложение docker GUI-mini на Python. Контейнер создаетя, но при удалении - ошибка:

AttributeError: 'ContainerCollection' object has no attribute 'remove'

Код Python:

import docker  
from flask import Flask, render_template, request, url_for, flash, redirect  
app = Flask(__name__)  
@app.route('/')  
def index():  
    client = docker.from_env()  
    lists = client.containers.list(all=True)  
    return render_template('index.html', lists=lists)  
@app.route('/create')  
def create():  
    client = docker.from_env()  
    client.containers.create(image='hello-world')  
    return render_template('index.html')  
@app.route('/delete')  
def delete(container_id=None):  
    client = docker.from_env()  
    client.containers.remove(container_id, force=True)  
    return redirect(url_for('index'))

Фрагмент HTML:

{% for item in lists %} <tr><td><h4>{{ item['name'] }}</h4></td>
 <td><h4>{{ item['short_id'] }}</h4></td>
 <td> <a href="/delete"><button class="btn btn-danger btn-xs">Delete</button></a></td> </tr>
{% endfor %} </tbody>  </table>
<a class="nav-link" href="/create"><button class="btn btn-secondary">add_container</button></a>
{% endblock %}

Ответы (2 шт):

Автор решения: CrazyElf

Судя по документации, метод remove есть только у объекта Container, а у ContainerCollection его нет. Видимо, надо делать так:

client.containers.get(container_id).remove(force=True)
→ Ссылка
Автор решения: gil9red

Погуглил по docker-py и, действительно, у объектов типа ContainerCollection нет метода remove, но оно есть у типа Container.

Думаю, правильно будет так:

client.containers.get(container_id).remove(force=True)
→ Ссылка