Step 6: Confirm the installation of docker on EC2 Ubuntu 18.04 instance, use the following command.
Step 7: Check the detailed information about docker and its other components using the following command.
Question: How to run “docker” command without “sudo” on AWS EC2 Ubuntu 18.04 instance?
Answer: In order to do so, we need to add the “ubuntu” user under the “docker” group, follow the forthcoming steps to achieve that.
Step 8: From the command below, check the details about the “ubuntu” user on EC2 Ubuntu 18.04 instance, it is created by default.
Step 9: Use the following command to add the “ubuntu” user on AWS EC2 Ubuntu 18.04 to “docker” group in order to run “docker command” without “sudo“.
Step 10: You can confirm with the help of command below, that the user “ubuntu” is now added to “docker” group.
Note: Before going to the next step, make sure you “Logout” and “Login” again, so that new configuration for the user can be reflected.
Step 11: Use the “docker -v” command without “sudo” as shown below, and confirm that now all the docker commands can be executed without using “sudo“.
With the private key downloaded and the instance running, let us now log in and deploy our application.
For this, we need the .pem file downloaded earlier and a terminal window. We will also need a user name for the chosen AMI - for the Amazon Linux AMI, the default username is ec2-user.
The instance's public DNS is also required to connect to it and this can be found on the instance's details section on the EC2 console dashboard.
Let us open a terminal in the folder that contains our private key file. We'll first need to change the key permissions to avoid seeing an "unprotected key file" warning:
$ chmod 400 <PRIVATE_KEY_FILE_NAME>
Then we can use the ssh utility, along with our key file, to connect to the instance:
$ ssh -i <PRIVATE_KEY_FILE_NAME> ec2-user@<PUBLIC_DNS>
__| __| __|
_| ( \__ \ Amazon Linux 2 (ECS Optimized)
____|\___|____/
For documentation, visit http://aws.amazon.com/documentation/ecs
12 package(s) needed for security, out of 25 available
Run "sudo yum update" to apply all updates.
-bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory
[ec2-user@ip-###-##-##-## ~]$
The response above means that we have successfully signed in to our instance, we will start by pulling our application image from Dockerhub and running it using the docker run command:
$ docker run -it -d -p 8000:8000 <DOCKERHUB_USERNAME>/django_ec2
Once our Docker image is pulled into our instance and successfully running, we can now access our Django application on the web through the same address we used to SSH into it.
When we do, we are welcomed with:
댓글 영역