Skip to content

2.4 Building and Running

gyk4j edited this page Dec 12, 2024 · 3 revisions

Both main and stepup site would build (if required) and run the Docker containers through the Docker Compose tool. We need to ssh into each guest VM separately.

The command differ when accessing the virtual machines when they are hosted locally on VirtualBox and remotely in the cloud on AWS.

Using Vagrant with VirtualBox

Main site guest VM

$ vagrant ssh main
$ cd /vagrant
$ docker compose up

Stepup site guest VM

$ vagrant ssh stepup
$ cd /vagrant
$ docker compose up

Using Terraform with AWS

Generate a key pair

Assuming the AWS CLI is installed, run the following command:

$ aws ec2 create-key-pair \
    --key-name my-key-pair \
    --key-type rsa \
    --key-format pem \
    --query "KeyMaterial" \
    --output text > $HOME/.ssh/id_rsa.pem

Private key pair is stored in id_rsa.pem. Now we need to extract the public key used for creating the EC2 instances. The private key is used for logging in to the virtual machine instances later.

$ ssh-keygen -y -f $HOME/.ssh/id_rsa.pem > $HOME/.ssh/id_rsa.pub 

Now, public key is stored in id_rsa.pub.

Tip

There are other methods for generating your SSH key pair. Kindly refer to create key pairs for more information.

Tip

The log in user name for the AWS EC2 instance may need to be adjusted to ec2-users if a non-Ubuntu AMI is used. See: managing users.

Main site guest VM

$ ssh -i $HOME/.ssh/id_rsa.pem ubuntu@<main-instance-public-dns-name>
$ git clone --depth 1 https://github.com/gyk4j/toc.git
$ cd toc
$ docker compose up

Stepup site guest VM

$ ssh -i $HOME/.ssh/id_rsa.pem ubuntu@<stepup-instance-public-dns-name>
$ git clone --depth 1 https://github.com/gyk4j/toc.git
$ cd toc
$ docker compose up

Tip

We may also split the action of building and running the Docker containers by using the following commands instead:

$ docker compose build
$ docker compose up