Skip to content

Set up AWS Linux instance running docker.

I will set up a Linux server running on AWS EC2. Basic and necessary information will be set up to build an application running environment on Docker.

Check the release version of the server

cat /etc/os-release
Output
NAME="Amazon Linux"
VERSION="2023"
ID="amzn"
ID_LIKE="fedora"
VERSION_ID="2023"
PLATFORM_ID="platform:al2023"
PRETTY_NAME="Amazon Linux 2023.4.20240416"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2023"
HOME_URL="https://aws.amazon.com/linux/amazon-linux-2023/"
DOCUMENTATION_URL="https://docs.aws.amazon.com/linux/"
SUPPORT_URL="https://aws.amazon.com/premiumsupport/"
BUG_REPORT_URL="https://github.com/amazonlinux/amazon-linux-2023"
VENDOR_NAME="AWS"
VENDOR_URL="https://aws.amazon.com/"
SUPPORT_END="2028-03-15"

Setting timezone for instance

In this case I use timezone in Tokyo, Japan

timedatectl set-timezone Asia/Tokyo
ln -sf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

Install Code Deploy Agency

Sign in to the instance, and run the following commands, one at a time. Running the command sudo yum update first is considered best practice when using yum to install packages, but you can skip it if you do not wish to update all of your packages.

1
2
3
sudo yum update
sudo yum install ruby
sudo yum install wget
Change to your home directory:
cd /home/ec2-user

Note

In the previous command, /home/ec2-user represents the default user name for an Amazon Linux or RHEL Amazon EC2 instance. If your instance was created using a custom AMI, the AMI owner might have specified a different default user name.

Download the CodeDeploy agent installer:

wget https://bucket-name.s3.region-identifier.amazonaws.com/latest/install
bucket-name is the name of the Amazon S3 bucket that contains the CodeDeploy Resource Kit files for your region, and region-identifier is the identifier for your region.

For example:

wget https://aws-codedeploy-ap-northeast-1.s3.ap-northeast-1.amazonaws.com/latest/install
For a list of bucket names and region identifiers, see Resource kit bucket names by Region.

Set execute permissions on the install file:

chmod +x ./install
To install the latest version of the CodeDeploy agent:
sudo ./install auto
Enable and start service
1
2
3
systemctl enable codedeploy-agent
systemctl start codedeploy-agent
systemctl status codedeploy-agent

Add user run docker

1
2
3
4
5
6
7
8
useradd minamino-user -m
cd /home/minamino-user
mkdir .ssh
chmod 700 .ssh
chown minamino-user:minamino-user .ssh
cat /path-to-pub-key/aws_user.pub >> .ssh/authorized_keys
chmod 600 .ssh/authorized_keys
chown minamino-user:minamino-user .ssh/authorized_keys

Install docker

1
2
3
yum search docker
yum info docker
yum install docker
Enable and start service
1
2
3
systemctl enable docker.service
systemctl start docker.service
systemctl status docker.service

Add group membership for the default minamino-user so you can run all docker commands without using the sudo command

sudo usermod -a -G docker minamino-user
id minamino-user
Reload a Linux user's group assignments to docker w/o logout
newgrp docker

Need docker-compose too? Try any one of the following command

1
2
3
4
cd /home/ec2-user
sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose version

Comments