Skip to content

Instantly share code, notes, and snippets.

@Big-Vi
Created February 4, 2023 19:59
Show Gist options
  • Save Big-Vi/b87786c742abf744f07b2bb60ba24d5e to your computer and use it in GitHub Desktop.
Save Big-Vi/b87786c742abf744f07b2bb60ba24d5e to your computer and use it in GitHub Desktop.
Pull docker image into EC2 Ubuntu instance for testing
sudo su
apt update
apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository "deb [arch=amd64,arm64] https://download.docker.com/linux/ubuntu focal stable"
apt-cache policy docker-ce
apt install docker-ce
systemctl status docker
apt install awscli
# Add AmazonEC2ContainerRegistryReadOnly IAM role to EC2 instance
aws ecr get-login-password --region <REGION> | docker login --username AWS --password-stdin <ACCOUNT_ID>.dkr.ecr.ap-southeast-2.amazonaws.com
docker pull <ECR_IMAGE_URL>
docker run -d -p 80:80 <IMAGE>
# Create .env and copy it to the container project folder
docker cp .env <CONTAINER_ID>:/var/www/html/.env
docker exec -it <CONTAINER_ID> bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment