sylver-john Imhoff
sylver-john Imhoff

Reputation: 43

Nginx Docker's container : set default home page with a custom index.html

I work with docker container and i built one for nginx.

I would to change the nginx's home page with my index.html.

How can i tell to my nginx container where find my custom index.html and replace his own index.html by my index ?

Upvotes: 1

Views: 4358

Answers (1)

VonC
VonC

Reputation: 1323953

You could simply put a COPY command or an ADD command in your Dockerfile, which would copy your index.html file over the one provided by NGiNX (defined by the root directive, like /data/www/index.html)

COPY <src>... <dest>
ADD <src>... <dest>

Here:

COPY /path/to/your/index.html /data/www/index.html
ADD /path/to/your/index.html /data/www/index.html

Note, RUN or COPY are preferred to ADD:

The first encountered ADD instruction will invalidate the cache for all following instructions from the Dockerfile if the contents of <src> have changed.
This includes invalidating the cache for RUN instructions.

That is why the suggestion made in the comments is better:

if you have few changes

RUN sed -i -e"s/aaa/bbb" /data/www/index.html 

If you have many changes, ADD is still a valid option (try COPY first), but try to put it at the end of the dockerfile, not at the beginning or in the middle.

Upvotes: 2

Related Questions