Setting up Docker and Docker Compose on AWS EC2 Instance

Written on 2023-03-08 by Adam Drake - 3 min read

Image of Setting up Docker and Docker Compose on AWS EC2 Instance

I was recently setting up an EC2 instance on AWS and thought it would be useful to document the very common terminal commands that are needed to set up your instance to work with docker containers and docker-compose. This article will show you how to ssh into an EC2 instance set up on AWS and install docker and docker-compose.


Once you have launched your instance on the AWS console you will then need to create a key/pair. Select the key pair type you want and the Private key format. For this application I chose:

Once you have created that, then download the key onto your machine.
Restrict access to that key:


chmod 400 ~/Downloads/server-key.pem


(Replace the path to the key to whereever you have saved the key on yourmachine.)


Then you can ssh into the server with that key:


ssh -i ~/Downloads/server-key.pem ubuntu@70.45.277.243


Type yes when prompted to finalise the ssh process into the server. Next you want to run an update to make sure everything on the server is up to date:


sudo apt update


Then you can install docker:


sudo apt install docker.io


Once this installation process has finished you can log out of the machine(ctrl + d) and log back in to complete the installation. To test it is working as expected, ssh back into the machine and type:


docker ps

It should print out this:

Next install docker-compose


sudo apt install docker-compose


And again once this installation process has finished you can log out of themachine (ctrl + d) and log back in to complete the installation.

Conclusion

So thats it! Nothing super complicated there but it's the sort of thing you do regularly enough that you need to know this process but not regularly enough that you can remember all the steps easily. At least I can't. Hope this is useful to some of you and I look forward to continuing to learn about AWS.

Loading...

Adam Drake AI Selfie

Written by Adam Drake

Adam Drake is a Frontend React Developer who is very passionate about the quality of the web. He lives with his wife and three children in Prague in the Czech Republic.

Adam Drakes Site © 2024