I'm following the following tutorial: https://medium.com/#khwsc1/a-simple-react-next-js-app-development-on-docker-6f0bd3f78c2c
When I try to access localhost:3000 however I get a "This site can’t be reached"
Not too sure what I'm doing wrong, when I run docker contqainer ls I definitely see the container running.
Try localhost:3333.
Port 3333 is mapped on the host. Port 3000 is accessible inside the container.
Run command - docker run -d -p 3333:3000 <your_username>/docker-nextjs:latest
Related
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*
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/
My Docker container is running Rails on port 3000, and I'm publishing the port to port 8900. See:
$ docker-compose ps
Name Command State Ports
rails_poc_1 /bin/sh -c puma -C config/ ... Up 0.0.0.0:3000->8900/tcp
However, when visiting http://localhost:8900 my browser displays ERR_CONNECTION_REFUSED.
When curling port 3000 from inside the container with docker exec 8fcceed1d477 curl localhost:3000 I get a valid response which proves Rails is working properly.
Am I overlooking something?
I think you have your port mapping reversed. Your ps line should look more like:
0.0.0.0:8900->3000/tcp
If you want to access 3000 outside the container as 8900
I unable to access docker exposed port on windows machine. In details I do the following:
$ docker build -t abc01 .
$ docker run -d -p 80:4000 abc01
Then I try to reach docker container in browser:
http://192.168.99.100:4000
and get annoying result:
This site can’t be reached 192.168.99.100 refused to connect.
What is the issue?
You are exposing the right ports, however, you need to access the website at: 80 instead of 4000, given that 4000 is the port on which your application is listening.
The way exposing ports in Docker works is as follows:
docker run -p 80:4000 myImage
where
80[is the outside port]
The one is exposed on your host and you will use it in your browser
4000 [is the inside port]
The port that is used inside the container by the application
I am new to docker. Just tried to run a container on port 80
docker run -p 80:80 kitematic/hello-world-nginx
and it seems to be working fine. I can get to the site at http://192.168.99.100/
but i tried changing the port to
docker run -p 70:50 kitematic/hello-world-nginx
and i cannot get to site at http://192.168.99.100:70. So how can i set a different port and connect to site please?
Please try:
docker run -p 70:80 kitematic/hello-world-nginx
binding port is probably mistyped in the command you provided.