0

I am docker newbie. I am trying to build a custom nginx image (lngin). Since I want to do run some custom scripts in my container before I start nginx. I am trying to use the following as a guideline https://stackoverflow.com/questions/42280792/reuse-inherited-images-cmd-or-entrypoint

My Dockerfile looks like this.

FROM --platform=linux/amd64  ubuntu/nginx:latest
RUN apt-get update && apt-get install -y vim
COPY resources/index.html /usr/share/nginx/html/index.html
ADD INIT_SCRIPTS/prestart.sh /prestart.sh
RUN chmod 765 /prestart.sh
ENTRYPOINT ["/bin/sh","-c"]
CMD ["/prestart.sh"]

My prestart.sh file is this.

#!/bin/bash
echo "Start my initialization script..."
echo $HOSTNAME
# Now start niginx
/docker-entrypoint.sh    "nginx"  "-g" "daemon off;"

My custom index.html looks like this

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Hello World -*** Nginx Docker ***-</title>
    <style>
        h1{
            font-weight:lighter;
            font-family: Arial, Helvetica, sans-serif;
        }
    </style>
</head>
<body>

<h1> Hello World </h1>

</body> </html>

I can start the container correctly with docker run -it -p 8080:80 --name web lngin and the output log looks like this

#docker run -it -p 8080:80 --name web  lngin                                    
Start my initialization script...
bd8a7451f497
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Configuration complete; ready for start up

When I login into my container docker exec -it web /bin/bash I can see the new index.html, I also made sure that it has my new contents by opening it in vim inside the container

root@cbb17bc1e06e:/# ls -l /usr/share/nginx/html/
total 4
-rw-r--r-- 1 root root 448 Feb 26 17:31 index.html

I can see the new index.html but when I run login into the URL http://localhost:8080/ it still shows me the default index.html that came with the base image.

enter image description here

Why is nginx not picking up the new index.html ?

  • According to https://hub.docker.com/r/ubuntu/nginx you should put the file to /var/www/html . Also, please post the nignx.conf you're using. – Daniel Feb 26 '23 at 23:59
  • Thanks Daniel, it worked correctly at the path you suggested. I was looking over here https://hub.docker.com/_/nginx – ivar kesav Feb 27 '23 at 00:37
  • Can you run: docker logs dockercontainer what is your output ? – Nick Jul 20 '23 at 09:26

0 Answers0