I am going to make a server pack using podman in my local machine (Fedora 31 KDE). The pack includes:
Now, I need a way to be able to start the 3 servers with a single command as well as stop with a single command. Therefore, I created a pod and put them under the pod. I need access to both the main web server and phpmyadmin server from the host. Here is a bash script I am usig to create them:
#!/usr/bin/env sh
if [ "$1" != "" ];then
WEB_PATH="-v $1:/var/www/html:Z"
fi
sudo podman pod create -n servers -p 80:80 -p 8080:80
sudo podman run -dt --pod servers --rm --name web $WEB_PATH php:7.2-apache
sudo podman run -dt --pod servers --rm --name mysql --env MYSQL_ROOT_PASSWORD=iamroot -v /var/lib/mysql:/var/lib/mysql:Z mysql:8
sudo podman run -dt --pod servers --rm --name pma phpmyadmin/phpmyadmin:5
The problem is, 1st and 3rd both servers use port 80 as their default. I cannot figure out this problem.
I need access the main web server on port 80 and pma server on port 8080 from the host.
I think what you want to accomplish is basically done by changing the default share option by pods.
In general Pods share cgroup,ipc,net,uts
. Making intercontainer communication easy. Having this enabled (or rather not changing it) does not allow you to port map containers into the pod, resolving in: Error: cannot set port bindings on an existing container network namespace
Like statet by tgogos, rootless containers do always share the same network. This is accomblished by the slirp4netns
project.
Check this site for more information about networking with containers.
I dont fully get why you use sudo
but you could also create your own network using sudo podman network create <networkname>
and assigning containers to this network with the --network <networkname>
flag.
Coming to solutions of your problem
podman pod create --name servers --share cgroup,ipc,uts
podman run -dt --pod servers --rm --name web -p 80:80 $WEB_PATH php:7.2-apache
podman run -dt --pod servers --rm --name mysql --env MYSQL_ROOT_PASSWORD=iamroot -v /var/lib/mysql:/var/lib/mysql:Z -p 8080:8080 mysql:8
podman run -dt --pod servers --rm --name pma -p SOMEPORT:80 phpmyadmin/phpmyadmin:5
sudo podman inspect -f "{{.NetworkSettings.IPAddress}}" <containername>
ip addr show
for any virtual bridge
, or if already created a cni podman
network hostname -I
this will only show IP-adresses, but any of them should work10.89.0.1:8080
192.167.133.1:8080
Note that Steps 1-2 can also be run as
sudo
, but I personally do not like having sudo containers/pods, since this is the beauty of podman to have userspaces and rootless containers. Let systemd services manage restarts etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With