Reset localhost:80 port - docker

running containersall containers
I've recently started learning docker and after following the tutorial, I ran the following command
docker run -d -p 80:80 docker/getting-started
and open up port localhost:80 and saw the docker getting started page. However, I had to run my client's project, whose port was mapped to localhost:80 as well. On account of this, I'm unable to run my client's project on localhost:80. In addition to that, any instance I randomly open up docker and then switch to localhost:80, it redirects to docker's getting started tutorial. I want to reset this localhost:80 port so that when I run my client's project, I can map them to localhost:80. Any method to rectify the issue?

First find you container's ID using:
docker ps
Supposing it is e11d9f8bb730, you can now stop and remove the container with:
docker stop e11d9f8bb730
docker rm e11d9f8bb730
Run again your container, this time using a different port:
docker run -d -p 81:80 docker/getting-started
Now your container is running on port 81 and you will be able to run your client's App on port 80.

First search for the container to see if its open:
docker container ls
If it's not then the page is probably cached by the browser.
I found this to be especially true when using Chrome.
So, if you don't see your container then use your browsers clear cache tool.
In Chrome this is as easy as right clicking on the page and selecting inspect, then right clicking the refresh page icon and selecting hard refresh.

You can use docker to map the container port to any port you choose on your local machine. As an example, you could use your docker getting started and map the port to 8080 instead of 80 like this:
docker run -d -p 127.0.0.1:8080:80/tcp docker/getting-started

All you have to do is stop the container you just started (docker / getting-started). You can open a command prompt, then type this command:
docker container ls
You can see which containers are currently running. For example:
docker containers list
You just need to do this command for the stop container:
docker container stop *yourContainerName*

Related

How to get the client IP from within a web service running within a docker container?

I have an application that extracts the client IP making the request. When I run the application directly on a server, it works and I could get the IP.
But when I run it within a docker containing by executing this command:
docker run --rm -d -p 4300:4300 image
All of a sudden the client IP being reported is now 172.17.0.1.
Googling around I see suggestion to pass in --net=host but doing this:
docker run --rm --net=host -p 4300:4300 image
now leads to the application not being reachable. For some strange reason it looks like the application is no longer available at the specified port.
This also does not work even when I drop the -p 4300:4300 as I got a message in the console that it is not needed when --net=host is used. That is:
docker run --rm --net=host -p image
Any suggestions on how to get this done? That is how to get the client IP from within a web service running within a docker container? I am running docker on a mac. Don't know if this has anything to do with the problem.
If you use the net=host configuration, you don't need the -p <host>:<container> setting, since this is only used to port forward when you use the bridge network configuration.
Just drop this flag and browse to whatever port your application listens on. It should work.

The URL is not working after running the container in Docker Toolbox

I pulled the docker container from the docker hub. After running the container, it gave me two links which should direct me to my desired page but both links show "the site can't be reached. I am using the following command: docker run 'name of the container'
I am working in the Docker toolbox in windows 10 home version.
Any help is highly appreciated
few Things first, docker hub has images that you pull and then using those images you start a container.
to start a container using the command - docker run -p 8080:8080 -d <image-name>
here -d is for a detached container so that it does not stop with the shell.
and -p is port that you want to be linked to your localhost port.
Your container would be in running state. check by the command docker ps.
Hope this helps. First answer on StackOverflow.

Cannot access web on running docker containers

I have two containers, wds and apache. Both of them are running and have clear logs. I also checked if apache is running inside apache container and It is. My problem is that if I try to connect at localhost:80 which is the port that apache container listents to, I get only ERR_TIMED_OUT. Can you point me in which direction to look ? Containers were builded succesfully, no errors in logs, apache is running. I don't know where to look.
did you expose the port in Dockerfile and used -p 80:80 while using docker run command?
There is a specific logic to be followed while running or interacting with containers.
I do not know what commands or arguments you want to use so I will put an example here with basic explanation assuming you want to run a container with exposed port 80 in terminal interactive
docker run [container ID] -ti -p 80:80 /bin/bash
used commands:
-t tty - allocate a terminal so you can directly interact with the docker command
-i - interactive - connects STDIN to the allocated terminal. Any command you enter after this will go to the terminal.
-p - binds port
https://docs.docker.com/network/host/
https://docs.docker.com/engine/reference/run/

Unable to navigate to Docker container

I built a container with a react app within it.
I start the app.. docker run -p 3000:3000 blarg3/node
I can bash into the container and curl localhost:3000 and it returns the front page of my site.
When I go to the IP and port http://172.17.0.2:3000/. Nothing is returned.
By default "docker run" binds port only to local interface. If you want to bind it to another interface you need to specify it's IP address like this:
docker run -p 172.17.0.2:3000:3000 blarg3/node
You can read more about docker networking options here: https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/#connect-using-network-port-mapping

docker: driver failed programming external connectivity on endpoint webserver

I am trying to run a docker example following this documentation
This is my command:
docker run -d -p 80:80 --name webserver nginx
But I get this error:
docker: Error response from daemon: driver failed programming external connectivity on endpoint webserver (bd57efb73c738e3b271db180ffbee0a56cae86c8193242fbc02ea805101df21e): Error starting userland proxy: Bind for 0.0.0.0:80: unexpected error (Failure EADDRINUSE).
How do I fix this?
From your error message, the EADDRINUSE indicates port 80 is already in use on either the docker VM or possibly directly on your laptop. You can either stop whatever is running on that port, or change the port used in your Docker, command. To change to the external port 8080, use:
docker run -d -p 8080:80 --name webserver nginx
If you are the port i not in use, try restarting docker. That usually works for me.
I had the same issue with one of my containers. I tried everything but when nothing worked, I tried the following and launched the container again with success
sudo service docker stop
sudo rm /var/lib/docker/network/files/local-kv.db
sudo service docker start
Try restarting the docker service. It works 99% of the time.
service docker restart
If that didn't work as expected, try restarting your pc and then restarting the docker service using above command.
If none of the above worked try changing the exposed port to another unused port that should work.
docker run -d -p 81:80 --name webserver nginx
Note :- 81 is the port on your host and 80 is the port on your docker container
For the first time, when i made a docker simple web app, i also faced same problem.
Simply you can try the following steps to resolve the problem and also able to understand the reason why you had faced the problem in details.
Step-1: check all the running containers using the command:
docker ps
Step-2: Find out the container id of the container which is running on the same port, you are trying to reach.
Step-3: Stop the container which one is running on the same port using this command:
docker stop <container id>
Step-4: Again build the container:
docker build -t DockerID/projectName .
Step-5: Again try to run your container on the same port using port mapping.
docker run -p 8080:8080 DockerID/projectName
Try this command:
sudo service docker restart
If it does not help, restart your server.
Stop all the running containers docker ps -a -q then
Stop the Docker on your machine & restart it.
Recently this problem started to happen a lot on Windows. You can try restarting docker or you can manually stop docker before Windows shutdown - docker starts cleanly on reboot. On 7/24/2018 docker issue is open and further details can be found at https://github.com/docker/for-win/issues/1967
Check what's on port 80 right now - sudo ss -tulpn | grep :80
You may have apache2 running.
You can check it - sudo service apache2 status
If so - sudo service apache2 statop
If you tried all above solutions and still having issues, you can kill LISTEN ports manually as below for Linux users
sudo lsof -i -P -n | grep LISTEN
sudo kill -9 <process_pid> (ex. sudo kill -9 28563 28575 28719 28804)
In my case, port 80 is the default port for the web server and therefore it is protected. I changed the bind to port 60:8080 to ensure no deeper issues. Changing the bind to a different port allows me to execute the docker run and hit it in the browser at http://ip:60
I had same problem with same error.
As long as I had a local nginx installed in my computer, running another nginx through the container made conflict in port :80.
Simply I tried to stop the service of my local installed nginx as below:
sudo service nginx stop
Then after, I could run nginx by docker-compose up -d without any problem:
Creating MyWebServer ... done
Creating mongo ... done
Creating redis ... done
For me, a simple
ddev poweroff
fixed this.
If this case is with Redis: remove the ports - ... in the docker-compose file and let it assign by itself. or change the port mapping in the host from 6379:6379 to 6378:6379 that worked for me.
windows users: docker description
On Windows systems, CTRL+C does not stop the container. So, first type
CTRL+C to get the prompt back (or open another shell), then type
docker container ls to list the running containers, followed by docker
container stop to stop the container.
Otherwise, you get an error response from the daemon when you try to
re-run the container in the next step.
I had the same problem, I thought with CTRL+C stoped the container but it was not the case, any af the answer above works because they all stop containers, restarting docker or stoping container explicity.
I prefer:
docker container ls #list containers running
docker stop [container id] #replace [container id] with the container id running
This seems to be an incompatibility problem with windows "fast-boot" as described here: (just restart the docker service) and it may work.
https://github.com/docker/for-win/issues/2722
This is caused by an incompatibility with Docker and fastboot. You can either make sure you stop all containers before shutting Windows down or you can disable fastboot in Windows' power settings by doing the following:
CTRL+R > "powercfg.cpl" > "Choose what the power buttons do" > "Change settings that are currently unavailable" > Deselect "Turn on fast start-up"
You can also disable fastboot with a single command in powershell if you're comfortable doing so:
Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Power\' -Name HiberbootEnabled -Value 0
If you are using WSL, after i tried all above and still it doesn't work, i tried to restart the WSL from Powershell with admin privileges and shutdown command:
wsl --shutdown
That worked for me.

Resources