LoginSignup
0
0

More than 5 years have passed since last update.

Using Docker on AWS anyway.

Last updated at Posted at 2019-05-04

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.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0