docker - 如何在 docker 中安装 nginx 1.14.X?
问题描述
# 1. use ubuntu 16.04 as base image
FROM ubuntu:16.04
# defining user root
USER root
# OS update
RUN apt-get update
# Installing PHP and NginX
RUN apt-get install -y nginx=1.4.* php7.0
# Remove the default Nginx configuration file
RUN rm -v /etc/nginx/nginx.conf
# Copy a configuration file from the current directory
ADD nginx.conf /etc/nginx/
ADD web /usr/share/nginx/html/
# Append "daemon off;" to the beginning of the configuration
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
# Expose ports
EXPOSE 90
# Set the default command to execute
# when creating a new container
CMD service nginx start
这是我的 Dockerfile。我想安装 1.14.2 的 Nginx 但出现错误:
E: Version '1.4.*' for 'nginx' was not found.
如何以这种方式在 docker 中安装特定版本的 nginx?
解决方案
您已将 Docker 映像基于ubuntu:16.04
. Ubuntu 16.04 版本不包含 nginx 1.14.x;它只有 nginx 1.10.3:
$ docker run -it --rm ubuntu:16.04 bash
root@1d780d71ebd5:/# apt update
[...]
root@1d780d71ebd5:/# apt show nginx
Package: nginx
Version: 1.10.3-0ubuntu0.16.04.3
[...]
如果您想要更新版本的 nginx,请考虑将您的映像基于更新的 Ubuntu 版本,或者自己从源代码构建。例如,Ubuntu 18.04 版本包括 nginx 1.14:
$ docker run -it --rm ubuntu:18.04 bash
root@d7ca6d8960f6:/# apt update
[...]
root@d7ca6d8960f6:/# apt show nginx
Package: nginx
Version: 1.14.0-0ubuntu1.2
[...]
推荐阅读
- javascript - 解析错误:分配给右值
- mysql - 从重复行中选择最大值
- angular - 角表组件
- python - 匹配数字或 100% 但不匹配 99% 的正则表达式
- perl - 为什么 h2xs 生成带有尾随冒号的模块名称?
- firebird - Firebird 2.5 错误,文件“ReadFile”操作期间的 I/O 错误
- html - CSS 元素无法在电子邮件中正确显示
- angular - 使用 Angular 计算值
- jquery - 在 JQuery 中将 HTML 添加到段落中时,阅读更多按钮不起作用
- javascript - 在 ngOnInit()-Angular 4 中访问构造函数内部调用的 Async 方法的值