Specification
AMI
Amazon Linux AMI 2018.03.0 (HVM), SSD Volume Type
Security Group
Name: mysecurity
Outbound:
Inbound:80, 22(only my IP)
$ aws ec2 describe-security-groups --group-id [your security groupID] --output table
-----------------------------------------------------------------------------------------
| DescribeSecurityGroups |
+---------------------------------------------------------------------------------------+
|| SecurityGroups ||
|+-------------+------------------------+-------------+---------------+----------------+|
|| Description | GroupId | GroupName | OwnerId | VpcId ||
|+-------------+------------------------+-------------+---------------+----------------+|
|| mysecurity | sg-***************** | mysecurity | ************ | vpc-******** ||
|+-------------+------------------------+-------------+---------------+----------------+|
||| IpPermissions |||
||+--------------------------+--------------------------------+-----------------------+||
||| FromPort | IpProtocol | ToPort |||
||+--------------------------+--------------------------------+-----------------------+||
||| 80 | tcp | 80 |||
||+--------------------------+--------------------------------+-----------------------+||
|||| IpRanges ||||
|||+---------------------------------------------------------------------------------+|||
|||| CidrIp ||||
|||+---------------------------------------------------------------------------------+|||
|||| 0.0.0.0/0 ||||
|||+---------------------------------------------------------------------------------+|||
|||| Ipv6Ranges ||||
|||+---------------------------------------------------------------------------------+|||
|||| CidrIpv6 ||||
|||+---------------------------------------------------------------------------------+|||
|||| ::/0 ||||
|||+---------------------------------------------------------------------------------+|||
||| IpPermissions |||
||+--------------------------+--------------------------------+-----------------------+||
||| FromPort | IpProtocol | ToPort |||
||+--------------------------+--------------------------------+-----------------------+||
||| 22 | tcp | 22 |||
||+--------------------------+--------------------------------+-----------------------+||
|||| IpRanges ||||
|||+---------------------------------------------------------------------------------+|||
|||| CidrIp ||||
|||+---------------------------------------------------------------------------------+|||
|||| ***.***.*.**/** ||||
|||+---------------------------------------------------------------------------------+|||
Login to AWS
$ ssh -i [your key path].pem ec2-user@[your public DNS or public IP4]
Install Docker
$ sudo yum update -y
$ sudo yum install -y docker
$ sudo service docker start
Add ec2-user to docker group
$ sudo usermod -a -G docker ec2-user
$ cat /etc/group |grep docker
$ exit
ReLogin to AWS
$ ssh -i [your key path].pem ec2-user@[your public DNS or public IP4]
Preparation for building
index.php
<?php echo "Hello, world."; ?>
Dockerfile
FROM php:7-apache
COPY index.php /var/www/html/
Build
$ docker build -t php .
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
php latest 3ba28b2621e4 1 minutes ago 378MB
php 7-apache 1dffbbe4a5d3 4 weeks ago 378MB
Run
$ docker run -it -p 80:80 php:latest
Then access to you public IP or public DNS.