0

I have an AMI in the AwS Marketplace which runs a docker container inside. I want to update the docker container once when the instance is booting the first time. Of course, I can ssh to the instance and update the container but maybe there is an easier way.

thx

Kev
  • 577
  • 1
  • 10
  • 29

1 Answers1

2

I want to update the docker container once when the instance is booting the first time

If you want to have updated docker images then you can put these in your user-data of during launch of the instance.

If you want to update ECS-agent then just put this in the user-data.

docker pull amazon/amazon-ecs-agent:latest

or if you want to update image from ECR then you need to run this but you the instance should have a role to access the ECR.

docker pull account_id.dkr.ecr.us-west-2.amazonaws.com/test:latest

you can find user-data section under

Launch instance -> configure instance -> Advanced Details -> user data

enter image description here

If you want to update to pull image from some private repo add the login command before pulling the image or if you have already the access then just run docker pull image_name

update:

If you want to add these in your AMI by default, you can use cloud.ini.

Here is the answer that you can look or here.

Adiii
  • 54,482
  • 7
  • 145
  • 148
  • thanks, but I think the most user will forget to paste the docker pull command in the user data field and as far as I know you cant set this as default – Kev Sep 11 '19 at 09:07
  • what is OS you are running in AMI? – Adiii Sep 11 '19 at 09:09
  • Ubuntu Server 16.04 LTS (HVM) – Kev Sep 11 '19 at 09:11
  • okay so you can add your command in crontab which will run on boot ,run command `crontab -e` then add `@reboot ( sleep 90 ; sh /home/ubuntu/init_script.sh)` your init_scipt.sh will container `docker pull image` or any other command and rebuild the AMI. tested with ubuntu 18 – Adiii Sep 11 '19 at 09:18
  • @Kev there is interesting answer, I thought you want to update but user has to update. so better to use cloudini.it https://stackoverflow.com/questions/23411408/how-do-i-set-up-cloud-init-on-custom-amis-in-aws-centos – Adiii Sep 11 '19 at 09:24
  • Thats what I am looking for (@masseyb also mentioned it), thx for your time – Kev Sep 11 '19 at 09:32
  • yes, I just thought that user has to update but later I convinced from your comment that it should be part of AMI instead of user-data. – Adiii Sep 11 '19 at 09:34
  • Thanks for appreciation @LinPy , one thing more would like to connect over linked if possible – Adiii Sep 11 '19 at 10:39
  • oh I see, I will give it try :) – Adiii Sep 11 '19 at 10:41