Locked out of ec2 instance after installing Docker on it - amazon-web-services

After I created a clean instance with Ubuntu 20 or Amazon Linux AMI, I can log into the instance using SSH.
Then I do:
sudo apt update -y && apt upgrade -y on Ubuntu
or
sudo yum update -y on Amazon Linux
Still all goes fine and I can continue to connect to the instance via SSH.
Then I install docker, the pipe becomes broken in the middle of the installation and I cannot connect to the instance any more.
The SSH times out.
This same behavior can be observed also with AMIs with preinstalled Docker on them.
For example I tried to use the redash AMI, I couldn't connect to it after launch.

Related

Install docker in AWS EC2 instance and map docker port to DNS in godady domain provider and apply SSL Certificates in AWS

I have generate a instance in AWS server EC2 and install Ubuntu 22.04 but i have now idea how to manage with docker everything like DNS map, Docker port Map with DNS and how to SSL certificates installs. There are some steps I have done
AWS EC2 Instance created
Ubuntu 22.04 install
apache2 install
Docker Install
Docker Compose install
I want to know
exp- I have a domain example.com
How to map docker like 137.31.63.15:8100 map in Godady DNS
How to apply SSL certificate in AWS with Docker port
plz anyone know help me...
Thank you
I have done these things and I have no idea what i do next.
AWS EC2 Instance created
Ubuntu 22.04 install
apache2 install
Docker Install
Docker Compose install

Configuring amazon-linux-extras epel on Amazon Linux 2 in a private subnet

I have an EC2 in a private subnet with no external internet access. I need to pull in a package called proj from the EPEL repository.
Based on this documentation I should be able to run
sudo amazon-linux-extras install epel -y
This does configure the EPEL repository but whenever I run sudo yum install <PACKAGE> I get the following error message.
Cannot retrieve metalink for repository: epel/x86_64. Please verify its path and try again
Looking at /etc/yum.repos.d/epel.repo I see that there is a metalink reference pointing to a HTTPS site but I changed it to HTTP. Is this still attempting to reach out to the internet to retrieve certain files?
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
metalink=http://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
Is there a way in AWS on an EC2 instance to point to somewhere internal within AWS that hosts the packages?
I also attempted to get a copy of the epel-release-latest-7.noarch.rpm uploaded to my EC2 instance and then ran sudo yum install epel-release-latest-7.noarch.rpm but I still am coming across a similar error message about the metalink.
I'm assuming this was just to configure the repo but it would still need to reach out to the public internet to pull in packages?
Is this still attempting to reach out to the internet to retrieve certain files?
Yes.
Is there a way in AWS on an EC2 instance to point to somewhere internal within AWS that hosts the packages?
No.
Normally what you do is to create a custom AMI with all the packages using an instance in a public subnet, and then create private instance using the AMI created. This way you do not need to connect to any repositories. Otherwise you have to setup NAT gateway to be able to access internet.

How to start docker in AWS EC2?

I have started an EC2 instance which is based on Amazon Linux2 AMI(HVM), SSD Volume Type. I want to install docker in that instance. I ran following command:
sudo yum update -y
sudo yum install -y docker
sudo chkconfig docker on
chkconfig --list docker
I get following message in my putty session:
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
error reading information on service docker: No such file or directory
I think Docker got installed alright, but it is not starting.Because in putty log I find
Installed:
docker.x86_64 0:18.06.1ce-8.amzn2
When I gave the command
sudo chkconfig docker on
putty told me:
Note.Forwarding request to 'systemctl enable docker.service'
So I even tried
sudo systemctl enable docker.service
Do I have to use some other AMI?
If you are using ECS, unless you have a reason to use a custom AMI, you should be using a supported ECS optimised AMI. These AMI are pre-configured with docker and all other ecs requirements:
The Amazon ECS-optimized AMIs are preconfigured with these requirements and recommendations. We recommend that you use the Amazon ECS-optimized Amazon Linux 2 AMI for your container instances unless your application requires a specific operating system or a Docker version that is not yet available in that AMI.
See https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-optimized_AMI.html

How to run Vagrant/Virtualbox on EC2

I wrote a unittest that verifies the setup of my dev environment by using Vagrant to create a Virtualbox VM and then run through all the setup steps.
I'm not trying to run this unittest as part of my normal build process on a QA server running as an EC2 instance, and it's failing because EC2 is based on Xen and Virtualbox doesn't support Xen. Trying to install the latest Oracle Virtualbox with sudo apt-get install virtualbox-5.1 fails with the error:
vboxdrv.sh: failed: Running VirtualBox in a Xen environment is not supported.
Oddly, installing the vanilla Virtualbox package in Ubuntu's standard repo succeeds, although it doesn't provide the VBoxManage tool needed by Vagrant.
What's the easiest way to get Vagrant to be able to spin up a VM from inside an EC2 instance? Presumably, I could use an EC2 provider, but spinning up an EC2 instance over the network is much much slower and more complicated than creating a local instance.

Restart ecs-agent from user-data

I mounted EBS to ecs-enabled instance in AWS.
For EBS to be visible to docker, docker daemon has to be restarted. I added appropriate commands to the user-data. But I am unable to restart ecs-agent docker container from the user data.
Following is my user-data:
#!/bin/bash
echo ECS_CLUSTER=MYCLUSTER>> /etc/ecs/ecs.config
mkfs -t ext4 /dev/sdb
mkdir /db/
mount /dev/sdb /db/
service docker stop
service docker start
docker start ecs-agent
On SSH, I could see that the ecs-agent container is created but it is not running. When I start the container manually, it is working. What is the correct way to start it during instance launch? What am I missing in my user-data script?
I need to create a launch configuration for use in my auto-scaling group. Instances should have EBS enabled and visible to docker.
If you need to restart the Docker daemon, it seems likely that you're dealing with an existing EC2 instance. In that case, user data scripts won't help you because according to the EC2 User Guide they "only run during the first boot cycle when an instance is launched".
As for the correct way to start the ECS agent during instance launch, it depends on which distribution you're running. For Amazon Linux instances the ECS Developer Guide recommends the ecs-init package:
sudo yum install -y ecs-init
sudo service docker start
sudo start ecs
(If you put this in your user data scripts, do not use sudo.)