user9730761
user9730761

Reputation:

How to install nginx 1.14.X inside docker?

# 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

This is my Dockerfile. I want to Install 1.14.2 of Nginx but Error occurs:

E: Version '1.4.*' for 'nginx' was not found.

How can I install specific version of nginx inside docker this way?

Upvotes: 4

Views: 4807

Answers (5)

Lion
Lion

Reputation: 17879

You should prefer the official images and only self-build an image if there is no alternative. This saves you work, is more flexible and makes maintaining (updates) easier. In your case, just use the 1.14 tag:

FROM nginx:1.14

However, from today it would make sense to use a more recent release insead. But the process is the same, just look in the Docker hub for avaliable tags (e.g. 1.23) and replace it in your Dockerfile.

PHP also have official images if needed. They can be used for different stacks, e.g. Apache2 with mod_php, PHP-FPM for use with Nginx (should be hosted in a seperate container) or just the PHP CLI.

It's also possible to further simplify your Dockerfile. For example, the step

RUN rm -v /etc/nginx/nginx.conf

is not required. The COPY overrides the existing one. It's also not really clean to copy an entire nginx.conf from your host and then modifying it. I'd either modify the existing one or copy my own. But in the second case, it should be a complete file. Otherwise it's confusing when someone looks at the Nginx configuration file and doesn't now that further modifications are done in the Dockerfile.

Upvotes: 0

KAREEP NAVAS
KAREEP NAVAS

Reputation: 19

FROM ubuntu

ENV NGINX_VERSION 1.14.0-0ubuntu1.2

RUN apt-get update && apt-get -y install nginx=$NGINX_VERSION

Upvotes: 0

MyTwoCents
MyTwoCents

Reputation: 7624

As pointed out by @larsks Ubuntu 16.04 supports nginx only till version 1.10.3

Official wiki with more detail

So best/safe option would be either move your base OS to 18.04 or use nginx 1.10.3

Just for reference how you can install Nginx from src.

wget https://nginx.org/download/nginx-1.14.0.tar.gz
tar zxf nginx-1.14.0.tar.gz
cd nginx-1.14.0
make
sudo make install
sudo nginx

More detail here

Upvotes: 2

Yash Jagdale
Yash Jagdale

Reputation: 1508

Other options for this is you can download tar(source code) and extract it. Below are the command which you need to follow:-

$ wget https://nginx.org/download/nginx-1.14.0.tar.gz
$ tar zxf nginx-1.14.0.tar.gz
$ cd nginx-1.14.0
$ make
$ sudo make install
$ sudo nginx

More Details can be seen here Nginx- Install doc

Upvotes: 0

larsks
larsks

Reputation: 311406

You've based your Docker image on ubuntu:16.04. The 16.04 release of Ubuntu does not include nginx 1.14.x; it only has 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
[...]

If you want a more recent version of nginx, consider basing your image on a more recent Ubuntu release, or building it yourself from source. For example, the 18.04 release of Ubuntu includes 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
[...]

Upvotes: 1

Related Questions