{"id":15396608,"url":"https://github.com/hupe1980/containers-from-scratch","last_synced_at":"2025-03-28T00:17:18.054Z","repository":{"id":96196789,"uuid":"368457432","full_name":"hupe1980/containers-from-scratch","owner":"hupe1980","description":"Writing a container in a few lines of Go code","archived":false,"fork":false,"pushed_at":"2021-05-20T08:06:12.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-02T02:14:03.448Z","etag":null,"topics":["cgroup","container","go","golang","namespace"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hupe1980.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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-05-18T08:32:58.000Z","updated_at":"2021-05-20T08:06:14.000Z","dependencies_parsed_at":"2023-05-05T16:32:52.914Z","dependency_job_id":null,"html_url":"https://github.com/hupe1980/containers-from-scratch","commit_stats":{"total_commits":3,"total_committers":2,"mean_commits":1.5,"dds":"0.33333333333333337","last_synced_commit":"a75425facbc84c6a1e08bf624bf729d2c5204e53"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hupe1980%2Fcontainers-from-scratch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hupe1980%2Fcontainers-from-scratch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hupe1980%2Fcontainers-from-scratch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hupe1980%2Fcontainers-from-scratch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hupe1980","download_url":"https://codeload.github.com/hupe1980/containers-from-scratch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245944108,"owners_count":20697960,"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":["cgroup","container","go","golang","namespace"],"created_at":"2024-10-01T15:34:22.749Z","updated_at":"2025-03-28T00:17:18.016Z","avatar_url":"https://github.com/hupe1980.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Containers from Scratch in Go\nThis is a container build from scratch in a few lines of Go code. It uses namespaces and cgroups and mounts a tmpfs that's isolated from host filesystem. The project must be run in a Linux environment (GOOS=linux). You can use vagrant to spin up a virtual linux machine. It is based on the great talk from Liz Rice - [Containers From Scratch](https://www.youtube.com/watch?v=MHv6cWjvQjM\u0026t=1316sc)\n\n## Installation (linux)\n- Run `make ubuntufs` to create a ubuntu filesystem (Docker required)\n- Run `make run` to start the container\n\n## Installation (non linux)\n- Run `make ubuntufs` to create a ubuntu filesystem (Docker required)\n- Run `vagrant up`\n- Run `vagrant ssh`\n- Change to the synced folder with `cd container`\n- Run `make run` to start the container  \n\n## How it works\n- The program forks itself with `CLONE_NEWUTS`, `CLONE_NEWPID`, `CLONE_NEWNS` flags to get isolated hostname, processes and mounts\n- The forked process creates a `cgroup` to limit pids to max 20\n- It mounts the `./ubuntu_fs` directory as root filesystem using `chroot` to limit access to host machine's filesystem\n- It mounts the `/mytemp` directory as tmpfs. Changes to this directory are not visible from the host.\n- It mounts the proc directory (after `CLONE_NEWPID` namespace was already set) so that when you run `ps` in the container, only the processes running in it are displayed.\n- It executes the supplied argument `/bin/bash` inside the isolated environment (=container)\n\n## Testing\nYou can run a fork bomb `:(){ :|:\u0026 };:` in the container to test the cgroup limitation. WARNING! These examples may crash your computer if executed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhupe1980%2Fcontainers-from-scratch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhupe1980%2Fcontainers-from-scratch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhupe1980%2Fcontainers-from-scratch/lists"}