Modify nginx base image with a Dockerfile

51 Views Asked by At

On my virtual machine, i created this Dockerfile:

FROM ubuntu:latest
RUN apt-get -y update && apt-get -y install nginx
COPY content/index.html /usr/share/nginx/html/index.html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

because i want to alter the nginx base image to my own by starting off with replacing the html file.

When the container is ran and everything's working fine i still see the default nginx html file when i go to the ip address, even though when i use docker exec commands and go inside the container i can see that my html file is indeed copied but the changes are not reflected.

what could be the issue?

1

There are 1 best solutions below

1
datawookie On BEST ANSWER

For NGINX installed on Ubuntu the default NGINX welcome page is actually not found at /usr/share/nginx/html/index.html but at /var/www/html/index.nginx-debian.html.

Update your Dockerfile:

FROM ubuntu:latest

RUN apt-get -y update && apt-get -y install nginx

COPY content/index.html /var/www/html/index.nginx-debian.html

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]

Test contents for content/index.html:

Hello, World!

Build and run.

docker build -t nginx-test . && docker run -it -p 80:80 nginx-test

enter image description here