awslabs / amazon-ecr-credential-helper

Automatically gets credentials for Amazon ECR on docker push/docker pull

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

systemd unit start - no basic auth credentials

pctj101 opened this issue · comments

docker pull works great in normal interactive shell

However, docker pull does not work in systemd unit. This is on CoreOS-stable-1855.4.0-hvm (ami-086eb64b7f4485a72)

[Unit]
Description=Run Some Service
After=docker.service

[Service]
User=core
TimeoutStartSec=0
ExecStartPre=/usr/bin/docker pull 1234.dkr.ecr.ap-northeast-1.amazonaws.com/myservice
ExecStart=/usr/bin/docker run  1234.dkr.ecr.ap-northeast-1.amazonaws.com/myservice

[Install]
WantedBy=multi-user.target

results in

Oct 17 12:28:20 ip-172-16-135-173 docker[1765]: Error response from daemon: Get https://1234.dkr.ecr.ap-northeast-1.amazonaws.com/v2/myservice/manifests/latest: no basic auth credentials
Oct 17 12:28:20 ip-172-16-135-173 systemd[1]: myservice.service: Control process exited, code=exited status=1

Normally docker pull works, with binary installed in /opt/bin (default part of path for interactive shells)

$ which docker-credential-ecr-login 
/opt/bin/docker-credential-ecr-login

solved by adding to [Service]
Environment="PATH=/opt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"