To create a new SSH key which can be used as the deploy key, run the command below:
ssh-keygen -t ed25519 -b 4096
Note: This will create a new ed25519
key, which is the recommended key for GitHub.
To display the public key, run:
cat ~/.ssh/id_ed25519.pub
Use the below commands to configure the EC2 virtual machine running Amazon Linux 2.
Install Git:
sudo yum install git -y
Install Docker, make it auto start and give ec2-user
permissions to use it:
sudo amazon-linux-extras install docker -y
sudo systemctl enable docker.service
sudo systemctl start docker.service
sudo usermod -aG docker ec2-user
Note: After running the above, you need to logout by typing exit
and re-connect to the server in order for the permissions to come into effect.
Install Docker Compose:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Use Git to clone your project:
git clone <project ssh url>
Note: Ensure you create an .env
file before starting the service.
To start the service, run:
docker-compose -f docker-compose-deploy.yml up -d
To stop the service, run:
docker-compose -f docker-compose-deploy.yml down
To stop service and remove all data, run:
docker-compose -f docker-compose-deploy.yml down --volumes
To view container logs, run:
docker-compose -f docker-compose-deploy.yml logs
Add the -f
to the end of the command to follow the log output as they come in.
If you push new versions, pull new changes to the server by running the following command:
git pull origin
Then, re-build the app
image so it includes the latest code by running:
docker-compose -f docker-compose-deploy.yml build app
To apply the update, run:
docker-compose -f docker-compose-deploy.yml up --no-deps -d app
The --no-deps -d
ensures that the dependant services (such as proxy
) do not restart.