Backport of important parts of https://github.com/ansible-collections/community.docker/pull/48 to stable-1.