0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

A detailed guide to run Docker WordPress instance on AWS EC2 Debian/GNU Linux

Last updated at Posted at 2022-05-04

A detailed guide to run Docker WordPress instance on AWS EC2 Debian/GNU Linux

Preparing EC2 Linux Instance (AMI)

  1. Goto console.aws.amazon.com/ec2/

Generate ssh-key pair

[on Client PC]

  1. 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

  2. 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

  3. 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

  1. Login as admin
    /w ED25519 key with Tera Term Pro

  2. Create user
    $ sudo useradd -d /home/charles -s /bin/bash -m charles
    $ passwd charles
    $ sudo visudo

  3. 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

  1. 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

  2. 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

  3. 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

  4. 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

  5. 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!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?