Skip to content

Instantly share code, notes, and snippets.

@ojengwa
Last active January 18, 2024 17:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ojengwa/76e4e7999ee6afcac60938da75ce0f97 to your computer and use it in GitHub Desktop.
Save ojengwa/76e4e7999ee6afcac60938da75ce0f97 to your computer and use it in GitHub Desktop.
Set by step guide on deploying your docker containers to AWS using docker-compose and docker-machine
# Deploy to AWS using docker-machine and docker-compose
## 1. Prepare your machine
Please follow this steps:
1.1 Install docker in your localhost. [Installation link](https://docs.docker.com/engine/installation/)
1.2 Install docker-machine in your localhost. [Installation link](https://docs.docker.com/compose/install/)
1.3 Install docker-compose in your localhost. [Installation link](https://docs.docker.com/machine/install-machine/)
1.4 Create an account in AWS (skip this step if you already have one). [AWS](https://aws.amazon.com/)
1.5 Create the AWS credentials file in your localhost. [docker-machine + aws](https://docs.docker.com/machine/drivers/aws/)
1.6 Log into aws and get your VPC ID
1.6.1 Go to: https://console.aws.amazon.com/vpc/
1.6.2 Click on the VPC link
1.6.3 Copy your VPC ID
## 2. Deploy to AWS
Please write this commands in your terminal:
2.1 `docker-machine create -d amazonec2 --amazonec2-vpc-id <your-vpc-id> --amazonec2-ami ami-e13739f6 <project_name>`
2.2 `docker-machine env <project_name>`
2.3 `eval $(docker-machine env <project_name>)`<br>
**(From now on all docker, docker-machine and docker-compose commands will point to the AWS EC2 instance)**
2.4. `cd <project_dir>`
2.5 `docker-compose build`
2.6 `docker-compose up -d`
## 3. Check <project_name> is up and running
Please follow this steps:
3.1 Go to your [AWS EC2](https://console.aws.amazon.com/ec2)
3.2 Click on the "running instances" link
3.3 Copy the public IP of the <project_name> instance
3.4 Check the security group applied to the instance allows inbound TCP traffic to the port on your exposed ports
3.5 On your browser go to:<br>
`http://<project_name-instance-public-ip>:<port>/`
Congratulations! You just deployed your project to AWS using docker-machine and docker compose:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment