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
Related
I'm quite new to software development and having some issues setting up a docker container.
I've pull the docker container and run it. Now I want to apply some configuration to my container with
docker run --rm --network="ansible_default" -v C:\folder\folder1\ansible\playbooks:/ansible/playbooks docker.<address>/ansible ansible-playbook -i host localhost.playbook.yml
But when I run the above code, it just gives an error:
ERROR the playbook localhost.playbook.yml does not appear to be a file
I am running on administration powershell and have cd into the folder that contains the yaml files. (so inside C:\folder\folder1\ansible\playbooks)
Do I need ansible installed? Any pointers would be greatly appreciated!
EDIT: The docker container exits with a code 2, I'm supposed to be able to access it via localhost:8080 but it's just a blank screen. Exited(2) I'm not too sure what it means, haven't found much success online.
Turns out the solution is to reinstall Docker.
I have Ubuntu 20.04, Mozilla Firefox 87.0, Google Chrome 89.0.4389.90.
I am trying to run the Docker Getting-started tutorial. I read a couple of posts from stack overflow to not avail. Also I checked this ToDo App (localhost:3000) shows no UI in Browser #9 and this enter link description here again to not avail. I do,
sudo docker build -t getting-started .
sudo docker run -dp 3000:3000 getting-started
and then when I go to http://localhost:3000 I get,
In Firefox,
in Chrome the following images alternate,
When I run, sudo docker ps -a I get,
Finally, do you suggest any Docker tutorial for beginners? I want to have enough understanding for Docker so that I can write scripts to manage docker images.
You might be building and running the Dockerfile outside the "app" directory which has this behaviour. As the tutorial says, first go to the app directory, create a Dockerfile there and then build and run. This should work.
3000:80 opens the tutorial because the default Dockerfile builds the docker/getting-started which is the tutorial.
Might be the problem something is blocking the port on your machine so try to Replace the port to 80 instead of 3000.
Change from
docker run -dp 3000:3000 getting-started
to
docker run -dp 3000:80 getting-started
and then open browser and hit http://localhost:3000
Answer 1 is correct but I would like to give a little explanation as to why you have to change "3000:3000" to "3000:80".
The port number before the colon represents the outgoing port and the port number after the colon represents the internal port inside the docker container.
"As the tutorial says, first go to the app directory, create a Dockerfile there and then build and run."
This solves the problem. If you build and run from the root - there is existing Dockerfile in there, it want work. Go to app folder, create Dockerfile with the content from the tutorial, build and run.
I am trying to get the Superset running on ubuntu server. I have referenced the steps from Superset page as below:
git clone https://github.com/apache/incubator-superset/
cd incubator-superset/contrib/docker
# prefix with SUPERSET_LOAD_EXAMPLES=yes to load examples:
docker-compose run --rm superset ./docker-init.sh
# you can run this command everytime you need to start superset now:
docker-compose up
I have fixed the initial issues around right version of docker-compose and postgress address bind issue on port 5432. So after fixing those my docker compose run command
docker-compose run --rm superset ./docker-init.sh
works fine and it asks me to set up a user name and password.
Finally to get the container running I run the final command
docker-compose up.
On my mac, it would run redis, postrgre container and then give me a localhost:8088 for me to get access to Superset UI with login info.
However on Ubuntu, when I run that, I first get this:
So looks it is running redis and postgres containers fine.
But then it is giving me Permission denied errors to create some mkdir directory.
Pls note I am running it as root user.
Also, my docker compose version is fine with 1.23.2 and my docker along with docker-compose is installed under
/usr/bin/docker and not /usr/local/bin/docker.
But I think that shouldn't be an issue.
Any help where it is going wrong and how can I fix it?
Thanks
Edit:
Ok I looked at the same issue mentioned on Github. And used a suggestion of using it only for Production and not development in docker-compose.yml file.
It seems to not throw the same error now when I do
docker-compose up.
However when I open localhost:8088 it does not connect to the UI.
try this:
mkdir ../../assets
chmod -R 777 ../../superset/assets/
as set in docker-compose.yml#L64, it is using ../../superset as volume when in develop. However the container does not have any permission in the host so the solution is to make a directory by yourself and grant the necessary permissions on to it.
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.