News
Seven days of Black Friday madness — great deal from Serverspace!

THE NEW YEAR
WHEEL OF FORTUNE

Spin the wheel and win a guaranteed prize right now!

By registering, you are signing up to receiving emails.
VB
April 18 2023
Updated December 6 2024

How to run Nginx in a Docker container on Ubuntu

Docker FAQ NGINX

Why you could want to run nginx in docker

The one of the main docker advantage is total idempotency. Docker image is "thing in itself", you can copy or move it to other server and image's behavior will be the same.

Docker setup

Before run any "containerized" software, you should install docker itself. Let's to it:

curl -fsSL https://get.docker.com -o initial.sh; bash ./initial.sh

Docker setup

Create the directory for the project files:

mkdir -p ~/project/content

Create the directory

Put the content into this directory. I will just create one page for demo-purposes:

echo "<h1>Serverspace is the best hosting company</h1>" > ~/project/content/index.html

Put content to project

Start the service:

docker run --name nginxapp -p 80:80 -v ~/project/content:/usr/share/nginx/html nginx

Start the service

Server should give you correct answer if you open its IP via web:

Check the result

It is enough for minimal configuration, but you could "attach" additional config-files to the web-server if needed. Also I advice you run container with -d flag, this flag will "say" docker to run the container into background so you can close terminal session:

docker run --name nginxapp -p 80:80 -v ~/project/content:/usr/share/nginx/html -v ~/project/yourdomain.conf:/etc/project/conf.d/yourdomain.conf -d nginx

Additional configuration

Conclusion

In this matherial I said some advantages of containerized nginx running and described way to run it on Ubuntu 20.04.

You may be also interested in

Vote:
5 out of 5
Аverage rating : 5
Rated by: 1
1101 CT Amsterdam The Netherlands, Herikerbergweg 292
+31 20 262-58-98
700 300
ITGLOBAL.COM NL
700 300
We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.