Iceforest
Iceforest

Reputation: 341

how do I launch an nginx docker container with a site that is copied to the container?

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

Upvotes: 0

Views: 1915

Answers (2)

Iceforest
Iceforest

Reputation: 341

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;"]

Upvotes: 0

KusokBanana
KusokBanana

Reputation: 345

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/

Upvotes: 1

Related Questions