xxxxxxxxxx
import docker
def stop_container(container_id):
client = docker.from_env()
container = client.containers.get(container_id)
container.stop()
# Replace 'CONTAINER_ID' with the actual ID of the container you want to stop
stop_container('CONTAINER_ID')
xxxxxxxxxx
$ sudo systemctl restart docker.socket docker.service
$ docker rm <container id>
xxxxxxxxxx
import docker
# Create a Docker client
client = docker.from_env()
# Get the running container by its ID or name
container = client.containers.get('container_id_or_name')
# Stop the container
container.stop()