To install Docker Compose on an Amazon AWS EC2 Linux 2 server, simply connect to the Amazon Linux 2 server via an SSH PuTTY terminal and run the sudo yum install docker command on the AWS SSH terminal to install it in a few minutes.
Docker is an open-source software, which is used to create, maintain and run applications. It is a kind of virtual container machine that can run with your local system and cloud server.
How to install Docker on Amazon Linux 2
Here are steps to installing and configuring docker on Amazon aws linux 2 ec2 server:
Step 1 – Login to Amazon AWS Linux 2 Console
Log into the AWS EC2 Management Console.
Step 2 – Connect to Amazon AWS Linux 2 Server via SSH
To connect your Amazon AWS linux 2 server from the SSH terminal, Open your putty or ssh and connect to from server.
If you are new to connect aws ec2 instance with Windows, ubuntu, and mac systems. A step-by-step guide on How to Connect to ec2 Instance From Putty and SSH Terminal.
Step 3 – Update System Dependencies
Run sudo yum update
command on aws ssh terminal window to update system packages:
sudo yum update
Step 4 – Install Docker on Amazon Linux 2
To run the sudo yum install docker command on ssh terminal window to install docker-compose with amazon aws linux 2 server:
sudo yum install docker
Step 5 – Enable and Start Docker on Amazon Linux 2
By default Docker is disabled and stopped on Amazon Linux 2 server, After installing Docker Compose, you can enable and start it by using sudo service docker start && sudo systemctl enable docker.service
command on amazon aws ssh terminal window:
sudo service docker start && sudo systemctl enable docker.service
To check the Docker status by running the sudo systemctl status docker.service
command on an ssh terminal window:
sudo systemctl status docker.service
Some common commands of Docker
To view the system information about Docker:
docker info
Download Docker Images:
docker run hello-world
Getting the output as shown below, you can access and download the images from Docker Hub.
Output Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 2db29710123e: Pull complete Digest: sha256:10d7d58d5ebd2a652f4d93fdd86da8f265f5318c6a73cc5b6a9798ff6d2b2e67 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly.
To run the docker images
command to see downloaded images:
docker images
To all active containers, use docker ps
command:
docker ps
Use docker ps -a
command to view all containers which are active and inactive:
docker ps -a
Use the following command to view the latest container:
docker ps -l
To start a docker container, use docker start
command followed by the Container ID or Container Name:
docker start container-id/name
Likewise, to stop a running container you can use the docker stop
command followed by Container ID or Container Name:
docker stop container-id/name
If you no longer need the container you can remove the container with the docker rm
followed by Container ID or Container Name:
docker rm container-id/name
To enter into interactive shell you can use the following command:
docker run -it container-id/name
Note that:- you can manually install commands inside the shell. For more details about docker commands use the docker run help
command.
Conclusion
Through this tutorial, you have learned how to install, configure Docker compose on amazon linux 2 ec2 server.