Unable to access UI due to /var/www/htdocs/ is forbidden issue on mac+docker

I downloaded Docker on mac and using “Docker Desktop” to work with docker.

I have small react app (created via creact-react-app) in which at root I have created etc dir as below which contain DockerFile under docker dir and nginx.conf

enter image description here

At root I use below command to build image: docker build . -f etc/docker/Dockerfile -t myui:rc0

and then run the container as below: docker container run -it -p 8081:8081 myui:rc0

2020/02/11 05:38:08 [error] 6#6: *6 directory index of “/var/www/htdocs/” is forbidden, client: 172.17.0.1, server: localhost, request: “HEAD / HTTP/1.1”, host: “localhost:8081” 172.17.0.1 - - [11/Feb/2020:05:38:08 +0000] “HEAD / HTTP/1.1” 403 0 “-” “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) DockerDesktop/2.1.1 Chrome/78.0.3904.94 Electron/7.1.0 Safari/537.36”

Here is the content of my Dockerfile:

FROM nginx:1.15

ARG IMAGE_EXPIRY_TIME=60d

COPY etc/nginx.conf /etc/nginx/nginx.conf
COPY myui /var/www/htdocs/myui

RUN touch /var/run/nginx.pid && \
  chown -R www-data:www-data /var/run/nginx.pid && \
  chown -R www-data:www-data /var/cache/nginx

USER www-data

VOLUME /var/www

EXPOSE 8081
CMD ["nginx", "-g", "daemon off;"]

and here is Dockerfile content:

#user  nobody;
worker_processes  2;

error_log  /var/log/nginx/error.log;

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       8081;
        server_name  localhost;

        root  /var/www/htdocs/;

        location /myui {
            alias /var/www/htdocs/;
            try_files $uri $uri/ /index.html;
        }

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    include servers/*;
}

Can anyone please help me with this issue.
Thanks

Anyone have an y hint on this issue. I am still struggling

I was able to solve it.
It was my server root which I need to set to /var/www/htdocs/myui instead of /var/www/htdocs

Unable to access UI due to is forbidden issue on mac+docker!

Facing the issue due to UI on Mac+docker. any solution?

After lots of struggle I fixed it.
The issue was path in nginx.conf. Here is what nginx.conf looks like now:

    root  /var/www/htdocs/myui;

    location /myui {
        alias /var/www/htdocs/myui;
        try_files $uri $uri/ /index.html;
    }

And it is working.
Hope that is helps you

by iosman987
Facing the issue due to UI on Mac+docker.. any solution?

thanks my issue has been fixed.