Docker Installation of Nginx
Nginx is a high-performance HTTP and reverse proxy web server, also providing IMAP/POP3/SMTP services.
1. Check Available Nginx Versions
Visit the Nginx image repository address: https://hub.docker.com/_/nginx?tab=tags.
You can view other versions of Nginx by sorting, with the default being the latest version nginx:latest.
You can also find other versions you want in the dropdown list.
Additionally, we can use the docker search nginx
command to check available versions:
$ docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 3260 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker c... 674 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable ... 207 [OK]
million12/nginx-php Nginx + PHP-FPM 5.5, 5.6, 7.0 (NG), CentOS... 67 [OK]
maxexcloo/nginx-php Docker framework container with Nginx and ... 57 [OK]
...
2. Pull the Latest Nginx Image
Here, we pull the official latest version of the image:
$ docker pull nginx:latest
3. Check Local Images
Use the following command to check if Nginx is installed:
$ docker images
From the image above, we can see that we have installed the latest version (latest) of the Nginx image.
4. Run the Container
After installation, we can use the following command to run the Nginx container:
$ docker run --name nginx-test -p 8080:80 -d nginx
Parameter explanations:
- --name nginx-test: Container name.
- -p 8080:80: Port mapping, mapping local port 8080 to the container's internal port 80.
- -d nginx: Setting the container to run in the background.
5. Successful Installation
Finally, we can access the Nginx service on port 8080 directly through the browser.