Saturday, August 13, 2022

How to install docker on EC2 instance



**************************************
How to install docker on EC2 instance
***************************************



To be continued,
This post will show how to install docker in the Ec2 server.

I have explained two ways here.

1. Install docker on EC2

8. Now let’s see how to install docker on an EC2 instance
    
1. Update the installed packages and package cache on your instance.
“sudo yum update -y”
    - Is this ok (y/d/N) : type ‘Y’ and enter

2. Install the most recent Docker.
“sudo yum install docker -y”

3. Check the docker status if the docker is active or inactive state
“sudo service docker status”

It shows the status as “Inactive(dead)”, That means docker service is not started yet.

4. To start the Docker service, run below command and check status again.
“sudo service docker start”
“sudo service docker status”

After running the above two commands docker service should start and in Active state(running state). To confirm check the below step

5. Let’s check the docker version and available images
“docker --version”


  To check the docker images, run below command.
  “sudo docker images”
  Obviously , there will not be any images running.

6. Add the ec2-user to the docker group so you can execute Docker commands without using sudo as prefix to any command.
“sudo usermod -a -G docker ec2-user”

Now let’s check docker images without using sudo command
“docker images”

Note - In case if you get ‘permission denied’ message because we need to restart ec2 instance so that the changes will of adding ec2-user to docker group changes will be reflected.

8. Restart EC2 instance
“sudo reboot”

9.Now login to ec2 instance again.
“ssh -i DockerisedSeleniumGrid.pem ec2-user@ec2_public_ip_address”

Now check docker images command without using sudo
“docker images”
Because docker service is not started yet, let’s start docker using below command
“sudo service docker start” and the check docke image "docker images". It should work.

10. Check any running container available
“docker ps -a”


Up till here, we have seen how to install docker on EC2. Now we need to install docker compose on EC2
Click on below to check how to do that.

After installing docker compose, We need to install the Java on EC2 in order to run the docker.
To check, click on below link


So far, We have EC2 instance ready and Docker and Java installed in it, Now we will configure selenium Hub and Node using docker-compose file
- This time we will launch EC2 using WinSCP, Download WinSCP
- Launch WinSCP
-Host name "Public ipv4 ip address" of Ec2
-User name as "ec2-user"
-Click on Advance
-
-Click on "OK" ->  Click on Login
-After completing the process user will be able to login to EC2 and see the below screen

- Create a file as I have created,
-Right click -> File -> name the file as docker-compose
-Double click on the file and paste the below content
- Login to Ec2 using command prompt as we did previously.-Envoke the docker-compose file using "docker-compose up"-You can access hu using "EC2 IP address:4445(Port)"
-And you can use the same URL in selenium RemoteDriver
-Selenium Hub will be triggered and Hub will delegate tests to respective node


2. Install docker on EC2

1) Create a AWS ec2 server 
2) $ sudo 
3) # apt-get update 
4) # curl -fsSL https:i!get.docker.com -o get-docker.sh 
5) # sh get-docker.sh 
6) # docker --version 
7) # docker run --name myc1 -d -p 8081:8080 <image name> 

To login to Ec2:

1) Go to the location where the pem file is downloaded
2) Right-click "git bash" (Git bash must be downloaded in the system)
3) You will be inside the Ec2 instance.





To go to previous post, Click here

 

No comments:

Post a Comment

How to install Java on EC2

***************************************** How to install Java on EC2 ***************************************** To be continued, In this post...

All Time Popular Post