To run a Docker container on an EC2 instance, we first have to set up an instance with a Docker installation and add an ec2-user to the Docker group so that we can execute Docker commands with an ec2-user rather than as a root user, which we will be covering in this recipe.
Setting up an EC2 instance to run a Docker container
How to do it...
- Switch to the root user from the ec2-user user by executing the following command:
[ec2-user@ip-172-31-34-99 ~]$ sudo su
[root@ip-172-31-34-99 ec2-user]#
- Install Docker and update an EC2 instance by executing the following commands:
[root@ip-172-31-34-99 ec2-user] yum install -y docker
[root@ip-172-31-34-99 ec2-user] yum update -y
- Start Docker as a service on an EC2 instance by executing...