I want to start docker but the VNC ports keep changing everytime i start docker container. So I was wondering if there is anyway to start docker image with ALL Ports OPEN?
-p external port:internal port (e.g. -p 80:80) if you wanted it to map port 80 in the container to port 80 on the host O/S. Docker documentation.
Related
I have a running Docker container which shows PORTS 9191/tcp. So on my browser, I tried accessing server using localhost:9191/api/.... However, browser throws an error This site can’t be reached
Here is a log to docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c214aefed15e shah "youtube-dl-server -…" 6 seconds ago Up 5 seconds 9191/tcp boring_swirles
This is what my docker file looks like
FROM mariozig/youtube-dl_server
RUN pip install --pre youtube_dl_server
EXPOSE 9191
ENTRYPOINT ["youtube-dl-server", "--host=0.0.0.0"]
You have not mapped the docker container port to host port.
The docker container runs on a host. And The host doesn't know which requests to be directed to the docker container. For that you have to to map the host port to docker container port using -p flag in docker run command as shown below:
docker run -d -p HOST_PORT:CONTAINER_PORT IMAGE_NAME
-p in this command will specify that you are forwarding your host port to the container port. In your local host in the port HOST_PORT will call the port CONTAINER_PORT of your container.
Now when you will access the HOST_IP:HOST_PORT then the host will redirect the request to corresponding container with which this HOST_PORT has been mapped.
For example I started a tomcat docker container and mapped the tomcat container's 8080 port to host's 9092 port by using the above command. When I do docker ps I can see the mapping under PORTS as 0.0.0.0:9092->8080/tcp
I'm new using docker.
I was asking me if is possible to run many containers on the same aws ec2 instance, triggering all port of the containers on one sigle port on the ec2 instance.
Suppose that we have 3 container:
container1 that run apache2 on port 80
container2 that run nginx on port 80
container3 with tomcat on port 8080
How can access to these services from my pc?
To do this I read that I need to expose ports by typing option -p externport : containerport but its not working
so i thought to change network and then I use option --network=host to trig all port to the same ip but it doesn't work.
I'd like just to accesso to these container in this way:
my-ec2-instance-public-dns:8080 -> container1
my-ec2-instance-public-dns:8081 -> container2
my-ec2-instance-public-dns:8082 -> container3
Can anyone help me?
It is not possible to map two services to the same port. You can map container ports to host ports using the -p flag, formatted hostPort:containerPort when you use container networking mode.
In your case, it could be
docker run -p 8080:80 nginx
docker run -p 8081:80 apache2
docker run -p 8082:8080 tomcat
Make sure you set the AWS security group of your virtual machine to allow traffic from your IP to ports 8080-8082.
I have a two HTTP servers on my host machine; one listening on 8080, the other listening on 8081. The 8080 is a webapp, and the 8081 is an API.
I also have a Docker container that should connect to the webapp on 8080 using an automated tool, and that webapp should make HTTP requests to the API that's on 8081.
Here is a visual representation of what I want:
Host machine HTTP 8080
⇩ ⇖
⇧ Docker container
Host machine HTTP 8081
The problem I'm having is that the Docker container cannot connect to the website on the host machines 8080. I'm not sure why, because I set the --network=host flag, so shouldn't it be using the host machines network?
This is my Docker image:
## Redacted irrelevant stuff...
EXPOSE 8080 8081
This is how run the container:
docker run -d -p 8080:8080 -p 8081:8081 --network=host --name=app app
Any ideas what's wrong with my setup?
So you have two services running directly on the machine and you want to deploy a Docker container that should connect to one of those services.
In that case, you shouldn't map those port to the container and you shouldn't expose those ports in the Dockerfile as those ports are not for the container.
Remove the Expose ports from the Dockerfile
Start the container using docker run -d --network=host --name=app app. The container should be able to access the services using localhost:8080.
I have fedora 20 running in my container, I can start my container and point it to a specific port through docker and the Websphere Liberty page loads just fine. (which is what i have in it). However, in the same container i have my db connection string- i can ping it fine, but in the logs when the wlp service start it throws db connection exception- cant connect. Maybe i ned to expose a port that db is running on? not sure, or maybe I am doing something completely wrong? I just got Dockers and dont have much experience with it...any help would be great! thanks!
When you run a container, Docker has two methods of assigning ports on the Docker host:
Docker can randomly assign a high port from the range 49000 to 49900
on the Docker host that maps to port 80 on the container.
You can specify a specific port on the Docker host that maps to port
80 on the container.
This will open a random port on the Docker host that will connect to port 80 on
the Docker container.
The -p flag manages which network ports Docker exposes at runtime.
$ sudo docker ps -l command will let you view the Docker port mapping.
I want to assign a container a port, so that it gets the same port after every restart of the container.
Example:
I have a container, which has an Apache in it. The Apache runs on port 80 inside the container.
Now, after starting the container, docker assigns a host port to the container port, for example: 49154 -> 80. But the host port changes after restart, depending on the number of running containers. I tried to specify the port in the config.json file of the container, but it gets overwritten.
Is it possible to specify the host port manually?
Thanks in advance and best regards,
Chris
Per the docker.io documentation: https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/
$ sudo docker run -p 80:80 <image> <cmd>
Default port redirects can be built into a container with the EXPOSE build command.
When you start docker, you can use the '-p' parameter.
docker run -p 80 yourimage apache2 will do what you currently have.
Now, you can specify ':' to make this port static:
docker run -p :80 -p :443 yourimage apache2
If you are using a Dockerfile with the EXPOSE instruction, it is the same thing :)