In this video, I'll tell you how to configure access to containers.
So in Potman and Rootless containers, the container does not have an IP address.
And that's not a problem.
I just see it this way.
A container is a way to start an application where you use an Apache web server on your
Linux server.
Do you give it a dedicated IP address?
You don't.
Because you give it a port, and that is exactly how it works in containers as well.
Now the only thing is that the container is running isolated, so it doesn't by default
bind to a port on the host operating system.
And for that reason, you need to use a port mapping.
For a Rootless container, this must be a non-privileged port that is exposed on the host that runs
the container.
A port on a container host is exposed and it forwards traffic to the container port
and that makes it accessible.
These are called port mappings, and port mappings can be set while starting the container, but
not on a container that has already been started.
And Rootless containers can only map to a non-privileged port with a support higher
than 1024.
Okay, for this demo, make sure that you are a non-Root user.
And let me show you how to work with these port mappings.
So first, what happens?
If you use popman run –d –p 80 colon 80 docker.io slash library slash nginx, uh-oh,
we are getting a field to bind port 80 permission denied, and that's what I told you.
In order to bind to a privileged port, you need a Root container.
You don't want to run a Root container, really you don't.
So we need to do it in a different way.
But before doing that, we need to do some housekeeping, because we just had a failed
attempt.
And this failed attempt has resulted in a container with the name funny-lemon.
Nobody is going to clean up funny-lemon if you don't do anything about it.
So I need popman rm on funny-lemon.
Otherwise, if you try it 10 times, then you would have 10 container environments that
have been created, filling up your file system in the end before it finally runs.
That's not what you want.
Now that I cleaned up my funny-lemon, we can get to a working situation, and the solution
is easy.
I changed the first port.
So you first have the port exposed on the host, then you have the port within the container.
And now popman port –a is showing that we have the port mapping.
This is not very readable.
You probably just want to see popman ps.
And there we can see the ports.
So the ports is 0000 colon 8080, means that port 8080 has bound to every IP address on
your host and is forwarding to the container.
Look, when I use curl localhost colon 8080, we can see welcome to Nginx.
It's an ugly webpage, but it's showing that it is working.
Now from a container perspective, we are done.
From a system perspective, we are not.
Because if you want this guy to be accessible from the outside, you need to take care of
firewalling.
So sudo firewall cmd –add port is 8080 slash tcp –permanent.
And sudo firewall cmd –reload will make sure that also from a firewall perspective,
this container is accessible remotely.