Reputation: 4852
Given below is my cloud-watch-test.service systemd unit file. I need to change the log driver on my container to be aws log driver. But some syntax error is failing to resolve.
[Unit]
Description=My Docker Service
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
Restart=on-failure
ExecStartPre=-/usr/bin/docker kill ravDocker
ExecStartPre=-/usr/bin/docker rm -f ravDocker
ExecStartPre=-/usr/bin/docker pull myImage:latest
ExecStartPre=-/bin/sh -c "/bin/docker rmi $(docker images --quiet --filter 'dangling=true')"
ExecStart=/usr/bin/docker run --log-driver=awslogs --log-opt awslogs-region=ap-southeast-1 --log-opt awslogs-group=test --log-opt awslogs-datetime-format='\\[%b %d, %Y %H:%M:%S\\]' --log-opt tag='{{.Name}}/{{.ID}}' --net=host --name ravDocker myImage:latest
ExecStop=/usr/bin/docker stop ravDocker
[Install]
WantedBy=multi-user.target
Given below is my systemctl statu output,
/etc/systemd/system/cloud-watch-test.service:13: Failed to resolve unit specifiers on awslogs-datetime-format=\[%b %d, %Y %H:%M:%S\]:
Note: When I run this straightly as a docker command it works fine. Any help is appreciated.
Upvotes: 0
Views: 1353
Reputation: 295914
Double up your %
signs to stop systemd from trying to interpret them itself.
Thus, the parameter causing the error could become:
--log-opt 'awslogs-datetime-format=\[%%b %%d, %%Y %%H:%%M:%%S\]'
Upvotes: 2
Reputation: 4852
Based on the below answer, the solution worked that for me contains backslashes which needs to be added due to an issue in docker aws log driver commands. More info on the reason behind adding backslashes can be found in here. The correct command is given below,
--log-opt awslogs-datetime-format='\[%%b %%d, %%Y %%H:%%M:%%S\]'
Upvotes: 0