Dino Geek, try to help you

How to use namespaces to isolate processes in LXC?


Namespaces in Linux allow isolating various processes in separate environments, and these are handy for creating light virtual machines such as Linux Containers, or LXC.

Here are basic steps on how to create a new namespace in LXC:

1. `unshare` command: UNIX systems provide the `unshare` command that allows you to run a process in a new namespace. Below is a simple example on how to start a shell in a new namespace:

\`\`\` sudo unshare —fork —pid —mount-proc /bin/sh \`\`\` This will start a new shell, isolated in a new user, PID, and mount namespace.

1. Verify the namespace: Now, we need to verify that the new shell is indeed running in a different namespace. To do it, we can check the PID (process ID) of the shell inside and outside of the namespace:

Inside the namespace, run: \`\`\` echo $$ \`\`\` Outside of the namespace, in another shell run: \`\`\` pgrep -fl /bin/sh \`\`\` You would notice that the PID of the command inside the namespace is 1, as it’s the first command running in this new namespace. However, outside of the namespace, it would apparently be running with another PID.

1. Configure the namespace: The new namespace is completely isolated and independent, so it has no network access or filesystem. We need to configure a root filesystem and networking using `mount` and network tools like `ip`.

Note: The Linux `unshare` command provides flags to set up new namespaces e.g. network namespace (`unshare -n`), IPC namespace (`unshare -i`), etc. Check the man page `man unshare` for more details.

Again, the `unshare` command is a basic and manual way to set up namespaces. For handling namespaces in a more systematic and scalable way, you should use LXC, Docker, or other containerization tools. They provide utilities and APIs that manage the lifecycle of containers including creation, deletion, stop/start, etc.


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use