nerdctl port not exposed - port

I started to used containerd instead of docker. I did what was to be installed for containerd with nerdctl. Nginx was the container I ran. Though container port 80 is mapped, it's not exposed. I've checked whether firewall blocks but none.
nerdctl run -d -p 80:80 70999c4a17c7
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0416dd502f86 docker.io/library/nginx:latest "/docker-entrypoint.…" 55 minutes ago Up 0.0.0.0:80->80/tcp nginx
So what could be the issue?

I found your question having just had the same issue! I did exactly the same as you, and indeed found the same: it does not work when you expose port 80.
I then tried a different port:
nerdctl run -d -p 8081:80 nginx
... and that did work. With no additional settings needed.
So I had a look at what else might be listening on port 80 ...
sudo lsof -iTCP -sTCP:LISTEN -Pnl | grep :80
... and (in my case) limactl was listening on port 80. I assume that would explain why nginx could not also use port 80. So it seems like you just need to use a different port (probably simpler than digging into lima settings).

Related

Parts of a Docker command

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

Conflict between docker-proxy and nginx

I want to run a dockerized nginx on port 443 (https), but this seems to be taken by the docker-proxy.
Why is this, and can I do someting about it?
EDIT
The same conflict happens with the http port (80)
docker-proxy is run when you publish a port on the host. Look for the container or service you have run that is publishing the port and remove it:
$ docker container ls
$ docker service ls

Docker to run new container - list of all mapped ports?

When running a new container, we specify a port RUN_PORT:EXPOSED_PORT to map with the host machine. This will fail if RUN_PORT is already used.
So my question is how to list all the mapped port - so that we can pick up the port number out of the list.
p.s.
I'm using Ubuntu 16.04
Do the following command
sudo netstat -tlnp | grep ":RUN_PORT"
Replace RUN_PORT with the actual port to see which application is blocking it.
Listing all tcp ports being used (for listening) can be seen with:
netstat -lnt
Looking up what is using a single port can be done with a netstat and grep, or if you have lsof installed:
sudo lsof -i :80 # shows the process using port 80
Starting a docker container on a random available port mapped to port 80 inside the container:
docker run -p 80 -n container_name your_container
Looking up what random port docker used in the above command on the host (this includes what IP interfaces it's attached to, or 0.0.0.0 for all interfaces, which is the default):
docker port container_name 80

Close Docker expose port from parent file

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"}]}

How to assign as static port to a container?

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 :)

Resources