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 :)
Related
I tried to do the following:
docker run --expose 8765 --publish-all -it nginx
But this also exposes 80 along with port 8765
[root#centos7]# docker port f4b608998815
80/tcp -> 0.0.0.0:49156
80/tcp -> :::49156
8765/tcp -> 0.0.0.0:49155
8765/tcp -> :::49155
How to publish port 8765 to one of the random available ports in the host without specifying where to?
The nginx base image already declares EXPOSE 80 and there's no way to un-expose a port, so if you use the docker run -P or --publish-all option to publish every exposed port, it will always be published alongside your manually-exposed port.
You can use the lowercase docker run -p option with only a single port number to publish that port on an arbitrary host port instead:
docker run -p 8765 -d nginx
Since Docker containers internally won't have port conflicts with each other, you may want to just use the default HTTP port 80, matching the standard Nginx config. The --expose --publish-all combination is pretty much the only actual effect of docker run --expose, and you can get the same thing with --port; you pretty much never need the docker run --expose option.
I pulled
docker pull dylanmei/zeppelin:latest
docker run --name zeppelin -p 8080:8080 -p 8081:8081 dymanmei/zeppelin:latest
If I want to change the port of the zeppelin web-site, where do I find the zeppelin configure files?
d91ecdff6a24 dylanmei/zeppelin:latest
"bin/zeppelin.sh" 26 seconds ago Up 26 seconds
0.0.0.0:8088-8089->8088-8089/tcp zeppelin
This is my docker ps -a information. Where is the Docker configuration file of zeppelin?
Zeppelin's configuration is somewhere within the image that you downloaded. However, your question asks how you may configure the port(s) on which Zeppelin is accessed and, using the container, this is straightforward.
The docker run ... command that you included defines 2 ports mappings. These are defined with the flags-p 8080:8080 and -p 8081:8081.. These define that your host's port 8080 is mapped to the container's port 8080 and your host's port 8081 to the container's port 8081.
Rather then change the ports used by the container (and configured within it), you may simple change these port mappings when you run the container.
For example, if you use -p 8888:8080, the container's port 8080 (unchanged) would now be available on your host's port 8888 (instead of 8080).
This has the effect you wanted of changing the port.
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 made my own Dockerfile for a apache server that starts with an standard parent file. See first line in my Dockerfile below:
FROM php:7.0-apache
EXPOSE 8080
This parent exposes port 80. Now have I exposed port 8080 in my Dockerfile. Only when I run it both ports are exposed.
It it posible to close the parent port 80 in my Dockerfile? As I cannot edit that file.
Unfortunately, this is currently impossible.
But you can follow this issue on Docker's GitHub. It's from 2014, but it is still Open. Never know...
As an alternative, rather than editing the configuration in the docker image you can also use port mapping to achieve the same result.
For example mapping port 8080 on the host to port 80 within the docker image, like so:
docker run -d -p 8080:80 image_name
Apart from telling docker to expose the port, you must configure apache to listen 8080, doing these two editions:
/etc/apache2/ports.conf
/etc/apache2/sites-enabled/000-default.conf
Dockerfile:
FROM php:7.0-apache
RUN sed -si 's/Listen 80/Listen 8080/' /etc/apache2/ports.conf
RUN sed -si 's/VirtualHost .:80/VirtualHost *:8080/' /etc/apache2/sites-enabled/000-default.conf
EXPOSE 8080
Then:
docker run -d -p 8080:8080 image_name
Edit:
About port 80. The port is not opened and it's not exposed if you use the previous command. If you don't see the ->80 symbol in docker ps, the port is not exposed:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
100fbb367226 php7 "docker-php-entryp..." 2 minutes ago Up 46 seconds 80/tcp, 0.0.0.0:8080->8080/tcp musing_snyder
And:
▶ docker inspect 100fbb367226 -f "{{json .NetworkSettings.Ports}}"
{"80/tcp":null,"8080/tcp":[{"HostIp":"0.0.0.0","HostPort":"8080"}]}
I have apache installed inside a running ubuntu:14.04 container. How to access this in the browser of the host machine? The address showing inside the container is, 172.17.0.2. Please help.
By default, the apache httpd image exposes the port 80
docker run -it --rm --name my-apache-app -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4
So http://localhost should be enough.
In your case, make sure:
the httpd is actually running (docker exec -it <yourContainer> bash: ps -eaf),
you have mapped the port you are running Apache in your container to the host (-p 80:80 for instance).
By default, the apache image exposes the port 80, but you need config this in run command (-p):
docker run -d -p 80:80 httpd
The first number is port of Docker Host and the second one is port of container. This configuration will map all connections to port tcp 80 of docker host to the same port of container.
After that you can access your application in your browser, using 127.0.0.1, localhost or other IP Address of your interface.