You can run Docker on AWS using AWS's ECR and ECS.
If you look at the list of all AWS services, it's listed in the far right corner.
Elastic Container Registry is ECR and Elastic Container Service is ECS.
・ ECS is the place to start Docker on AWS **. Start the container from the ECR image.
You can push a Docker image onto AWS and share it with the entire team (ECR) instead of Docker hub, or you can launch and operate a container on AWS (ECS) **.
--Abbreviation for Elastic Container Registry. --Docker registry service. --AWS version of Docker hub.
Elastic is elastic. Here, it means that there is a high degree of freedom in following changes in the procedure. Container is a Docker container. Registry is the storage location. In summary, nuances such as ** highly flexible container storage location **.
You can push the created image to ECR and save it.
You can choose Private or Public to create a repository.
You can see the list of created images by clicking the repository name.
Click on the image to see its details.
Enter the creation screen from the repository creation button at the top right of the screen. Very easy to create. Basically,
--Private or Public selection --Enter the repository name --Creating a repository
Only 3 steps.
Go into the repository and click ** Show Push Command ** in the upper right to see the steps to push an image into the repository.
step1
#Get an AWS authentication token and log in to docker's repository server
aws ecr get-login-password --region ap-northeast-1 | docker login --username AWS --password-stdin [aws_account_id].dkr.ecr.[region].amazonaws.com
· Aws ecr get-login-password --region ap-northeast-1
Get the PW (token) of the specified region with the aws ecr
command.
· Command A | Command B
When commands are connected with a "|" pipe, the data acquired by command A is passed to command B.
· Docker login [optional] [server]
--username AWS
: Log in with your username as AWS
--password-stdin
: For the password, enter the token obtained earlier as standard input (-stdin).
Pass by.
[aws_account_id].dkr.ecr.[region].amazonaws.com
Specify the aws account for the server.
If no server is specified, connect to Docker hub.
step2
docker build -t [Repository name] .
-Docker build [option] [Docker file path]
-t [image name: tag name]
: Add a tag to the created image. Here, the repository name is specified as a tag.
If no tag name is specified, it will be latest
.
For example
For docker build -t test-repository .
The image name will be test-repository: latest
.
・ .
The path to the directory where the Dockerfile is located. Specify that it is in the current directory.
step3
docker tag [Repository name]:latest [aws_account_id].dkr.ecr.[region].amazonaws.com/[Repository name]:latest
Set the repository name for the image.
docker tag [image name] [repository name: tag name]
[Image name] can be specified by either the image ID or the image: tag.
Example after setting
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
[aws_account_id].dkr.ecr.[region].amazonaws.com/[Repository name on AWS] latest test-repository:latest 33 minutes ago 802MB
docker push [aws_account_id].dkr.ecr.[region].amazonaws.com/test-repository:latest
docker push [repository name: tag name]
Push the image of the tag name corresponding to the specified repository.
This completes pushing the image.
--Abbreviation for Elastic Container Service --Docker container execution environment
(Reference) Docker official overview
There are two main items in processing: (1) cluster and (2) task definition.
Simply put, clusters are sites and applications, task definitions are container creation settings.
** ▼ ECS object relationships **
A cluster is ** one or more containers that can execute task requests **
In other words, one application. For example, if the blog site and the corporate site are operated on separate servers, there are two clusters, the blog site and the corporate site.
The image is that multiple containers such as Ruby on Rails and DB such as PostgreSQL are running in the blog site.
Select a template to easily create a cluster.
Read as Fargate. A service dedicated to ECS (and EKS) that allows you to run containers without having to manage EC2 servers or clusters.
An abbreviation for Amazon Virtual Private Cloud (Amazon VPC), a dedicated space for launching containers.
It will be possible to send specific data addition to AWS operation status monitoring service CloudWatch.
There are some data that can be sent, such as CpuUtilized (the number of CPU units in use).
This completes the cluster creation.
Task definition is required to run Docker container in ECS.
** ▼ Contents of task definition **
--Docker image used by each container in the task --Amount of CPU and memory used by each task or each container within the task --The startup type to use. Determine the infrastructure on which the task will be hosted. --Docker network mode used for task containers --Log configuration used for tasks --Whether to continue running the task if the container terminates or fails --Commands that need to be executed when the container starts --Data volume that needs to be used in the task container --The IAM role that the task must use
↓
Set the task name, CPU and memory amount to be allocated to the container, container name, etc.
** ▼ Main settings **
Specify the image to start the container from ECR.
Recommended Posts