sudo docker pull nginx
sudo docker run --name my-nginx -p 8080:80 -v /some/content:/usr/share/nginx/html:ro -d nginx
sudo chmod -R 755 /some/content
First, update your system to ensure all packages are up to date.
sudo dnf update -y
CentOS 8 doesn't include the latest Nginx packages in its default repositories. To get the latest version, add the official Nginx repository.
Create a repository file for Nginx:
sudo nano /etc/yum.repos.d/nginx.repo
Add the following content to the file:
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
The nginx-stable
repository is enabled by default, while the nginx-mainline
repository is not. You can enable the nginx-mainline
repository by setting enabled=1
if you prefer to use the mainline version of Nginx.
Install Nginx using the dnf
package manager.
sudo dnf install nginx -y
Once the installation is complete, start the Nginx service and enable it to start on boot.
sudo systemctl start nginx
sudo systemctl enable nginx