I am big fun of Docker, it makes development fast and reliable. Since I am a big fan, I am trying to use docker whenever I get the chance.
I have a many automated jobs running on daily basis. I have used to setup these cron jobs by running ansible scripts against my EC2 instance(s).
Lately I have tried to switch these cron jobs to a docker container and run them on ECS service.
ECS
is an AWS service that let you run your docker containers on EC2 instance. Also they provide another service called ECR
, which allows you to store your docker images, it is very similar to docker hub.
The setup is fairly easy I will share with you my Docker file, All you have to do, is to change the cron jobs upload your docker image and run it.
Setup
Dockerfile
Note : Make sure your cron job exists and has all the jobs you want to run
Build & Push
Now let’s build the docker image.
Now the image has been built we have to push it to ECR. Assuming you are familiar with AWS. Otherwise you can run the docker image anywhere and you are ready to go.
First Make sure you have AWS cli installed and have your AWS profile setup (check ~/.aws/).
- Login to ECR service (depending on your region)
- Create your repository
- Tag your image so you can push the image to this repository
Now your image on ECR, you can easily run it using ECS tasks. I will explain this part in another post.
Comments