A detailed guide to run Docker WordPress instance on AWS EC2 Debian/GNU Linux
Preparing EC2 Linux Instance (AMI)
- Goto console.aws.amazon.com/ec2/
Generate ssh-key pair
[on Client PC]
-
Run Command prompt and generate ssh key pairs
C:>ssh-keygen -t ed25519 -C "my@example.com"
Then you'll get id_ed25519.pub(public key) and id_ed25519(private key)
you can rename it to id_aws.pub / id_aws -
Launch "Puttygen.exe" and convert .ppk to .pem
(for Use /w SCP.exe)
2-1. Load '.ppk' -> choose the .ppk key
2-2. Click menu 'Conversions' -> 'Export OpenSSH key'
2-3. Close the app -
Use SCP.exe to transfer the public key to remote server.
C:>scp -4 -C -P 22 -i deb10.pem id_aws.pub admin@aws-server:/tmp/
Run the AMI and create user
-
Login as admin
/w ED25519 key with Tera Term Pro -
Create user
$ sudo useradd -d /home/charles -s /bin/bash -m charles
$ passwd charles
$ sudo visudo -
Register ssh public key
$ sudo su - charles
charles$ mkdir ~/.ssh; chmod 700 ~/.ssh
charles$ cd ~/.ssh
charles$ cat /tmp/id_aws.pub >> authorized_keys
Now you can login to aws ec2 instance as user.
Install Docker, Docker-compose
-
Update the apt pkg index and install pkgs to allow apt to use a repos over HTTPS
$ sudo apt -y update
$ sudo apt -y install ca-certificates curl gnupg lsb-release -
Add Docker's official GPG key
$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg -
Set up the stable repository
$ echo
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null -
Install docker engine
$ sudo apt -y update
$ sudo apt -y install docker-ce docker-ce-cli containerd.io docker-compose-plugin
$ sudo gpasswd -a charles docker -
Install Docker Compose
$ sudo curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s-
uname -m` -o /usr/local/bin/docker-compose
$ sudo curl -L "https://github.com/docker/compose/releases/download/v2.5.0/docker-compose-linux-aarch64" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
Now you can run your own docker container with docker-compose.yml!