How to Run an Nginx Web Server Container with Custom Directory and Settings
2 min readMar 25, 2023
When it comes to running a web server, containerization can be a convenient way to isolate and manage the server’s resources. In this article, I will go through the steps to run an Nginx web server container with a custom directory and settings, including automatically deleting the container when closed, listening on port 8080, and limiting container memory to 256 MB.
To start, I will use the docker run command to start a new container. Here is the full command:
docker run --rm -p 8080:80 -m 256m -v /tmp/webpage/:/usr/share/nginx/html:ro nginx
Let’s break down the command and its parameters:
docker run
: Command to run a new container.--rm
: Automatically remove the container when it exits.-p 8080:80
: Map port 80 from the container to port 8080 on the host.-m 256m
: Limit the container's memory to 256MB.-v /tmp/webpage/:/usr/share/nginx/html:ro
: Mount the directory/tmp/webpage/
on the host to/usr/share/nginx/html
the container instr read-only mode.nginx
: Name of the Nginx image to run.
By default, Nginx serves content from the /usr/share/nginx/html
directory, which is where I've mounted…