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.
Related
I am new to Docker.
I was trying to dockerize a simple static website using nginx base image.
The applicatio runs fine on local server when i run.
docker run -d -P <container-name>
So, here the app runs on some random port on which i am able to see my app running.
while, when i try to specify port by using the following command:
docker run -d -p 5000:5000 --restart=always --name app mkd63/leo-electricals
The page at localhost:5000 shows site cant be reached.
My Dockerfile is:
FROM nginx:alpine
COPY . /usr/share/nginx/html
EXPOSE 5000
By default, the nginx image listens on port 80 inside the container.
Publishing a port creates a port forward from the host into the container. This doesn't modify what port the application is listening on inside the container, so if you forward to an unused port, you won't connect to anything.
Exposing a port in the Dockerfile is documentation by the image creator to those running the image, but doesn't modify container networking or have any control over what the application running inside the container is doing. With docker, the -P flag uses that documentation to publish every exposed port.
To map port 5000 on the host to nginx listening on port 80 inside the container, use:
docker run -d -p 5000:80 --restart=always --name app mkd63/leo-electric
I came across the command docker run -d -p 80:80 docker/getting-started, which appeared to be a demonstration command to initialize a container. However, I am curious as to what the 80:80 does in regard to the overall command. What does this do? (If an answer to my question can be found in their documentation or some other resource, please do link it as I have done a good deal of searching around to no avail and am more than willing to do the reading myself. Thanks!)
The -p HOST_PORT:CONTAINER_PORT flag binds your container port to the host port. In your case it's 80:80, which the containers port 80 is bound to the port 80 of the host. (default is TCP)
https://docs.docker.com/config/containers/container-networking/
based on docker run -d -p 80:80 docker/getting-started
docker run:start your Container
-d detach your container when you start it
-p 80:80: map your container port to your host port that's mean when you connect to 80 port host you are connect to 80 port container.Architecture is -p {host_port}:{container_port}
docker/getting-started:is your image name
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
I am trying to run jenkins container. I used "docker run --restart always --name myjenkins -p 8080:80 jenkins" but cannot access jenkins at http://localhost:8080 on browser. If I use docker run --restart always --name myjenkins -p 8080:8080 jenkins, I can access the jenkins url.
Thanks in advance
Without Docker
Each application must use a different port.
You can access to your application using directly its ports (if are available of course):
APP_A : 192.168.4.5:8080
APP_B : 10.10.10.15:8081
APP_C : www.app.com:8082
With Docker
Applications could use any port because each one "is a different world"
You can not access to your docker applications using its internal ports:
APP_A : 192.168.4.5:8080
APP_B : 10.10.10.15:8080
APP_C : www.app.com:8080
Because for instance, 8080 of APP_B is only visible inside APP_B container. No body can access to this applications.
In order to access to your docker applications, You must explicitly establish a relationship between:
Linux host ports <-> inside containers ports.
To do that you could use -p parameter
docker run -d -p 8080:8080 APP_A ...
docker run -d -p 8081:8080 APP_B ...
docker run -d -p 8082:8080 APP_C ...
After this you could access to your docker applications using its new ports :
APP_A : 192.168.4.5:8080
APP_B : 10.10.10.15:8081
APP_C : www.app.com:8082
Also a common error when docker-compose & docker network are used is use localhost instead ip when a docker app needs to connect to another docker app. As you can see you need to use ip or domain + external port instead localhost:8080
what is the difference between publishing 8080:80 and 8080:8080 in a docker run?
With 8080:80 you expect that your application uses or start with the 80 internal port inside container.
With 8080:8080 you expect that your application uses or start with the 8080 internal port inside container.
You just need to research what is the internal container port used by your jenkins and put it in docker run -p ...
8080:80 refers that in the container you are using port 80 and you are forwarding that port to host machine's 8080 port. So you are running Jenkins on port 80 inside your container wherever in scenario 2 you are running Jenkins on port 8080 inside the container and exposing it over the same port on host machine.
For example if I am running mysql in container I may use 8080:3306 so mysql would be running on port 3306 but exposed on 8080 of host machine but if choose it to be 8080:80 for mysql it may not work because as per the code of mysql it binds itself on port 3306 not port 80. Same is the scenario in your case of Jenkins too.
When you say 8080:80, it means any request coming on port 8080 will be forwarded to service running on port 80 inside your docker container.
Similarly 8080:8080 means any request coming for port 8080 will be forwarded to service running on port 8080 inside your container
You can also think of it as -
Port for Outside World: Actual Port of service in container
Hope this helps
The syntax looks like below. More details about -p flag.
docker run -p [ip-on-host:]port-on-host:port-in-container image-name
In your case, -p 8080:80 means leading all traffic to port 80 in container. If you check port status on host by netstat -lntp|grep 8080, there is a process managed by docker-proxy who is listening on port 8080 on host machine. It would manage all traffic routing between port 8080 on host and port 80 in container.
I have found a similar thread, but failed to get it to work. So, the use case is
I start a container on my Linux host
docker run -i -t --privileged -p 8080:2375 mattgruter/doubledocker
When in that container, I want to start another one with GAE SDK devserver running.
At that, I need to access a running app from the host system browser.
When I start a container in the container as
docker run -i -t -p 2375:8080 image/name
I get an error saying that 2375 port is in use. I start the app, and can curl 0.0.0.0:8080 when inside both containers (when using another port 8080:8080 for example) but cannot preview the app from the host system, since lohalhost:8080 listens to 2375 port in the first container, and that port cannot be used when launching the second container.
I'm able to do that using the image jpetazzo/dind. The test I have done and worked (as an example):
From my host machine I run the container with docker installed:
docker run --privileged -t -i --rm -e LOG=file -p 18080:8080
jpetazzo/dind
Then inside the container I've pulled nginx image and run it with
docker run -d -p 8080:80 nginx
And from the host environment I can browse the nginx welcome page with http://localhost:18080
With the image you were using (mattgruter/doubledocker) I have some problem running it (something related to log attach).