Here is my dockerfile.
FROM 796678920264.dkr.ecr.us-west-1.amazonaws.com/myproject/base:latest
COPY /* /
RUN python awslogs-agent-setup.py --non-interactive -c /aws-log.myservice.cfg --region us-west-2
CMD ["/start.sh"]
I use the dockerfile to build images that will be used in both dev and production environment. The behaviour is determined by an env variable. i.e. I will do something like this to start a docker container: docker run -e ENV=dev -ti myservice
One issue with this dockerfile is that: the logs in both dev and prod are sent to the same cloudwatch log in the region us-west-2
.
Is there anything I can do to change the region for dev environment to a different value when a docker container is started? Preferably it should be controlled by the same environment variable.
Best Answer
I add and call the following script in the main CMD script
The script must be called before the aws log service is started.