profile
viewpoint

Ask questionsInternal server error ("Device is Busy") for docker client images.remove()

docker.version '4.0.2'

I'm having a problem where calls to images.remove() results in an internal server error. I'm using version 4.0.2 of docker-py.

Below is some context to show where I'm calling images.remove(). In the interest of brevity, I'm leaving out some of the variable declarations and helper functions you see referenced below. This is in a script called replicate_image.py.

client = docker.DockerClient(base_url=dockerConfig.url, version='auto')
client.login(
    username=DOCKER_ECR_USER_NAME,
    password=password,
    email=None,
    reauth=True,
    registry=registry)

img = client.images.pull(srcRepoConfig.uri)
dstRepo = dstRepoConfig.repository()
imageTag = srcRepoConfig.image_tag()
img.tag(repository=dstRepo, tag=imageTag)
dstTag = dstRepoConfig.image_tag()
img.tag(repository=dstRepo, tag=dstTag)
client.images.push(repository=dstRepo)
client.images.remove(img.id, force=True)

And here's the stack trace.

2019-10-26 15:55:52,536 :INFO : pushing image to dst repository. uri:<my-ecr-repository>
2019-10-26 15:55:53,318 :INFO : Pushed image successfully. Deleting local copy of image: sha256:
Traceback (most recent call last):
  File "/lib/python3.6/site-packages/docker/api/client.py", line 261, in _raise_for_status
    response.raise_for_status()
  File "/lib/python3.6/site-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: http://127.0.0.1:4243/v1.24/images/sha256:6b65ccc2e1ae6e611880d2b21e94d6ef4c999860ee19a20eebce71297b32100e?force=True&noprune=False

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/lib/python3.6/site-packages/ecr_copier/replicate.py", line 58, in replicate_image
    client.images.remove(img.id, force=True)
  File "/lib/python3.6/site-packages/docker/models/images.py", line 462, in remove
    self.client.api.remove_image(*args, **kwargs)
  File "/lib/python3.6/site-packages/docker/utils/decorators.py", line 19, in wrapped
    return f(self, resource_id, *args, **kwargs)
  File "//lib/python3.6/site-packages/docker/api/image.py", line 494, in remove_image
    return self._result(res, True)
  File "/lib/python3.6/site-packages/docker/api/client.py", line 267, in _result
    self._raise_for_status(response)
  File "/lib/python3.6/site-packages/docker/api/client.py", line 263, in _raise_for_status
    raise create_api_error_from_http_exception(e)
  File "/lib/python3.6/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
    raise cls(e, response=response, explanation=explanation)
docker.errors.APIError: 500 Server Error: Internal Server Error ("Device is Busy")
Script <my_script> failed with an exit status of 1.

    Failed with exit code 1

Exit Status: 1
 
Signal: 0
 
Core Dumped: 0
docker/docker-py

Answer questions shin-

That's an error at the server level (in the Docker daemon) - the SDK is behaving appropriately here by raising.

Related questions

docker.errors.DockerException: Error while fetching server API version: Timeout value connect was Timeout(connect=60, read=60, total=None), but it must be an int or float. hot 44
pip install in virtualenv breaks virtualenv hot 42
AttributeError: 'module' object has no attribute 'PY34' hot 39
pip install in virtualenv breaks virtualenv hot 34
'ImportError: No module named ssl_match_hostname' upon 'import docker' in a Python script hot 30
Not compatible with pywin32 version 225 hot 18
docker client on Python 3.8 is not working hot 11
TypeError: load_config() got an unexpected keyword argument 'config_dict' hot 7
Issue with creating a docker container while inside a docker container hot 7
docker client on Python 3.8 is not working hot 7
"addgroup: The GID `20' is already in use." when running `make docs`
build function gives broken pipe error
ResourceWarning: unclosed <socket.socket>
How to create a mount point in a docker container. hot 4
Support for stacks hot 4
Github User Rank List