Skip to content
tbrogan25 edited this page Apr 16, 2023 · 7 revisions

Summary

Add docker config file to GH

The following configuration is for an Ubuntu 20.04 Docker server with an Nginx web server running within a Docker container. The machine is consequently named docker.

Initial Config

The network was configured as follows with netplan.

  • sudo nano /etc/netplan/00-installer-config.yaml

image

  • sudo netplan apply

Installing Docker

The below steps detail a connection to the official Docker repository by adding a new package source, adding the Docker GPG key for a valid download, and a package installation.

sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
sudo apt install docker-ce

Nginx Docker Container

An official Docker NGINX image exists and can be pulled from the remote Docker Hub. To start an NGINX server on port 8080 with the image, run:

  • docker run -it --rm -d -p 8080:80 --name web nginx

image

Now the NGINX test page should appear in the browser on port 8080. Here is the linked index.html config file.

Adding Custom HTML to NGINX

We will be creating a bind mount to mount a local directory containing the desired HTML files to the NGINX container. We first need to stop Docker container with:

  • docker stop web

Because NGINX refers to the /usr/share/nginx/html directory for files to be hosted, we need to mount existing local directories to this directory. In my home directory, we created another directory called site-content and added a custom index.html file within it.

image

Mount the site-content directory with:

  • $ docker run -it --rm -d -p 8080:80 --name web -v ~/site-content:/usr/share/nginx/html nginx

Now the custom index.html should appear on port 8080 from w1's browser.

image

Clone this wiki locally