Skip to content

Instantly share code, notes, and snippets.

@tpai
Last active January 24, 2024 10:35
Show Gist options
  • Save tpai/309b503e3cd0a63b100c5334754209ee to your computer and use it in GitHub Desktop.
Save tpai/309b503e3cd0a63b100c5334754209ee to your computer and use it in GitHub Desktop.
Upgrading Docker-Compose from V1 to V2 with Ansible

install docker compose v2

mkdir -p /usr/local/lib/docker/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.24.2/docker-compose-linux-x86_64 -o /usr/local/lib/docker/cli-plugins/docker-compose
sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
docker compose version

Ref: https://docs.docker.com/compose/install/linux/#install-the-plugin-manually

install Docker SDK for Python

pip install docker

Ref: https://galaxy.ansible.com/ui/repo/published/community/docker/docs/

upgrade Ansible collection community.docker to 3.6.0+

# upgrade installed collection
$ ansible-galaxy collection install -U community.docker

$ ansible-galaxy collection verify community.docker
Downloading https://galaxy.ansible.com/...
Verifying 'community.docker:3.6.0'.
Installed collection found at '/root/.ansible/collections/ansible_collections/community/docker'

Ref: https://docs.ansible.com/ansible/latest/cli/ansible-galaxy.html#cmdoption-ansible-galaxy-collection-install-U

reconfigure Ansible playbook

- community.docker.docker_compose
+ community.docker.docker_compose_v2

Ref: https://galaxy.ansible.com/ui/repo/published/community/docker/content/module/docker_compose_v2/#examples

 - hosts: all
   become: yes
   become_method: sudo
+  collections:
+    - community.docker
   roles:
     - grafana

Ref: https://github.com/ansible-collections/community.docker?tab=readme-ov-file#using-this-collection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment