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.

Subscribe to My Weekly Updates on Medium!

Enjoyed This Post?

If you found this blog post helpful, why not stay updated with my latest content? Subscribe to receive email notifications every time I publish.

If you're feeling really generous you can buy me a coffee. (Btw, I really like coffee…)

What You'll Get

  • Exciting Discoveries: Be the first to know about the latest tools and libraries.
  • How-To Guides: Step-by-step articles to enhance your development skills.
  • Opinion Pieces: Thought-provoking insights into the world of frontend development.

Join Our Community

I live in the vibrant city of Prague, Czech Republic, with my family. My blog is more than just articles; it's a community of like-minded developers who share a love for innovation and learning.

About me

I'm a passionate Frontend Developer specialising in React and TypeScript. My professional journey revolves around exploring and mastering new tools and libraries within the JavaScript ecosystem.

Check out my LinkedIn and Github if you are interested.

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 © 2025