How to fix No package nginx available in Docker
This error occurs when yum cannot find a requested package in its configured repositories during Docker builds on CentOS/RHEL-based images. The most common cause is that the package exists in a repository (like EPEL) that isn't enabled by default.
Quick fix
Fixes No package nginx available
FROM centos:7
# ❌ WRONG - nginx not in base repos
RUN yum install -y nginx
# ✅ CORRECT - Enable EPEL first
RUN yum install -y epel-release && \
yum install -y nginx- Enable EPEL repository before installing packages
- Clean yum cache and update repository metadata
- Verify package name and search for alternatives
- Fix archived repository URLs for EOL distributions
FROM centos:7# ❌ WRONG - nginx not in base reposRUN yum install -y nginx# ✅ CORRECT - Enable EPEL firstRUN yum install -y epel-release && \yum install -y nginxNo package nginx available
What this error means
The "No package available" error appears when yum (Yellowdog Updater Modified), the package manager used in CentOS, RHEL, and Fedora-based Docker images, cannot locate a requested package in any of its configured repositories. Unlike Debian-based systems where packages are generally available in base repositories, many common packages on RHEL-based systems require enabling additional repositories like EPEL (Extra Packages for Enterprise Linux). This error is particularly common in Docker containers because base images ship with minimal repository configurations. Packages like nginx, htop, or many development tools aren't available in the base CentOS or RHEL repositories and require adding the EPEL repository or other third-party repos before installation.
Typical symptoms
- Build fails with 'No package <package-name> available'
- yum install commands succeed on host but fail in Dockerfile
- Error appears even for common packages like nginx, htop, or nodejs
- Package installs fine on Ubuntu but fails on CentOS-based images
- Message 'Nothing to do' appears after the error
Common causes
- Package exists in EPEL repository which isn't enabled by default
- Package name differs between distributions (e.g., httpd vs apache2)
- Repository URLs are outdated or unreachable (especially for EOL CentOS versions)
- Package is not available for the specific architecture or OS version
- Repository is configured but disabled in yum.repos.d configuration
- Network connectivity or DNS issues preventing repository access
How to fix "No package nginx available"
Many common packages are only available in the EPEL (Extra Packages for Enterprise Linux) repository. Enable it first:
FROM centos:7
# ❌ WRONG - nginx not in base repos
RUN yum install -y nginx
# ✅ CORRECT - Enable EPEL first
RUN yum install -y epel-release && \
yum install -y nginxFor Rocky Linux or AlmaLinux (CentOS replacements):
FROM rockylinux:9
RUN dnf install -y epel-release && \
dnf install -y nginxThe epel-release package adds the EPEL repository configuration, making thousands of additional packages available.
If repositories are configured but packages still aren't found, clear the cache and refresh:
RUN yum clean all && \
yum makecache && \
yum install -y epel-release && \
yum install -y nginxOr in a single optimized layer:
RUN yum clean all && \
yum install -y epel-release && \
yum install -y nginx && \
yum clean all && \
rm -rf /var/cache/yumThe final cleanup reduces the image size by removing cached package files.
Package names differ between distributions. Search for the correct name:
# Run interactively to search for packages
docker run -it centos:7 bash
# Search for packages containing a keyword
yum search nginx
# List all available packages from EPEL
yum install -y epel-release
yum --disablerepo="*" --enablerepo="epel" list availableCommon package name differences:
| Debian/Ubuntu | CentOS/RHEL |
|---------------|-------------|
| apache2 | httpd |
| php | php |
| mysql-server | mariadb-server |
| libssl-dev | openssl-devel |
| build-essential | gcc make |
CentOS 7 and 8 have reached End-of-Life. Update repository URLs to use vault or archive mirrors:
For CentOS 7 (EOL July 2024):
FROM centos:7
# Update repo URLs to vault (archived)
RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* && \
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
# Now install packages
RUN yum install -y epel-release && \
yum install -y nginxFor EPEL 7 (archived):
RUN yum install -y https://archives.fedoraproject.org/pub/archive/epel/7/x86_64/Packages/e/epel-release-7-14.noarch.rpmBetter approach: Migrate to actively maintained distributions like Rocky Linux 9, AlmaLinux 9, or Fedora.
For specific software, use the vendor's official repository instead of EPEL:
Nginx official repository:
FROM centos:7
# Add Nginx official repo
RUN echo '[nginx-stable]' > /etc/yum.repos.d/nginx.repo && \
echo 'name=nginx stable repo' >> /etc/yum.repos.d/nginx.repo && \
echo 'baseurl=http://nginx.org/packages/centos/$releasever/$basearch/' >> /etc/yum.repos.d/nginx.repo && \
echo 'gpgcheck=1' >> /etc/yum.repos.d/nginx.repo && \
echo 'enabled=1' >> /etc/yum.repos.d/nginx.repo && \
echo 'gpgkey=https://nginx.org/keys/nginx_signing.key' >> /etc/yum.repos.d/nginx.repo
RUN yum install -y nginxNode.js from NodeSource:
RUN curl -fsSL https://rpm.nodesource.com/setup_18.x | bash - && \
yum install -y nodejsIf using Amazon Linux 2, use the amazon-linux-extras command:
FROM amazonlinux:2
# Enable and install nginx
RUN amazon-linux-extras enable nginx1 && \
yum install -y nginx
# Or use the shorthand
RUN amazon-linux-extras install nginx1 -yFor Amazon Linux 2023, packages are available via dnf:
FROM amazonlinux:2023
RUN dnf install -y nginxAmazon Linux uses its own curated repositories rather than EPEL.
Advanced notes
CentOS Stream vs CentOS Linux: CentOS Linux (7, 8) has reached EOL. CentOS Stream is a rolling-release distribution that sits upstream of RHEL. For production containers, consider Rocky Linux or AlmaLinux as drop-in CentOS replacements.
Repository priorities: When multiple repositories provide the same package, yum uses the yum-plugin-priorities package to determine which version to install. Lower priority numbers take precedence.
GPG keys: If you encounter GPG key errors, you can temporarily bypass verification (not recommended for production):
RUN yum install -y --nogpgcheck epel-releaseContainer-specific images: For nginx specifically, consider using the official nginx Docker image instead of installing on CentOS:
FROM nginx:alpine
# or
FROM nginx:1.25dnf vs yum: On CentOS 8+, RHEL 8+, Fedora, Rocky Linux, and AlmaLinux, dnf has replaced yum. While yum still works as an alias, prefer dnf for new Dockerfiles:
FROM rockylinux:9
RUN dnf install -y epel-release && dnf install -y nginxMinimal installations: Use yum install --setopt=tsflags=nodocs to skip documentation and reduce image size.
Frequently asked questions
- What does "No package nginx available" mean?
- The "No package available" error appears when yum (Yellowdog Updater Modified), the package manager used in CentOS, RHEL, and Fedora-based Docker images, cannot locate a requested package in any of its configured repositories. Unlike Debian-based systems where packages are generally available in base repositories, many common packages on RHEL-based systems require enabling additional repositories like EPEL (Extra Packages for Enterprise Linux). This error is particularly common in Docker containers because base images ship with minimal repository configurations.
- How do I fix "No package nginx available"?
- This error occurs when yum cannot find a requested package in its configured repositories during Docker builds on CentOS/RHEL-based images. The most common cause is that the package exists in a repository (like EPEL) that isn't enabled by default.
- What causes "No package nginx available"?
- Package exists in EPEL repository which isn't enabled by default Package name differs between distributions (e.g., httpd vs apache2) Repository URLs are outdated or unreachable (especially for EOL CentOS versions)
- Is the "No package nginx available" error serious?
- It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- 📚Docker Official Documentation
- 💬Docker RUN yum -y install epel-release causes ERROR(Stack Overflow)
- 💬CentOS 7 - yum install not working(Stack Overflow)
- 📝
- 📖100 Common Docker Errors & Solutions(Official Docs)
- 📖