Deploy a secure and minimal NGINX container image built by Minimus to optimize security
index.html
file to override the default directory.
-d
):
Map the ports
-p
flag maps port 80 on the host machine to port 8080 on your container. Minimus NGINX defaults to port 8080 so it can run as an unprivileged process anywhere, even Kubernetes.Here’s the general command for mapping the host port to the container port:Bind mount the directory file
html.dir
file directly in the container would require copying it back and forth and would be unnecessarily tedious.Instead of directly editing the directory file, it is simpler to copy the desired directory file to the host and map it to the default directory path in the NGINX configuration. See the detailed instructions below.Bind mount the configuration file
/usr/share/nginx/html
) is specified by the root directive in the NGINX configuration file (nginx.conf
):
static
folder and nest it under site
. The -p
flag creates all the directories in the path, so it’s useful for setting up nested directory structures in a single step.
index.html
file to the new directory.
index.html
file from the host to the default directory path in the configuration file. For our example, we’ll add the following parameter when running the NGINX container:
:ro
is a standard best practice for protecting the container from accidentally or maliciously modifying host data.
Prerequisite: Validate your Docker Compose version
Create the Compose file
compose.yaml
file that defines the NGINX service with the appropriate configurations. The configuration details are explained below.Run the service
compose.yaml
file is located.-d
flag is for detached mode, so your terminal stays free.Verify the container
docker ps
to confirm that the container is running. You can run docker inspect
to review the container’s settings and status.Visit your NGINX site
compose.yaml
file with the following code:
nginx
in our example).myNginxContainer
).80:8080
)./home/me/site/static:/usr/share/nginx/html
: mounts your static file directory to the container’s HTML directory./home/me/nginx.conf:/etc/nginx/nginx.conf
: mounts your custom NGINX configuration file to the container’s config directory.