Creating a docker host on AWS using Docker Machine (personal memorandum)

Obtaining credentials to perform AWS operations

*** If you have not created a user in AWS IAM **

1.Click on IAM for services
2.Select a user from the menu on the left
3.Click Add User
4.Enter any user name
5.The type of access is programmatic access
6.Click next step
7.Set permissions to "Attach existing policy directly"
8.Check "Administrator Access".
9.Press the next step.
10.Press the next step.
11.If there are no problems, click "Create User".

When the user creation is completed, the access key and secret access key will be displayed, so make a note of them. You can check the secret access key by clicking "View". These are the keys to connecting to AWS **, so don't lose them.

** If you have already created a user **

1.Click on IAM for services
2.Select a user from the menu on the left
3.Click on any username
4.Click Add Access Privilege on the Access Privileges tab
5.Set permissions to "Attach existing policy directly"
6.Check "Administrator Access".

Make sure that ** "Administrator Access" ** is added to the access authority.

Create a ".aws" directory and credentials file under your home directory.

-#Move to home directory
% cd 
-#In your home directory.ls because it becomes a hidden file when creating "aws"-You can check with a.
% mkdir ~/.aws
-#Credential settings
% vim ~/.aws/credentials
-#Enter the two keys you noted earlier
[default]
aws_access_key_id = xxxxxxx
aws_secret_access_key = xxxxxxx

Create an instance on AWS EC2

-#Example
% docker-machine create —-driver amazonec2 —-amazonec2-open-port 8000 —-amazonec2-region ap-northeast-1 aws-sandbox

** --driver ** is the specification of amazonec2. ** --amazonec2-open-port 8000 ** The port 8000 of the instance started is open to the outside. ** --amazonec2-region ap-northeast-1 ** is the region specification. ap-northeast-1 is the designation of the Tokyo region. ** aws-sandbox ** is specified as the host with the name "aws-sandbox".

Check the instance of EC2 and you can see that the instance is created by "aws-sandbox".

Start the container on the Docker host

-#Setting environment variables to connect to docker host
% eval $(docker-machine env aws-sandbox)
-#Helllo displaying a test page-world-Launch a container called webserver using nginx
% docker run -d -p 8000:80 —-name webserver kinematic/hello-world-nginx
-#Check the ip of docker host
% docker-machine ip aws-sandbox
52.199.66.11

Confirm that the web page is displayed at 52.199.66.11: 8000.

Stop container

-#Stop container
% docker-machine stop aws-sandbox
Stopping "aws-sandbox2"...
Machine "aws-sandbox2" was stopped.

Make sure that the EC2 instance state is ** "stopped" **.

Remove Docker host

-#docker host delete command
% docker-machine rm aws-sandbox
About to remove aws-sandbox
WARNING: This action will delete both local reference and remote instance.
-#Enter y
Are you sure? (y/n): y
Successfully removed aws-sandbox

Make sure that the EC2 instance state is "terminated".

Recommended Posts

Creating a docker host on AWS using Docker Machine (personal memorandum)
Docker Machine (personal memorandum)
Building a CICD pipeline using Docker (personal memorandum)
Launch docker container on EC2 (personal memorandum)
Data management using volume in Docker (personal memorandum)
Docker network (personal memorandum)
Deploy laravel using docker on EC2 on AWS ① (Create EC2 instance)
Data management using Docker bindmount and tmpfs (personal memorandum)
Creating a lightweight Java environment that runs on Docker
Construction of data analysis environment using Docker (personal memorandum)
A memorandum for creating an extended logger using org.slf4j.Logger
[Amateur remarks] Build multiple WordPress on AWS using Docker Compose
Deploy laravel using docker on EC2 on AWS ② (Elastic IP acquisition-linking)
Creating a 2021 weekly calendar (refill for personal organizer) using Ruby
Creating a calendar using Ruby
Deploy laravel using docker on EC2 on AWS ④ (git clone ~ deploy, migration)
Procedure for publishing an application using AWS (4) Creating a database
Install docker on AWS EC2
I tried running a Docker container on AWS IoT Greengrass 2.0
Try Hello World using plain Java on a Docker container
Deploy laravel using docker on EC2 on AWS ③ (SSH connection ~ Docke-compose installation)
Easily set up a Jenkins server on AWS using Bitnami's AMI
Run (provisionally) a Docker image with ShellCommandActivity on AWS Data Pipeline
Install Docker on AWS Ubunt 20.04 LTS
Try using Redmine on Mac docker
To beginners launching Docker on AWS
Run React on a Docker container
Build a Minecraft server on AWS
Run the AWS CLI on Docker
Run PureScript on a Docker container
A memorandum of personal phpenv install
Using Docker on Windows10 Home WSL2
Using a local network on iOS 14
Access MySQL on a Docker container from a local (host OS) Java program
How to build a Ruby on Rails environment using Docker (for Docker beginners)
Create a web environment quickly using Docker
A memorandum on how to use Eclipse
Deployed using Docker + Rails + AWS (EC2 + RDS)
[Creating] A memorandum about coding in Java
Creating a user authentication function using devise
Build a Maven repository on AWS S3
[Personal memo] Writing a file using BufferedWriter
Send an email using JavaMail on AWS
Build an environment with Docker on AWS
Try the Docker environment on AWS ECS
[Personal memo] Reading a file using BufferedReader
I made a bulletin board using Docker 1
A quick note on using jshell with the official Docker image of the JDK