I am trying to build a nginx webserver to share files among team members.
In 'ubuntu 16.04', I am running following command:
root#automation00-new:/home/test# docker run -d -p 8081:80 -v /var/www/apj/:/usr/share/nginx/html --name test-nginx nginx:latest
As shown below docker is able to mount the files successfully.
root#automation00-new:/home/test# docker exec ec795af0f1f2 ls /usr/share/nginx/html
Builds
Logs_for_perf_Testing
json.txt
ravi
root#automation00-new:/home/test#
But when I try to access webserver using browser "http://1.1.1.1/8081" I am seeing '403 forbidden' error.
But if I try 'http://1.1.1.1/8081/json.txt', I am able to view the 'json.txt' contents on browser.
I want to browse all the directories and files inside.
Any idea on how to fix this issue please?
Please give us more context in terms of your nginx configuration.
Are you using the default nginx.conf or do you have done modifications?
The solution should be to add all relevant files to the nginx index
Details also here, you will need to modify your nginx.conf:
autoindex needs to be turned on for the location /
Related
I'm trying to run a visual studio server and create a dockerfile. If you want to reproduce the script clone https://github.com/alessandriLuca/4Stackoverflow .
script.sh will build the docker container and run it sharing the port. The problem is that apparently i cant reach the port 8080 even if i exposed it. I solved on ubuntu with --network host but this option is not accessible for OsX or Windows.
Here is the last part of the dockerfile, that is related to visualStudio installation
COPY visualStudio /visualStudio
RUN cd /visualStudio/ && 7za -y x "*.7z*"
RUN dpkg -i /visualStudio/visualStudio/*.deb
COPY config.yaml ~/.config/code-server/config.yaml
EXPOSE 8080
CMD ["code-server","--auth","none"]
As you can see i use a config.yaml but that one is also not working since when i run the code-server that file is overwritten so, the port still remain 8080.
Thank you for any help
EDIT
You can find all files, included config.yaml here https://github.com/alessandriLuca/4Stackoverflow/tree/main/merged2_visualStudio
EDIT
I kind of solved it! Practically as you said was hosting on 127.0.0.1 instead of 0.0.0.0, soo i changed manually in config.yaml and now is working. The only problem now is to add this configuration directly in the dockerfile since, when I run the server he overwrite the config.yaml that I created. Does someone have any idea about this part?
I installed docker on my linux and I installed nginx container like this:
docker pull nginx
docker run -it -d -p 8081:80 --name web -v /mnt/Project/Flutter/Projects/app_web2/build/web:/usr/share/nginx/html nginx
Now I want to change Cache-Control on my nginx container. Because I write a pwa with flutter, Every time I changed my page, when I launch page I still see old version of page, Now I want to change nginx caching.
How can I change it's default?
I suspect that you can achieve this directly. There are two approach.
Run nginx container as you running as of now. Then perform following operation.
docker exec -it <<containername>>
go to /etc/nginx/conf.d/default.conf ( Edit this file)
Note : This approach is problem as you have to do this every time.
Another approach is create custom image based on nginx.
FROM nginx:latest
COPY ./default.conf /etc/nginx/conf.d/default.conf
This ./default.conf will reside in your directory and from where you execute following command.
docker build . mynginx:latest
In this default.conf at your directory you can add custom header.
You can find sample over here : https://github.com/jp1482/mynginxwithcustomerheader
I'm new to Docker and currently following this tutorial:
Learn Docker in 12 minutes
I created the necessary files and I made it up to display "Hello World!" on localhost:80.
Beyond that point, I tried to mount the container using the direct reference to my folder so I can update the index.php file to mimic the development evironment, and then I come with this error:
All I did is change the way the image is ran so I can update the content of the index.php file and see the changes reflect in the webpage when I hit F5.
Currently using Docker for Windows on Windows 10 Pro
Docker for Windows is running
I followed every steps scrupulously so I don't get myself fooled and it didn't work for me it seems.
To answer Mornor's question, here is the result for docker ps
And here for docker logs [container-name]
And since I now better understand what happens under the hood, how do I go to solve my problem illustrated in the log?
Here is my Dockfile
And the command I executed to run my image:
docker run -p 80:80 -v /wmi/tutorials/docker/src/:/var/www/html/ hello-world
And so you see that the file exists:
Error is coming from Apache which tries to show you the directory contents as there is no index file available. Either your docker mapping is not working correctly, or your apache does not have php support installed on it. You are accessing http://localhost, try http://localhost/index.php.
If you get same error, problem is with mapping. If you get php code the problem is with missing PHP support in Apache.
I think you're wrongly mouting your index.php. What you could do to debug it, is to firstly check if the index.php is indeed mounted within the container.
You could issue the following command :
docker run -p 80:80 -v /wmi/tutorials/docker/src/:/var/www/html/ hello-world bash -c 'ls -lsh /var/www/html/'
(use sh instead of bash if it does not work). If you can indeed see a index.php, then congratulations your file is correctly mounted, and the error is not coming from Docker, but from Apache.
If index.php is not there, then you have to check your Dockerfile. You mount src/, check if /src is in the same directory as your Dockerfile.
Keep us updated :)
I know the answer is late but the answer is very easy:
this happens When using docker and you have SELinux, be aware that the host has no knowledge of container SELinux policy.
by adding z
docker run -p 80:80 -v /wmi/tutorials/docker/src/:/var/www/html/:z hello-world
this will automatically do the chcon .... that you need to do.
Check whether the html folder has the proper permission or not.
Thank you
I'm newbie in docker. And i tried to create a Dockerfile to run a website was written byrails, postgresql on apache+passenger.
But when i run Dockerfile, it run successfully, but it had a problem with permission denied. I found problem that folder web must belongs to apache user. Then i tried to change apache user to source web (on container). And it run ok.
But every time i modified a file on local. It always ask password when i saved this file.
And i checked permission source on local. It changed all role to weird role.
How can i solved this problem ?
This is my Dockerfile.
And i used two commands to run.
docker build -t wics .
docker run -v /home/khanhpn/Project/wics:/home/abc -p 80:80 -it wics /bin/bash
After a mount of time, i found a solution to solve this problem.
I just add this line in Dockerfile, the problem was solved.
RUN usermod -u 1000 apache
I run docker on windows 10 with this command:
docker run -d -v /c/Users/tsh/docker:/usr/share/nginx/html -p 80:80 nginx
Inside Users/tsh/docker folder I have simple index.html file:
<h1>Hello!</h1>
It works perfectly well, when I point my browser on windows to virtualbox IP I can see web page with "Hello!" displayed.
But when I change content of the index.html to something like:
<h1>Hello from docker!</h1>
The web page still shows me the old "Hello!" text.
Is it possible when I change index.html data on the web page is also changed?
Upd:
docker run -it -v //c/Users/tsh/docker:/usr/share/nginx/html -p 80:80 nginx bash
root#ae5fc6b6126a:/# cd /usr/share/nginx/html
root#ae5fc6b6126a:/usr/share/nginx/html# cat index.html
<h1>Hello from docker!</h1>
root#ae5fc6b6126a:/usr/share/nginx/html#
Container see new data <h1>Hello from docker!</h1> but page still shows the old Hello!
This problem appears to be related to Virtualbox caching. I also encountered this problem recently editing CSS and I was able to create a "workaround" by resetting the image in Virtualbox. But, I call this a workaround only in a vague sense since it is not very useful to have to completely reboot the boot2docker image each time you make an edit to an HTML doc.
There seems to be some issues with the windows paths. Please try the workaround suggested in Github issue https://github.com/docker/docker/issues/12590
Use double leading slashes on the path:
docker run -d -v --name mynginx //c/Users/tsh/docker:/usr/share/nginx/html -p 80:80 nginx
You can debug your situation as follows:
First name your container as 'mynginx' using the above updated run command
Then you can enter into the container using following command:
docker exec -it mynginx /bin/bash
Now you should be inside the container, and there you can verify the contents of the mounted file using:
cat /usr/share/nginx/html/index.html
If the file here is showing your changes, and still your browser is showing the old file, that means the file is cached somewhere in the chain. Nginx / browser. If it is cached in the browser, you can check by opening in the incognito window or doing Ctrl + F5.
I had the same problem but with Apache. VirtualBox on Windows and Centos with httpd and php on docker. Problem fixed by changing httpd.conf parameter
#
# EnableMMAP and EnableSendfile: On systems that support it,
# memory-mapping or the sendfile syscall may be used to deliver
# files. This usually improves server performance, but must
# be turned off when serving from networked-mounted
# filesystems or if support for these functions is otherwise
# broken on your system.
# Defaults if commented: EnableMMAP On, EnableSendfile Off
#
#EnableMMAP off
EnableSendfile off
EnableSendfile to off because
...but must be turned off when serving from networked-mounted filesystems...
Sending files still works good. Hope this will help someone.