My IDE is IntelliJ and it is configured and working with Xdebug and PHP 5.6.
It is working in my host machine (MacOS) but when I turn on the Docker, the debug process fails.
If I try to expose the port 9000 (docker run -p 80:80 -p 9000:9000 ...) when I run the image I get an error inside IntelliJ -> port 9000 is in use.
If I do not expose the port 9000, I get nothing inside IntelliJ,
Here is part of the php.ini inside docker: that shows that xdebug is enabled.
[xdebug]
zend_extension = /usr/local/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.remote_autostart=1
What I am doing wrong?
I have docker 1.12.3 running on macOS sierra.
I need my server to set serveral ips in the hosts file, and also set the containter hostname to resolve to 127.0.0.1.
I had the following command
docker run -dit -p 8080:8080 --add-host someServer:192.168.1.1 --add-host myHostName:127.0.0.1 -h myHostName myImage
So the hostname did changed to myHostName, and also added to the hosts file.
However, it doesn't do anything!. Trying to use it in my server, or even just do ping myHostName resolve in
ping: unknown host
From the documation it look like it should work, but it doesn't. I really need it and I don't have any more ideas how to solve it.
Please help.
I am following this tutorial to use splash to help with scraping webpages.I installed Docker toolbox and did these two steps:
$ docker pull scrapinghub/splash
$ docker run -p 5023:5023 -p 8050:8050 -p 8051:8051 scrapinghub/splash
I think it is running correctly, based on the prompted message in Docker window, which looks like this:
However, when I open the `localhost:8050' in a web browser, it says the localhost is not working.
What might have gone wrong in this case? Thanks!
You have mapped the port to your docker host (the VM), but you have not port-forwarded that same port to your actual "localhost" (your Windows host)
You need to declare that port-forwarding in the Network settings of your VM (for instance "default"), or with VBoxManage controlvm commands.
Then and only then could you access that port (used by your VM) from your Windows host (localhost).
That or you can access that same port using the IP address of your boot2docker VM: see docker-machine ls.
#user3768495, when you use http://192.168.99.100:8050/ , you are actually using the docker-machine ip and this ip would be available on your machine only and not on the network. To map it to localhost, you do need to port-forward the same port to your localhost. I was having the same issue and I detailed the process in below link.
https://stackoverflow.com/a/35737787/4820675
I have Grunt running a node connect (grunt-contrib-connect) web server on localhost:8080 in a docker container. I run the container with this command:
$ docker run --rm -it -p 8080:8080 js1972/yeoman:v3.
Inside my container I run the grunt connect task with grunt develop.
I'm on a Mac so using boot2docker. boot2docker ip says the host ip is 192.168.59.103 so I should access the connect server with http://192.168.59.103:8080 in my browser.
However this doesn't work and I just get a safari can't connect to server message. (note that the port forwarding works just fine when I use a simple python web server like on the docker website examples.)
Any idea whats wrong here? The same process works perfectly well outside of docker.
I've got a feeling its something to do with running Connect on localhost. I've tried various combinations of --add-hosts and -p localhost:8080:8080 and so on to no avail...
If it helps here's my docker file and gruntfile:
https://dl.dropboxusercontent.com/u/7546923/Dockerfile
https://dl.dropboxusercontent.com/u/7546923/Gruntfile.js
Rgds, Jason.
Change localhost to 0.0.0.0.
At the moment the container is only listening for internal connections on the local interface. Using 0.0.0.0 will tell it to listen to all interfaces including the one the Docker host is connected to.
Modify the ip of the hostname in the connect settings of the Gruntfile:
// The actual grunt server settings
connect: {
options: {
port: 8080,
// Change this to '0.0.0.0' to access the server from outside.
hostname: '0.0.0.0',
livereload: 35729
},
And open the server and reload port to the boot2docker vm:
boot2docker poweroff # vm needs to be off to modify the network settings
VBoxManage modifyvm "boot2docker-vm" --natpf1 "containergruntserver,tcp,,8080,,8080"
VBoxManage modifyvm "boot2docker-vm" --natpf1 "containergruntreload,tcp,,35729,,35729"
boot2docker up
I'm running under boot2docker 1.3.1.
I have a Docker container running a web server via uwsgi --http :8080.
If I attach to the container I can browse the web site using lynx http://127.0.0.1:8080 so I know the server is working.
I ran my container with:
$ docker run -itP --expose 8080 uwsgi_app:0.2
It has the following details:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5248ad86596d uwsgi_app:0.2 "bash" 11 minutes ago Up 11 minutes 0.0.0.0:49159->8080/tcp cocky_hypatia
$ docker inspect --format '{{ .NetworkSettings.IPAddress }}' 5248ad86596d
172.17.0.107
I thought I could access that web site from my host by going to http://172.17.0.107:49159.
This does not work. I just see 'connecting...' in Chrome, getting nowhere.
What am I doing wrong?
Extending Anentropic's answer: boot2docker is the old app for Mac and Windows, docker-machine is the new one.
Firstly, list your machines:
$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM
default * virtualbox Running tcp://192.168.99.100:2376
Then select one of the machines (the default one is called default) and:
$ docker-machine ip default
192.168.99.100
Ok, stupid me, I found the answer in the docs for boot2docker
https://docs.docker.com/installation/mac/#container-port-redirection
I needed to use the ip address of the boot2docker vm, rather than the ip of the container, i.e.
$ boot2docker ip
192.168.59.103
and I am able to browse my site from the host at http://192.168.59.103:49159/
I did not need to add any route on the host
To find the IP address of your container, you should need NO additional installs:
docker inspect <container>
This provides a wealth of info. grep it for the IPAddress.
You could use boot2docker port mapping option -L, as described here.
So, in your case it would be
boot2docker ssh -L 0.0.0.0:8080:localhost:8080
and then
docker run -it -p 8080:8080 uwsgi_app:0.2
That way, you do not have to use boot2docker's IP address: you can use localhost or your own IP address (and your docker container can be accessed from outside).
Boot2docker is outdated, but you may still have this problem on Docker for Windows or Mac, even though the same container works on Linux. One symptom is that trying to access a page on the server inside the container gives the error "didn't send any data" as opposed to "could not connect."
If so, it may be because on Win/Mac the container host has its own IP, it's not localhost as it is on linux. Try running Django on IP 0.0.0.0, meaning accept connections from all IPs, like this:
python manage.py runserver 0.0.0.0:8000
Alternatively, if you need to make sure the server only responds to local requests (such as from your local proxy like nginx, apache, or gunicorn) you can use the host IP returned by hostname -i.
And make sure you are using the -p port forwarding option correctly in the docker run command.
Assuming all is well, you should be able to access your server at http://localhost in a browser running on the host machine.
docker build -t {imagename} .
docker build -t api-rest-test .
docker run -dp {localport}:{exposeport} image:name
docker run -dp 8080:8080 api-rest-test:latest
make sure you are using the same port for yourlocalport and exposeport
then you can access your rest service in your local machine http://localhost:8080
[EDIT: original version was ignoring the -P in question]
If you want to get to the containers without having to 'publish' the port (which changes its number)
there is a good run-through here.
The key is this line:
sudo route -n add 172.17.0.0/16 172.16.0.11
which tells the Mac how to route to the private network inside the VirtualBox VM that the Docker containers are on.
Had the same issue and in my case i was using AWS EC2 instance. I was trying with the container IP which did not work. Then I used the actual public IP of the AWS host as the IP, which worked.
How to troubleshoot the issue on hosting application on local host browser
For this launch the container with below command, in my case it was:
[root#centoslab3 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1b81d8a0e3e1 centos:baseweb "/bin/bash" 8 minutes ago Exited (0) 24 seconds ago webtest
[root#centoslab3 ~]# docker run --name=atul -v /root/dockertest:/var/www/html -i -t -p 5000:8000 centos:baseweb /bin/bash
In the httpd configuration:
[root#adb28b08c9ed /]# cd /etc/httpd/conf
[root#adb28b08c9ed conf]# ll
total 52
-rw-r--r--. 1 root root 34419 Sep 19 15:16 httpd.conf
edit the file with the port 8000 in listner and update the container ip and port under Servername.
Restart the httpd service and you are done.
Hope this helps