编写service文件
sudo vim /usr/lib/systemd/system/docker-login.service
[Unit]
Description=docker auto login
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=docker login -u username -p password
ExecStop=docker logout
[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
测试
sudo systemctl start docker-login.service
sudo cat /root/.docker/config.json
{
"auths": {
"image.domain.com": {
"auth": "YWRtaW46TW5acjM5SGQwWUB2U2kmeg=="
}
},
"HttpHeaders": {
"User-Agent": "Docker-Client/19.03.8 (linux)"
}
}
sudo systemctl stop docker-login.service
sudo cat /root/.docker/config.json
{
"auths": {},
"HttpHeaders": {
"User-Agent": "Docker-Client/19.03.8 (linux)"
}
}
sudo systemctl enable docker-login.service