How to Deploy Container in Cloud Raya using Docker
This article will explain how to deploy container in Cloud Raya using Docker. Before knowing how to deploy container using docker, let’s understand the basic of it.
What is Docker?
Docker is a tool that allows developers, sys-admins, etc. to easily deploy their applications in a sandbox (called containers) to run on the host operating system, e.g. Linux.
Accordingly, the key benefit of Docker is that it allows users to package an application with all of its dependencies into a standardized unit for software development. Unlike virtual machines, containers do not have high overhead and hence enable more efficient usage of the underlying system and resources.
What are containers?
To begin with, the industry standard today is to use Virtual Machines (VMs) to run software applications. VMs run applications inside a guest Operating System, which runs on virtual hardware powered by the server’s host OS.
In addition, VMs are great at providing full process isolation for applications: there are very few ways a problem in the host operating system can affect the software running in the guest operating system, and vice-versa. But this isolation comes at great cost — the computational overhead spent virtualizing hardware for a guest OS to use is substantial.
Furthermore, containers take a different approach. By leveraging the low-level mechanics of the host operating system, containers provide most of the isolation of virtual machines at a fraction of the computing power.
Before we begin to the tutorial, the following are the stack versions that we are going to install:
- OS: Ubuntu 18.04 (LTS)
- Latest Docker Engine stable version for Ubuntu 18.04
- Latest Docker Repository
In short, there are three tasks that we need to do:
- Open necessary port on CloudRaya Security Profile
- Install docker (Community Edition)
- Deploy or Create a Web Server container with Nginx
Open Necessary Port on Cloud Raya frontend
Before we start further, open necessary ports to your instances, go to https://cp.cloudraya.com/ >> Home >> networking >> Security Profile
There are at least three ports that needs to be opened 80, 443 (for HTTP and HTTPS) and 22 (for SSH)
Please run the following command to ensure there is no old docker installed:
sudo apt-get remove docker docker-engine docker.io containerd runc
Additionally, it’s OK if
apt-get reports that none of these packages are installed.
Install using the repository
Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.
Setup The Repository
$ sudo apt-get update
$ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
There will appear a confirmation prompt, please type “Y” to continue
Add Docker’s official GPG key:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
To set up the stable repository:
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Install Docker Engine
To install the Docker Engine command, run:
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
Verify that Docker Engine is installed correctly by running the
$ sudo docker run hello-world
There will be an information that stated as follows after verification is running properly:
Hello from Docker! This message shows that your installation appears to be working correctly.
Deploy or Create a Web Server container with Nginx
Now, we have to create a hosting simple static content command.
Create a folder
Download, deploy latest nginx image and configure the web-root. We named it into “test-nginx”
docker run --name test-nginx -v /var/www/html:/usr/share/nginx/html:ro -d nginx
After that, verify if container is running:
docker container ls
Verify port 80 whether it’s listened or not by running the following command:
netstat -tulpn | grep 80
Then, create a test script:
Append the following test script:
TEST WEBSERVER as CONTANIER
When it’s done. Save the modification by pressing “ctrl + x“, Choose “Y” then press “Enter“
Please open a browser app such as Chrome, Firefox and insert your Public IP instance: http://126.96.36.199/ and it will show the following display:
TEST WEBSERVER as CONTANIER
list all Docker containers
docker container ls -a
Stop a specific container
docker container stop [container_id]
Remove a stopped container
docker container rm [container_id]
Remove all stopped containers:
docker container rm $(docker container ls –aq)
List Docker image
docker image ls
Remove an image, or multiple images:
docker image rm [image_id1]
docker image rm [image_id1] [image_id2]
To sum up, this article explains about running NGINX official image, adding our custom html files and creating a container based off of the official image
Last but not least, we hope this helps you. Thank you.