I have a very simple HTML file which outputs 'Container with HTML file
'.
I have this Dockerfile where I copy my welcome.html
(my simple HTML page):
FROM nginx:latest
WORKDIR /usr/share/nginx/html
COPY welcome.html welcome.html
Then I create an image in the directory containing this HTML page:
docker image build -t html_nginx .
and run a container using:
docker container run -p 80:80 --rm html_nginx
But when the container is run on port 80, I get the default 'Welcome Page
' of nginx and not my desired output from the HTML file ('Container with HTML file
').
How much ever I try, I have never been able to get my message printed on the browser.
Can someone please point me in the right direction?
Let's start our Nginx Docker container with this command: sudo docker run --name docker-nginx -p 80:80 nginx.
The WORKDIR command is used to define the working directory of a Docker container at any given time. The command is specified in the Dockerfile. Any RUN , CMD , ADD , COPY , or ENTRYPOINT command will be executed in the specified working directory.
nginx:<version>It is designed to be used both as a throw away container (mount your source code and start the container to start your app), as well as the base to build other images off of.
The default nginx config will load the index.html
file from the /usr/share/nginx/html
directory.
This default is set in /etc/nginx/conf.d/default.conf
with the lines
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
So to fix this you can copy welcome.html
into the /usr/share/nginx/html
directory as index.html
, or change the above index
line to reference welcome.html
and reload. To make this change more permanent you would likely want to create a dockerfile that defines a docker image overriding the config copied in where you have already set this value.
Alternatively you should just be able to access /welcome.html
when hitting your server e.g. http://localhost:80/welcome.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With