How to start docker in AWS EC2? - amazon-web-services

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

Related

Setting up Network (TCP) Load balancer for GCE instances with Container-Optimized OS

I have a containerized server, which is running on GCE (using Container-optimized OS feature). Now that the server is running, I am trying to set up a load balancer between my server and clients, but setting up load balancer requires me to create a start script, which only works on Debian OS. At the end of the day, I just need my server to be load balanced over TLS.
My server serves RPCs over port 8080, do I need the startup script provided in the GCP document?
apt-get update
apt-get install apache2 -y
a2ensite default-ssl
a2enmod ssl
vm_hostname="$(curl -H "Metadata-Flavor:Google" \
http://169.254.169.254/computeMetadata/v1/instance/name)"
echo "Page served from: $vm_hostname" | \
tee /var/www/html/index.html
systemctl restart apache2
If I do need it, how do I use apt-get on Container-Optimized OS?
Google Compute Engine Container Optimized OS (COS) is locked down. You do not have tools such as apt that modify the host operating system. Instead, deploy a container-based application.
The script in your question is an example for demonstration purposes with Compute Engine and does not apply to COS.

Locked out of ec2 instance after installing Docker on it

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.

AWS Cloudshell unable to start docker service

I have been created EKS cluster.
Now, I'm trying to create docker image to push it into my private ECR so I just installed docker using the following command:
amazon-linux-extras install docker
The installation succeed but when I'm tried to use docker I got the following:
[cloudshell-user#ip-10-0-73-203 ~]$ docker images
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
When I'm trying to start docker service I got:
[cloudshell-user#ip-10-0-73-203 ~]$ sudo systemctl start docker
Failed to get D-Bus connection: Operation not permitted
How can I solve it? Should I need to use another user?
Unfortunately this cannot be done (today).
Currently, the AWS CloudShell compute environment doesn't support Docker containers.
From the doc page.
An alternative would be to run a full fledge instance using Cloud9. Note Cloud9 has a cost as it is backed by an EC2 instance.

How to open glassfish admin UI (console) in AWS ElasticBeansTalk installed with glassfish 4.1 java 8?

I have deployed my war file on AWS ElasticBeanstalk (setup with glassfish4.1 java 1.8). I want to open glassfish admin UI in browser.
Thanks in advance!
I am not sure its possible to access the glassfish console UI (at least I never went to this point so far, but might be possible using docker forward port ...)
what I do is the following:
SSH into the ec2 instance elastic beanstalk has provisioned
run sudo docker ps -a to find out about the container running on the instance
ssh into the container sudo docker exec -it <container id here> bash
this will log you on the container running glassfish, from there you can run the asadmin command

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.)