Solution 1 :

Dockerfile:

FROM nginx
COPY index.html /usr/share/nginx/html

Docker-compose file:

version: '2'
services:
    app:
        build:
          context: .
          dockerfile: Dockerfile
        ports:
            - "8080:80"

The build context is very important here. In COPY command of your dockerfile, source path must be inside your build context.

This is the content of build context directory:

tree -ah

Also remember to run docker-compose in a detached mode (docker-compose up -d).

Solution 2 :

You need either a server block to point your NGINX to the /test folder, or to mount your index.html file at the default location: /usr/share/nginx/html

  1. Using the default NGINX location /usr/share/nginx/html, you just need this docker_compose.yml (you don’t need a Dockerfile):

    version: '2'
    services:
      app:
        image: nginx
        volumes:
          - C:UsersX12XDesktopdocker:/usr/share/nginx/html
        ports:
          - "8080:80"
    
  2. Adding a server block:

    1. You need to override the default a server block configuration file, in /etc/nginx/conf.d/default.conf:

      server {
        listen 80 default_server;
        server_name _;
        index index.html;
      
        server_name_in_redirect off;
      
        root  /test;
      } 
      
    2. You need to mount this configuration file in the configuration folder /etc/nginx/conf.d/ as well as the index.html

      version: '2'
      services:
        app:
          image: nginx
          volumes:
            - C:UsersX12XDesktopdocker:test
            - C:UsersX12XDesktopdockerdefault.conf:/etc/nginx/conf.d/default.conf 
          ports:
            - "8080:80"
      

Problem :

I am just playing around with docker, & trying to launch a basic html file locally using docker. the server is up and running but its not displaying the html text on the website. what configurations do I need to show the html text?

The error I’m getting:

“If you see this page, the nginx web server is successfully installed and working. Further configuration is required.”

here’s my code:

index.html:

<h1>Hello world</h1>
<p1>docker</p1>

dockerfile:

FROM nginx
COPY C:UsersX12XDesktopdocker test

docker-compose.yml:

version: '2'
services:
    app:
        shm_size: 128m
        build: .
        image: nginx
        volumes:
            - C:UsersX12XDesktopdocker test
        ports:
            - "8080:80"

I am totally new to docker, & im not sure what kind of configurations i need to do in order to show the HTML text on the localhost/8080 webpage

Comments

Comment posted by mhc2001

After using that code above. it take me to a webpage which displays “402 FORBIDDEN” with “nginx/1.19.0” under it.

Comment posted by β.εηοιτ.βε

With which one, the solution 1 on the 2? (I just updated the second after a retesting of the correct file to use)

By