Create an image you want.
$ mkdir docker-php && cd docker-php
$ vim index.php
index.php
<?php echo "Hello, world."; ?>
$ vim Dockerfile
Dockerfile
FROM php:7-apache
COPY index.php /var/www/html/
$ docker build -t php .
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
php latest cba780f28f8b 52 seconds ago 378MB
php 7-apache 1dffbbe4a5d3 3 weeks ago 378MB
Install AWS CLI to use ECR.
$ curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
$ sudo python get-pip.py
$ sudo pip install awscli
$ rm -rf get-pip.py
$ aws --version
aws-cli/1.16.150 Python/2.7.13 Darwin/17.5.0 botocore/1.12.140
Create IAM (If you don't have it.)
- Sign in or create an account on AWS.
- Create IAM user
- Choose "User" at left side.
- Enter name that you like and check "access via program".
- Attache "AmazonEC2ContainerRegistryFullAccess"
- Skip tagging.
- Confirm your information.
- Done
Apply your information using AWS CLI.
$ aws configure
AWS Access Key ID [None]: ****************** [Enter you Access Key ID]
AWS Secret Access Key [None]: ****************** [Enter your Secret Access Key]
Default region name [None]: ap-northeast-1
Default output format [None]: json
You can check your info this command.
$ aws configure list
Create repository on ECR
Access to ECR -> Amazon ECR -> Repositories.
Enter "php" (in here) as repository name.
Done.
Push to ECR from local image.
Log in to AWS
$ (aws ecr get-login --no-include-email --region ap-northeast-1)
docker login -u AWS -p ....
$ docker login -u AWS -p ....
...
Login Succeeded
push to your ECR repository.
Use your id instead of ************.
$ docker tag php:latest ************.dkr.ecr.ap-northeast-1.amazonaws.com/php:latest
$ docker push ************.dkr.ecr.ap-northeast-1.amazonaws.com/php:latest
If you'd like to update your image, tagging and push again as same tag.