Home > Mobile >  docker not installed through yum in user data
docker not installed through yum in user data

Time:01-29

this is how my user data looks like, but docker is not installed, when connecting to my ec2 machine:

sudo yum -y install docker
sudo service docker start
sudo docker pull nginx
sudo docker run -d -p 80:80 nginx

what can I do?

CodePudding user response:

When using user-data script you can debug what is happening by ssh connecting to the instance and check the output in cloud-init-output.log.

sudo cat /var/log/cloud-init-output.log

When doing this you'll find an strange error containing:

Jan 29 11:58:25 cloud-init[2970]: __init__.py[WARNING]: Unhandled non-multipart (text/x-not-multipart) userdata: 'sudo yum -y install dock...'

Which means that the default interpreter seems to be python and it's neccesary to start the user-data with #!/bin/bash. (See this other StackOverflow answer)

When changing the user-data to:

#!/bin/bash 
sudo yum -y install docker
sudo service docker start
sudo docker pull nginx
sudo docker run -d -p 80:80 nginx

it will be executed as expected and you will find nginx running on your ec2.

  • Related