Files
Scrap-Web/manual/devopsDigitalOcean.tex
T

229 lines
6.0 KiB
TeX

\chapter{Digital Ocean Docker Deployment}
\ChapterLabel{Digital Ocean}
\section{Overview}
This chapter documents the deployment of the Dockerized website to a
DigitalOcean Droplet. The DigitalOcean Droplet was configured as an Ubuntu
Linux server and was accessed remotely using SSH. Docker was then installed
and configured on the Droplet so that the website could run inside a Docker
container.
The deployment process consisted of creating the DigitalOcean Droplet,
connecting to the Droplet through SSH, updating the Ubuntu operating system,
installing Docker, transferring the website project to the server, building
the Docker image, running the Docker container, configuring the firewall, and
accessing the deployed website through the Droplet's public IP address.
DigitalOcean Droplets are Linux-based virtual machines that can be used to
host websites and other applications. The DigitalOcean documentation
recommends using SSH keys for secure access to Droplets
\section{Create the DigitalOcean Droplet}
A DigitalOcean Droplet was created through the DigitalOcean Control Panel.
The Droplet was configured with an Ubuntu operating system and a suitable
shared CPU plan for the website deployment.
After the Droplet was created, DigitalOcean provided a public IPv4 address.
This address was used to remotely access the server and later to access the
deployed website.
The public IPv4 address of the deployed Droplet is:
\begin{center}
\textbf{137.184.211.98}
\end{center}
\section{Connect to the Droplet Using SSH}
After creating the Droplet, an SSH connection was established from the local
Mac terminal. The following command was used to connect to the remote Ubuntu
server:
\begin{minted}{bash}
ssh root@137.184.211.98
\end{minted}
After successfully connecting, the terminal displayed the Ubuntu server
prompt. This confirmed that commands entered in the terminal were being
executed on the DigitalOcean Droplet rather than on the local computer.
\section{Update the Ubuntu Server}
The Ubuntu package repository was updated before installing the software
required for the deployment. The following command was executed:
\begin{minted}{bash}
apt update
\end{minted}
The installed packages were then upgraded using:
\begin{minted}{bash}
apt upgrade -y
\end{minted}
\section{Install and Verify Docker}
Docker was installed directly on the DigitalOcean Ubuntu Droplet. The
following command was used:
\begin{minted}{bash}
apt install docker.io -y
\end{minted}
Docker was then configured to start automatically when the server starts:
\begin{minted}{bash}
systemctl enable docker
\end{minted}
The Docker service was started with:
\begin{minted}{bash}
systemctl start docker
\end{minted}
The Docker installation was verified using:
\begin{minted}{bash}
docker --version
\end{minted}
The Docker service status was also checked using:
\begin{minted}{bash}
systemctl status docker
\end{minted}
\section{Transfer the Website to the Droplet}
The website source code was transferred to the DigitalOcean Droplet. The
application contained the Dockerfile and the source files required to build
and run the website.
The project directory on the Droplet contained the Dockerfile used to create
the Docker image.
The project was then accessed from the terminal using:
\begin{minted}{bash}
cd digital-ocean-docker
\end{minted}
\section{Build the Docker Image}
After entering the project directory, a Docker image was created using the
following command:
\begin{minted}{bash}
docker build -t digital-ocean-docker .
\end{minted}
The \texttt{-t} option assigns the image the name
\texttt{digital-ocean-docker}. The period at the end of the command specifies that the
current directory is used as the Docker build context.
The resulting Docker image was verified with:
\begin{minted}{bash}
docker images
\end{minted}
\section{Run the Docker Container}
The Docker container was started using the following command:
\begin{minted}{bash}
docker run -d \
--restart unless-stopped \
-p 80:3000 \
--name digital-ocean-docker \
digital-ocean-docker
\end{minted}
The port mapping was configured as:
\begin{center}
\texttt{80:3000}
\end{center}
This maps port 80 on the DigitalOcean Droplet to port 3000 inside the
Docker container. Since the Express application runs on port 3000, requests
received by the Droplet on port 80 are forwarded to the application inside
the Docker container.
The \texttt{docker ps} command was used to verify that the container was
running:
\begin{minted}{bash}
docker ps
\end{minted}
The expected port mapping appeared similar to:
\begin{minted}{text}
0.0.0.0:80->3000/tcp
\end{minted}
This confirmed that the website was exposed through port 80 of the
DigitalOcean Droplet.
\section{Configure the Firewall}
The Ubuntu firewall was configured to allow SSH, HTTP, and HTTPS traffic.
OpenSSH uses port 22 for the SSH connection to the server.
The following commands were used:
\begin{minted}{bash}
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
\end{minted}
The firewall was then enabled:
\begin{minted}{bash}
ufw enable
\end{minted}
The firewall configuration was verified with:
\begin{minted}{bash}
ufw status
\end{minted}
The firewall configuration allowed the following traffic:
\begin{itemize}
\item Port 22 -- SSH/OpenSSH access to the Droplet.
\item Port 80 -- HTTP access to the deployed website.
\item Port 443 -- HTTPS access for secure web traffic.
\end{itemize}
Port 22 was allowed before enabling the firewall so that the existing SSH
connection to the Droplet would remain accessible.
\section{Access the Deployed Website}
After the Docker container was started and port 80 was exposed, the deployed
website was accessed through the public IPv4 address assigned to the
DigitalOcean Droplet.
The website can be accessed at:
\begin{center}
\url{http://137.184.211.98}
\end{center}
The public website link is also provided below:
\begin{center}
\href{http://137.184.211.98}{\textbf{DigitalOcean Deployed Website}}
\end{center}
The browser request is sent to the Droplet on port 80 and is forwarded to
port 3000 inside the Docker container.