{"id":21601545,"url":"https://github.com/vmware-samples/photon-os-container-builder","last_synced_at":"2025-04-11T02:13:22.053Z","repository":{"id":46268664,"uuid":"387544135","full_name":"vmware-samples/photon-os-container-builder","owner":"vmware-samples","description":"Compose and deploy photon OS containers","archived":false,"fork":false,"pushed_at":"2024-10-14T19:40:44.000Z","size":6511,"stargazers_count":6,"open_issues_count":3,"forks_count":4,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-11T02:13:12.932Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vmware-samples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-07-19T17:27:19.000Z","updated_at":"2024-07-09T00:52:02.000Z","dependencies_parsed_at":"2024-04-09T00:24:03.798Z","dependency_job_id":"75387299-613a-4743-bd01-1d855445a288","html_url":"https://github.com/vmware-samples/photon-os-container-builder","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmware-samples%2Fphoton-os-container-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmware-samples%2Fphoton-os-container-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmware-samples%2Fphoton-os-container-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmware-samples%2Fphoton-os-container-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vmware-samples","download_url":"https://codeload.github.com/vmware-samples/photon-os-container-builder/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248328163,"owners_count":21085261,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T19:09:51.291Z","updated_at":"2025-04-11T02:13:22.034Z","avatar_url":"https://github.com/vmware-samples.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"### photon-os-container-builder\n----\n***cntrctl*** spawns Photon OS image as a light-weight container. It uses `systemd-nspawn` to start Photon OS containers. The primary\nuse case for ***cntrctl*** is to run Photon OS test cases in a isolated environment.\n\nPhoton OS package manager ***tdnf*** integrated with ***cntrctl***. Hence it allows to prepare a root fs consisting packages depending on the user choice. It automatically prepares the root fs and boots into the container quickly. VMDK images can be automatically deployed via ***cntrctl*** and tested.\n\nInstall systemd-container\n```bash\n❯ sudo tdnf install systemd-container -y\nInstalling:\nsystemd-container                                                x86_64                     5.10-1.ph4                          photon-release              1.65M 1728537\n\nTotal installed size:   1.65M 1728537\n\nDownloading:\nsystemd-container                                  478107 100%\nTesting transaction\nRunning transaction\nInstalling/Updating: systemd-container-247.11-4.ph4\n\nComplete!\n```\n\n```bash\n❯ sudo cntrctl spawn photon4\nRefreshing metadata for: 'VMware Photon Linux 4.0 (x86_64)'\nRefreshing metadata for: 'VMware Photon Linux 4.0 (x86_64) Updates'\nRefreshing metadata for: 'VMware Photon Extras 4.0 (x86_64)'\n\nInstalling:\nfilesystem               x86_64       1.1-4.ph4        photon-release   7.19k 7363\n\nTotal installed size:   7.19k 7363\n\nDownloading:\n\nTesting transaction\nRunning transaction\nInstalling/Updating: filesystem-1.1-4.ph4.x86_64\n\nComplete!\n```\n\n```bash\n\u003e ❯ sudo cntrctl dir photon4\nSpawning container photon4 on /var/lib/machines/photon4.\nPress ^] three times within 1s to kill container.\nroot@photon4 [ ~ ]# passwd\nNew password:\nBAD PASSWORD: The password is shorter than 8 characters\nRetype new password:\npasswd: password updated successfully\n```\n\n```bash\n\u003e ❯ sudo cntrctl boot photon4\nSpawning container photon4 on /var/lib/machines/photon4.\nPress ^] three times within 1s to kill container.\nsystemd v247.11-4.ph4 running in system mode. (+PAM -AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP -LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +ZSTD +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 -IDN -PCRE2 default-hierarchy=hybrid)\nDetected virtualization systemd-nspawn.\nDetected architecture x86-64.\n[  OK  ] Finished Permit User Sessions.\n[  OK  ] Started Console Getty.\n[  OK  ] Reached target Login Prompts.\n[  OK  ] Started Network Service.\n[  OK  ] Reached target Multi-User System.\n         Starting Update UTMP about System Runlevel Changes...\n[  OK  ] Finished Update UTMP about System Runlevel Changes.\n[  OK  ] Started OpenSSH Daemon.\n\nWelcome to Photon 4.0 (x86_64) - Kernel 5.10.142-2.ph4 (console)\nphoton4 login:\n```\n\n#### Run container as systemd service\n```bash\n❯ sudo cntrctl start photon4\n❯ sudo systemctl status photon4\n● photon4.service - Photon OS container photon4\n   ● photon4.service - Photon OS container\n     Loaded: loaded (8;;file://zeus/usr/lib/systemd/system/photon4.12.service^G/usr/lib/systemd/system/photon4.12.service8;;^G; disabled; preset: enabled)\n     Active: active (running) since Sun 2022-11-27 13:16:28 UTC; 16s ago\n       Docs: 8;;man:cntrctl(1)^Gman:cntrctl(1)8;;^G\n   Main PID: 194027 (systemd-nspawn)\n     Status: \"Container running: Startup finished in 4.458s.\"\n      Tasks: 1 (limit: 16384)\n     Memory: 1.1M\n     CGroup: /machine.slice/photon4.12.service\n             └─194027 /usr/bin/systemd-nspawn --capability=all -bD /var/lib/machines/photon4.12 --link-journal=try-guest -M\n\nNov 27 13:16:32 zeus cntrctl[194027]: ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBBOql3dIN0eJ/4NLKSaOV7aPc9luOtpDcRWs5xs9+13vS8qVR6XIBshv3TwmUu+8NP+\u003e\nNov 27 13:16:32 zeus cntrctl[194027]: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOq6/QRG07DMxIzy/7/gTB0hsdJfNP5FVZyvyO5agJyq root@photon4\nNov 27 13:16:32 zeus cntrctl[194027]: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDSE0byx3ZW75bAdhKNUohEBppQuxjWzQSoFTvZ9K6tfnoyV+qsFgh3nViT+XJWoE6fONNpdWRolNWYiyhRiu1JIsITQZTVbIM5kXN\u003e\nNov 27 13:16:32 zeus cntrctl[194027]: -----END SSH HOST KEY KEYS-----\nNov 27 13:16:32 zeus cntrctl[194027]: [  OK  ] Finished Execute cloud user/final scripts.\nNov 27 13:16:32 zeus cntrctl[194027]: [  OK  ] Reached target Cloud-init target.\nNov 27 13:16:32 zeus cntrctl[194027]: [  OK  ] Stopped OpenSSH Daemon.\nNov 27 13:16:32 zeus cntrctl[194027]: [  OK  ] Started OpenSSH Daemon.\nNov 27 13:16:33 zeus cntrctl[194027]:\nNov 27 13:16:33 zeus cntrctl[194027]: Welcome to Photon 4.0 (x86_64) - Kernel 5.10.142-2.ph4 (console)\n```\n#### Login to the container\n```bash\n❯ sudo machinectl login photon4\nConnected to machine photon4. Press ^] three times within 1s to exit session.\n\nWelcome to Photon 4.0 (x86_64) - Kernel 5.10.142-2.ph4 (pts/1)\nphoton4 login: root\nPassword:\nroot@photon4 [ ~ ]#\n```\n\n#### Creating container with macvlan network\n```\n❯ cntrctl spawn --network macvlan --link eth0 ph4-macvlan\n```\n```\n❯ systemctl start ph4-macvlan\n```\n```\n❯ systemctl status ph4-macvlan\n● ph4-macvlan.service - Photon OS container\n     Loaded: loaded (8;;file://zeus/usr/lib/systemd/system/ph4-macvlan.service^G/usr/lib/systemd/system/ph4-macvlan.service8;;^G; disabled; preset: enabled)\n     Active: active (running) since Sun 2022-11-27 14:04:29 UTC; 6s ago\n       Docs: 8;;man:cntrctl(1)^Gman:cntrctl(1)8;;^G\n   Main PID: 2818 (systemd-nspawn)\n     Status: \"Container running: Startup finished in 4.307s.\"\n      Tasks: 1 (limit: 16384)\n     Memory: 1.2M\n     CGroup: /machine.slice/ph4-macvlan.service\n             └─2818 /usr/bin/systemd-nspawn --capability=all -bD /var/lib/machines/ph4-macvlan --network-macvlan=eth0 --link-journal=try-guest -M\n\nNov 27 14:04:33 zeus cntrctl[2818]: [  OK  ] Reached target Login Prompts.\nNov 27 14:04:33 zeus cntrctl[2818]: [  OK  ] Reached target Multi-User System.\nNov 27 14:04:33 zeus cntrctl[2818]:          Starting Update UTMP about System Runlevel Changes...\nNov 27 14:04:33 zeus cntrctl[2818]: [  OK  ] Finished Update UTMP about System Runlevel Changes.\nNov 27 14:04:33 zeus cntrctl[2818]: [  OK  ] Finished Apply the settings specified in cloud-config.\nNov 27 14:04:33 zeus cntrctl[2818]:          Starting Execute cloud user/final scripts...\nNov 27 14:04:34 zeus cntrctl[2818]: [  OK  ] Finished Execute cloud user/final scripts.\nNov 27 14:04:34 zeus cntrctl[2818]: [  OK  ] Reached target Cloud-init target.\nNov 27 14:04:35 zeus cntrctl[2818]:\nNov 27 14:04:35 zeus cntrctl[2818]: Welcome to Photon 4.0 (x86_64) - Kernel 5.10.152-3.ph4 (console)\n```\n\n```\n❯ machinectl login  ph4-macvlan\nConnected to machine ph4-macvlan. Press ^] three times within 1s to exit session.\n\nWelcome to Photon 4.0 (x86_64) - Kernel 5.10.152-3.ph4 (pts/1)\nph4-macvlan login: root\nPassword:\n\nroot@ph4-macvlan [ ~ ]# ip a\n1: lo: \u003cLOOPBACK,UP,LOWER_UP\u003e mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000\n    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00\n    inet 127.0.0.1/8 scope host lo\n       valid_lft forever preferred_lft forever\n    inet6 ::1/128 scope host\n       valid_lft forever preferred_lft forever\n2: mv-eth0@if2: \u003cBROADCAST,MULTICAST,UP,LOWER_UP\u003e mtu 1500 qdisc noqueue state UP group default qlen 1000\n    link/ether 16:d3:88:53:c7:be brd ff:ff:ff:ff:ff:ff link-netnsid 0\n    inet 192.168.103.177/23 brd 192.168.103.255 scope global dynamic mv-eth0\n       valid_lft 7174sec preferred_lft 7174sec\n    inet6 fe80::14d3:88ff:fe53:c7be/64 scope link\n       valid_lft forever preferred_lft forever\n```\n\n```bash\n\u003e cntrctl\nNAME:\n   cntrctl - Controls state of containers\n\nUSAGE:\n   cntrctl [global options] command [command options] [arguments...]\n\nVERSION:\n   v0.1\n\nDESCRIPTION:\n   Compose and deploy photon OS containers\n\nCOMMANDS:\n   spawn, s      [NAME] Spawn a container\n   boot, b       [NAME] Boot a container\n   dir, d        [NAME] Directory to use as file system root for the container\n   start         [NAME] start container as a systemd service unit (use host networking)\n   stop          [NAME] stop container as a systemd service unit\n   restart       [NAME] restart container as a systemd service unit\n\n```\n\n#### Build\n\n```bash\n❯  make build\n❯  sudo make install\n❯  sudo tdnf install systemd-container\n```\n\ncntrctl spawn [command options] [arguments...]\n\nOPTIONS:\n\n   `--packages value, -p`\n      If specified, the list of packages will be used to compose the container.\n\n   `--release value, -r`\n      If specified, the Photon OS release version will be used. Defaults to 4.0.\n\n   `--ephemeral, -x`\n      If specified, a systemd service unit will be created with ephemeral flag.\n\n   `--dir, -d`\n      If specified, Once installation is finished, chroot into the container,\n\n   `--network value, -n`\n       If specified, enables kind of network (macvlan, ipvlan) and also enable systemd-networkd inside container\n\n   `--link value, -l`\n      If specified, the parent physical interface that is to be associated with a MACVLAN/IPVLAN to container. This\n      should be used with combination of `--network` option.\n\n   `--machine value, -m`\n       If specified, sets the machine name for this container during runtime.\n\n\n#### Contributing\n----\n\nThe ***photon-os-container-builder*** project team welcomes contributions from the community. If you wish to contribute code and you have not signed our contributor license agreement (CLA), our bot will update the issue when you open a Pull Request. For any questions about the CLA process, please refer to our [FAQ](https://cla.vmware.com/faq).\n\nslack channel [#photon](https://code.vmware.com/web/code/join).\n\n#### License\n----\n\n[BSD 2-Clause](https://spdx.org/licenses/BSD-2-Clause.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvmware-samples%2Fphoton-os-container-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvmware-samples%2Fphoton-os-container-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvmware-samples%2Fphoton-os-container-builder/lists"}