# Use docker\_login and docker\_compose\_v2

**URL:** <https://forum.ansible.com/t/use-docker-login-and-docker-compose-v2/38769>\
**Category:** Ansible Project\
**Tags:** ubuntu, aws\
**Created:** [April 30, 2024, 7:13pm UTC](https://forum.ansible.com/t/use-docker-login-and-docker-compose-v2/38769 "2024-04-30T19:13:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emilio\_Botero](https://avatars.discourse-cdn.com/v4/letter/e/49beb7/32.png) [@Emilio\_Botero](https://forum.ansible.com/u/Emilio_Botero)\
**Post date:** [April 30, 2024, 7:13pm UTC](https://forum.ansible.com/t/use-docker-login-and-docker-compose-v2/38769/1 "2024-04-30T19:13:37Z")

</div>

Hi,  
I’m trying to authenticate to my private registry (AWS ECR) and use docker compose to start my container. I have something like this:

- name: Create AWS credentials file  
ansible.builtin.copy:  
dest: “{{ user\_details.home }}/.aws/credentials”  
content: |  
[default]  
aws\_access\_key\_id = {{ aws\_access\_key\_id }}  
aws\_secret\_access\_key = {{ aws\_secret\_access\_key }}  
mode: “0600”  
force: true  
register: aws\_credentials\_created

- name: Authenticate to AWS  
ansible.builtin.command: “aws ecr get-login-password --region {{ aws\_region }} --profile default”  
register: ecr\_login\_password  
changed\_when: true

- name: Docker login to AWS ECR  
community.docker.docker\_login:  
state: present  
username: “AWS”  
password: “{{ ecr\_login\_password.stdout }}”  
reauthorize: true # what does this do?  
registry\_url: “{{ registry\_url }}”  
changed\_when: true

- name: Docker compose container  
community.docker.docker\_compose\_v2:  
project\_src: “{{ user\_details.home }}/{{ path\_to\_repos }}/container”  
state: “present”

I can’t get the compose task to correctly pull the image from my private registry given that I authenticated in the task before. Is it even possible to do this? Setting aside security best practices for the moment, how do I get the compose task to pull the image? The compose file has a pull policy of “always”, so when the task tries to do like “docker compose up”, it will try to pull the image.

See the error here:  
fatal: [18.208.187.13]: FAILED! =\> {“actions”: [{“id”: “my-image”, “status”: “Pulling”, “what”: “service”}], “changed”: false, “cmd”: “/snap/bin/docker compose --ansi never --progress plain --project-directory /home/ubuntu/docker/my-image up --detach --no-color --quiet-pull --”, “containers”: , “images”: , “msg”: “Error when processing my-image: Error response from daemon: Head "[https://account-id.dkr.ecr.region.amazonaws.com/v2/my-image/manifests/latest\](https://account-id.dkr.ecr.region.amazonaws.com/v2/my-image/manifests/latest%5C)”: no basic auth credentials", “rc”: 18, “stderr”: " my-image Pulling \n my-image Error \nError response from daemon: Head "[https://account-id.dkr.ecr.region.amazonaws.com/v2/my-image/manifests/latest\](https://account-id.dkr.ecr.region.amazonaws.com/v2/my-image/manifests/latest%5C)“: no basic auth credentials\n”, “stderr\_lines”: [" my-image Pulling ", " my-image Error “, “Error response from daemon: Head "[https://account-id.dkr.ecr.region.amazonaws.com/v2/my-image/manifests/latest\](https://account-id.dkr.ecr.region.amazonaws.com/v2/my-image/manifests/latest%5C)”: no basic auth credentials”], “stdout”: “”, “stdout\_lines”: }

Thanks,

Emilio

---

<div class="post-metadata">

**Author:** ![Emilio\_Botero](https://avatars.discourse-cdn.com/v4/letter/e/49beb7/32.png) [@Emilio\_Botero](https://forum.ansible.com/u/Emilio_Botero)\
**Post date:** [May 1, 2024, 6:42pm UTC](https://forum.ansible.com/t/use-docker-login-and-docker-compose-v2/38769/2 "2024-05-01T18:42:26Z")

</div>

@felixfontein any pointers?
