Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
gentoo:containers [2024/04/02 13:14] – willy | gentoo:containers [2025/03/13 13:25] (current) – [Using Containers on Gentoo] willy | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Using Containers on Gentoo ====== | + | ====== |
- | Containers are a great tool that caters to some specific, and important, needs. But be aware that // | + | Containers are a great tool that caters to some specific, and important, needs. But be aware that // |
Bear in mind, always, that **containers** while being an astounding piece of technology, are **NOT** meant and have **NOT** been created with self-hosting in mind. Since it's easy and simple to use them for self-hosting, | Bear in mind, always, that **containers** while being an astounding piece of technology, are **NOT** meant and have **NOT** been created with self-hosting in mind. Since it's easy and simple to use them for self-hosting, | ||
Line 62: | Line 62: | ||
Installing Podman is pretty easy since it's in Portage repository, but let's enable docker wrapper as well, so you can " | Installing Podman is pretty easy since it's in Portage repository, but let's enable docker wrapper as well, so you can " | ||
<code bash> | <code bash> | ||
- | > | + | echo " |
- | > emerge podman | + | emerge |
</ | </ | ||
Line 79: | Line 79: | ||
which i suggest to run as un-priviledged user to verify everything is working as non-root too. | which i suggest to run as un-priviledged user to verify everything is working as non-root too. | ||
- | Now, install **podman-compose** | + | Now, install **podman-compose**, and thanks to a few user contributed inputs (see [[https:// |
+ | <code bash> | ||
+ | emerge -vp podman-compose | ||
+ | </ | ||
- | Follow my [[gentoo: | + | beware that it might be masked for your arch, in this case, just unmask it with your keyword, ex ~amd64. |
- | <file - podman-compose-1.0.6.ebuild> | + | |
- | # Copyright 2024 Gentoo Authors | + | |
- | # Distributed under the terms of the GNU General Public License v2 | + | |
- | EAPI=8 | + | === Podman rootless users === |
- | DISTUTILS_USE_SETUPTOOLS=rdepend | + | When running a container rootless, which is the main point behind Podman, you might end up having some issues with user IDs. |
- | PYTHON_COMPAT=( python3_{10..11} ) | + | |
- | inherit distutils-r1 | + | [[https:// |
- | DESCRIPTION=" | + | In short: when running rootless, the //user 0//, or root, of the container, will be mapped to your user ID, and any //additional// user will be remapped according to the content of **/etc/subuid** and **/ |
- | HOMEPAGE=" | + | |
- | SRC_URI=" | + | |
- | # | + | |
- | LICENSE=" | + | The easiest way to fix it, is to force your container to run... **as user 0**! In fact, since we are using rootless podman, that only means **as your own user** nad not actually root. |
- | SLOT="0" | + | |
- | KEYWORDS=" | + | |
- | DEPEND="" | ||
- | RDEPEND=" | ||
- | ${DEPEND} | ||
- | dev-python/ | ||
- | dev-python/ | ||
- | " | ||
- | BDEPEND="" | ||
- | </ | ||
- | |||
- | as // | ||
- | |||
- | I hope that this ebuild will be merged to Gentoo official repo soon. | ||
==== Podman networks ==== | ==== Podman networks ==== | ||
Line 121: | Line 103: | ||
To create a Podman subnet you need to run the following command after each reboot, as root: | To create a Podman subnet you need to run the following command after each reboot, as root: | ||
<code bash> | <code bash> | ||
- | > | + | podman network create my-container-net |
</ | </ | ||
Line 141: | Line 123: | ||
networks: | networks: | ||
my-container-net: | my-container-net: | ||
- | | + | </ |
| | ||
- | | + | I strongly suggest that you edit your docker compose files and ensure each service has it's own independent network. I will give more details for each service on it's respective page. |
+ | |||
+ | |||
+ | ==== Podman containers autostart ==== | ||
+ | |||
+ | Autostarting containers is pretty easy if you use SystemD, but even if you don't, and i don't, it's easy enough too. | ||
+ | |||
+ | <file - / | ||
+ | # | ||
+ | # Copyright 2024 Willy Garidol | ||
+ | # Distributed under the terms of the GNU General Public License v3 | ||
+ | |||
+ | depend() { | ||
+ | need localmount net | ||
+ | } | ||
+ | |||
+ | UC_LOG_PATH=/ | ||
+ | UC_SLOT=" | ||
+ | UC_USER=${USER: | ||
+ | UC_COMPOSER_FILE=${COMPOSER_FILE: | ||
+ | UC_CHOWN_DIR=${CHOWN_DIR} | ||
+ | if [ " | ||
+ | then | ||
+ | UC_HOME=${HOME: | ||
+ | fi | ||
+ | |||
+ | extra_commands=" | ||
+ | update() { | ||
+ | if [ " | ||
+ | then | ||
+ | COMMAND=" | ||
+ | stop | ||
+ | ebegin " | ||
+ | su - ${UC_USER} -c " | ||
+ | start | ||
+ | else | ||
+ | ebegin " | ||
+ | eend 255 | ||
+ | fi | ||
+ | } | ||
+ | |||
+ | description=${DESCRIPTION: | ||
+ | pidfile="/ | ||
+ | |||
+ | start_pre() { | ||
+ | if [ " | ||
+ | then | ||
+ | test -e " | ||
+ | test -e " | ||
+ | mkdir " | ||
+ | } && chown -R ${UC_USER} " | ||
+ | if [ -n " | ||
+ | then | ||
+ | chown -R ${UC_USER} ${UC_CHOWN_DIR} | ||
+ | fi | ||
+ | else | ||
+ | ebegin " | ||
+ | eend 255 | ||
+ | fi | ||
+ | } | ||
+ | |||
+ | |||
+ | start() { | ||
+ | ebegin " | ||
+ | COMMAND=" | ||
+ | ARGUMENTS=(compose -f ${UC_COMPOSER_FILE} up) | ||
+ | ebegin " ... ensuring nat table is loaded ..." | ||
+ | iptables -L -t nat &> /dev/null | ||
+ | ebegin " ... creating ' | ||
+ | podman network create ${UC_SLOT}-net &> /dev/null | ||
+ | su - " | ||
+ | start-stop-daemon -p ${pidfile} \ | ||
+ | -1 " | ||
+ | -2 " | ||
+ | -u ${UC_USER} \ | ||
+ | -d ${UC_HOME} \ | ||
+ | -b -m \ | ||
+ | --start | ||
+ | -- ${ARGUMENTS[@]} | ||
+ | eend $? | ||
+ | } | ||
+ | |||
+ | stop() { | ||
+ | ebegin " ... running ' | ||
+ | su - " | ||
+ | start-stop-daemon -p ${pidfile} \ | ||
+ | -u ${UC_USER} \ | ||
+ | -d ${UC_HOME} \ | ||
+ | --stop ${UC_SLOT} | ||
+ | eend $? | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | I assume you have a**service_name** that runs with a podman compose file as user **myuser**. | ||
+ | |||
+ | Just link the above script to your new service file: | ||
+ | <code bash> | ||
+ | ln -s / | ||
+ | </ | ||
+ | |||
+ | and create | ||
+ | <file - / | ||
+ | USER=myuser | ||
+ | DESCRIPTION=" | ||
+ | </ | ||
+ | |||
+ | and add the service to your desired runlevel: | ||
+ | <code bash> | ||
+ | rc-update add user-containers.service_name default | ||
+ | </ | ||
+ | |||
+ | That's it. | ||
+ | |||
+ | The above script also provide an " | ||
==== Using Podman for new containers ==== | ==== Using Podman for new containers ==== | ||
Line 158: | Line 254: | ||
* Podman containers are not restarted at boot: i will give you instructions for those services as needed. | * Podman containers are not restarted at boot: i will give you instructions for those services as needed. | ||
* Networks needs to be explicitly declared and created as root. | * Networks needs to be explicitly declared and created as root. | ||
+ | |||
+ | |||
==== Migration from Docker to Podman ==== | ==== Migration from Docker to Podman ==== |