[DOCKER] Notes on what to do when EC2 is set up with t2.micro

I accidentally terminate the EC2 instance for study instead of stopping it, and sometimes I recreate it, so I will keep a memorandum about what to do when launching the instance.

Various update

sudo yum update -y 

Increase swap memory

In the case of an instance with a small memory such as t2micro, it will be dropped by a process that uses a lot of memory like Angular's prod build, so increase the swap memory to avoid it.

#Create a 4GB swap file (it will fail if there are a lot of bs because the memory is low)
sudo dd if=/dev/zero of=/swapfile bs=1M count=4096
#Grant read / write permission to swap file
sudo chmod 600 /swapfile
#Swap space setup
sudo mkswap /swapfile
#Enable swap space
sudo swapon /swapfile
#Check swap space
sudo swapon -s

Reference: https://aws.amazon.com/jp/premiumsupport/knowledge-center/ec2-memory-swap-file/

When swapon, you can confirm that the file is created with the specified size as shown below

$ sudo swapon -s
Filename                                Type            Size    Used    Priority
/swapfile                               file            4194300 0       -2

If you execute the free command, you can confirm that it is recognized as memory.

$ free
              total        used        free      shared  buff/cache   available
Mem:        1006940       82724       63424         404      860792      771392
Swap:       4194300           0     4194300

Enable swap at startup

Edit / etc / fstab with vi

sudo vi /etc/fstab

Add the following line to the end and save

/swapfile swap swap defaults 0 0

Install Git

sudo yum install git-all -y

Reference: https://git-scm.com/book/ja/v2/%E4%BD%BF%E3%81%84%E5%A7%8B%E3%82%81%E3%82%8B-Git % E3% 81% AE% E3% 82% A4% E3% 83% B3% E3% 82% B9% E3% 83% 88% E3% 83% BC% E3% 83% AB

Git user settings

git config --global user.name "username"
git config --global user.email [email protected]

Reference: https://git-scm.com/book/ja/v2/%E4%BD%BF%E3%81%84%E5%A7%8B%E3%82%81%E3%82%8B-% E6% 9C% 80% E5% 88% 9D% E3% 81% AEGit% E3% 81% AE% E6% A7% 8B% E6% 88% 90

Install Docker and docker-compose

#docker installation
sudo yum install docker -y
#docker service started
sudo service docker start
#Settings that allow docker commands to be used without sudo
sudo usermod -a -G docker ec2-user
#Set docker service to start automatically
sudo systemctl enable docker

Reference: https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/developerguide/docker-basics.html    http://docs.docker.jp/v1.11/engine/admin/systemd.html

Install docker-compose

#Binary download
sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
#Grant execute permission
sudo chmod +x /usr/local/bin/docker-compose

Reference: https://docs.docker.com/compose/install/

If this is left as it is, Permission Error: [Errno 13] Permission denied will occur, so exit from EC2 and reconnect.

Install Node.js

#Download installer&Run
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
# nvm.sh run
. ~/.nvm/nvm.sh
# Node.js installation
nvm install node

Reference: https://docs.aws.amazon.com/ja_jp/sdk-for-javascript/v2/developer-guide/setting-up-node-on-ec2-instance.html

Recommended Posts

Notes on what to do when EC2 is set up with t2.micro
[IOS] What to do when the image is filled with one color
What to do when CentOS cannot be started with VirtualBox on Catalina
Notes on what to do when a WebView ClassNotFoundException occurs in JavaFX 12
What to do when is invalid because it does not start with a'-'
ParseException: What to do when Unparseable date is reached
What to do when booting Ubuntu on WSL2 and getting "Process terminated with code 1"
After installing'devise''bootstrap' of gemfile with rails, what to do when url is an error
What to do if you get a port error when docker-compose up on Mac
What to do when you launch an application with rails
What to do if audio is not available on discordrb
What to do if FacesMessage is set but not displayed
You can do it right away with Serverless Framework Serverless on AWS (API + Lambda [java] is easy to set up)
[Joke] What to do when the invalid sample rate is reached when using Mixxx on Ubuntu 20.04
What to do when javax.batch.operations.JobStartException occurs
[Rails] What to do when the view collapses when a message is displayed with the errors method
Notes on what to do if Ubuntu 20.04 installation on Virtual box 6.1 (Windows10) fails with "Error 5 Input / output error"
What to do if the app is not created with the latest Rails version installed when rails new
Set up ImpressPages 5.0 with LAMP on CentOS 7.3
What to do when undefined method ʻuser_signed_in?'
What to do when "npm ERR! Code ENOSELF" is displayed after npm install
Minimal steps to set up a Ruby environment with rbenv on Ubuntu 20.04
What to do when Blocked Host: "host name" appears in Ruby on Rails
What to do if tomcat process remains when tomcat is stopped in eclipse
What to do when "call'Hoge.connection' to establish a connection" appears on rails c
What to do if you get Application with name appName is already registered. When you try to start GlassFish
What to do when you want to delete a migration file that is "NO FILE"
[Swift] What to do if the app icon is set but not reflected
What to do when "Nil location provided. Can't build URI." Appears on CarrierWave
What to do when debugging "Source not found"
What do you use when converting to String?
What to do when IllegalStateException occurs in PlayFramework
WELD-001408: What to do when Unsatisfied dependencies for type Bean with qualifiers @Default
What to do if you get a NoClassDefFoundError when trying to run eclipse on Java9
What to do when "Fail to load the JNI shared library" is displayed in Eclipse
What to do when build fails by rbenv install / pyenv install with anyenv (Debian system)
What to do when routing settings do not work after building Docker environment with Laravel
I want to hit the API with Rails on multiple docker-composes set up locally
What to do when JSF tags do not become HTML
Error encountered with notes when deploying docker on rails
Steps to set up Postfix and Dovecot on CentOS 8.3
What to do when a null byte error occurs
What to see when IntelliJ doesn't start on Mac
Error ExecJS :: RuntimeUnavailable: What to do when it occurs
BasicDataSourceFactory is ClassNotFoundException when connecting to DB on Tomcat 8
What is `docker-compose up`?
Tips to make side-scrolling feel good when RecyclerView or ViewPager is set on Navigation Drawer
What to do if a SAX Parser error occurs when using Liferay 7 / DXP on AWS
What to do when Rails on Docker does not reflect controller changes in the browser
What to do when it becomes Unable to find CDI BeanManager.
How to set environment variables when using Payjp with Rails
[App groups] What to check when UserDefaults data is inaccessible
What to do when Method not found in f: ajax
Set watermark to be output only when printing with iText
What happens to instance variables when copying an instance with ruby
What to do when Cannot apply expression operators to method binding
Notes on character encoding when migrating from windows to Mac
Set up Django on Ubuntu 16.04 with PostgreSQL and Gunicorn on ECS
How to set up a proxy with authentication in Feign
When I try to use the AWS SDK with Ruby + Lambda, `sam local` is messed up.
What to do when Gradle says "For more information, please recompile with the -Xlint: unchecked option"