skip to Main Content

I wrote such a docker file, run the container and open localhost, opens nginx, although the site should open from the /var/www/html folder . How to solve the problem?

FROM nginx

RUN apt-get update && apt-get -y install zip
WORKDIR  /02_Continuous_Delivery/html
COPY . /var/www/html
RUN rm -f /var/www/html/site.zip; zip -r /var/www/html/site.zip /02_Continuous_Delivery/html
EXPOSE 80

2

Answers


  1. Chosen as BEST ANSWER

    i have a solution

    FROM nginx
    
    RUN apt-get update && apt-get -y install zip
    
    COPY 02_Continuous_Delivery/html /usr/share/nginx/html
    RUN zip -r /usr/share/nginx/html/site.zip /usr/share/nginx/html
    EXPOSE 80
    #CMD ["nginx","-g","daemon off;"]
    

  2. Your problem is that by default nginx image provides config (/etc/nginx/conf.d/default.conf) like this:

    server {
        listen       80;
        listen  [::]:80;
        server_name  localhost;
    
        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }
    }
    

    So, you should either copy your site to /usr/share/nginx/html directory or provide your custom config and set there location root as /var/www/html directory.

    For second solution you can create file default.conf with content like:

    server {
        listen       80;
        listen  [::]:80;
        server_name  localhost;
    
        location / {
            root   /var/www/html;
            index  index.html index.htm;
        }
    }
    

    and copy it to /etc/nginx/conf.d/ directory in your Dockerfile

    COPY default.conf /etc/nginx/conf.d/
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search