Ubuntu Docker Nginx

  • Setup Nginx as a Reverse-Proxy inside Docker. For a basic setup only 3 things are needed: 1) Mapping of the host ports to the container ports 2) Mapping a config file to the default Nginx config file at /etc/nginx/nginx.conf 3) The Nginx config. In a docker-compose file, the port mapping can be done with the ports config entry, as we've seen.
  • The operating system is assumed to be Ubuntu 20.04, although it is pretty easy to generalize to other distros; Let's install the two main packages that we will need in this setup: $ sudo apt install docker.io nginx -y Problem statement.
  • I had tried updating docker file with. #RUN sudo apt-get install -y nginx-module-njs. But get similar message that connate find package. Key here is I am starting with ubuntu image. I am interested in how to setup docker to load the 'dynamic' module with nginx. Docker ubuntu nginx dockerfile nginx-config.

$ docker login $ docker tag nginx-frontend /nginx-frontend $ docker push /nginx-frontend Awesome Compose. The Awesome compose project is a curated list of Docker Compose samples. These samples provide a starting point for how to integrate different services using a Compose file and to manage their deployment with Docker Compose.

Installing Docker

If you've heard about Docker, you may know about its ability to help you build applications in a sealed environment. This is helpful, as it eliminates any changes that may occur between your developer machine and your production machine, such as a VPS server from Hostwinds.

How To Install Docker

Install docker using this command:

Container technology is beneficial in sealing an environment, but when you need to configure things like SSL or other applications, this can introduce additional complexity.

Installing Nginx

Nginx (Pronounced 'Engine-ex') is a highly configurable web server. This makes it great for things setting up what's called a 'reverse proxy,' which simply means that this webserver will take in requests and forward them to our Docker containers. Add this into your Hostwinds VPS with:

Setting up a simple Apache Container

For this, We're going to use the official Apache image on the Docker hub. It's documentation can be found here.

As the documentation mentions, we will need to create a DockerFile.

Using a text editor, such as nano (nano apache. docker), write a file with these contents:

Now create a file called index.html, and insert this into its contents:

It is possible to use any static page or even a directory in place of the index file. For simplicity, a single HTML file is fine. Once the file is written, run these commands to build the docker file.

Ubuntu

Visiting your server at [yourdomain:8080] or [your IP]:8080 Should result in seeing this page in your web browser

Configuring Nginx as a reverse proxy

With the docker container set up to serve your files, we can set up Nginx. This way, we can mostly leave the container's configuration alone and silo it off behind Nginx. Edit /etc/nginx/nginx.conf and add in this code:

Ubuntu Docker Nginx

Docker Ubuntu Nginx Start

From here, NGINX takes in all the public requests, and the Apache container serves your files.