{"id":13416358,"url":"https://github.com/jpetazzo/nsenter","last_synced_at":"2025-09-28T21:30:42.445Z","repository":{"id":18004093,"uuid":"21020707","full_name":"jpetazzo/nsenter","owner":"jpetazzo","description":null,"archived":true,"fork":false,"pushed_at":"2020-05-27T13:07:06.000Z","size":45,"stargazers_count":2594,"open_issues_count":0,"forks_count":270,"subscribers_count":85,"default_branch":"master","last_synced_at":"2025-01-12T10:56:22.172Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jpetazzo.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}},"created_at":"2014-06-20T00:56:30.000Z","updated_at":"2024-12-24T12:44:49.000Z","dependencies_parsed_at":"2022-07-13T05:30:32.840Z","dependency_job_id":null,"html_url":"https://github.com/jpetazzo/nsenter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpetazzo%2Fnsenter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpetazzo%2Fnsenter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpetazzo%2Fnsenter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jpetazzo%2Fnsenter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jpetazzo","download_url":"https://codeload.github.com/jpetazzo/nsenter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234563132,"owners_count":18853059,"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-07-30T21:00:57.625Z","updated_at":"2025-09-28T21:30:42.081Z","avatar_url":"https://github.com/jpetazzo.png","language":"Shell","readme":"# Looking to start a shell inside a Docker container?\n\nStarting from Docker 1.3 you can use [Docker exec](https://docs.docker.com/reference/commandline/cli/#exec) to enter a Docker container. Example:\n\n    docker exec -it CONTAINER_NAME /bin/bash\n\nThere are differences between nsenter and docker exec; namely, nsenter doesn't enter the cgroups, and therefore evades resource limitations. The potential benefit of this would be debugging and external audit, but  for remote access, **docker exec is the current recommended approach**.\n\n**Important notice:** this repository was useful in the early days of Docker, because `nsenter` was missing from major distributions back then. `nsenter` was written in early 2013, and included in `util-linux` release 2.23. If we look at Ubuntu LTS releases, `trusty` (14.04) shipped `util-linux` 2.20, and `xenial` (16.04) shipped 2.27. In other words, if you were using Ubuntu LTS, you had to wait until 2016 to get `nsenter` through the main, official packages. That being said, all modern distros now ship with `nsenter`, and this repository is no longer useful, except for historical or curiosity purposes. **It is no longer maintained.**\n\n\n## nsenter in a can\n\nThis is a small Docker recipe to build `nsenter` easily and install it in your\nsystem.\n\n\n## What is `nsenter`?\n\nIt is a small tool allowing to `enter` into `n`ame`s`paces. Technically,\nit can enter existing namespaces, or spawn a process into a new set of\nnamespaces. \"What are those namespaces you're blabbering about?\"\nWe are talking about [container namespaces].\n\n`nsenter` can do many useful things, but the main reason why I'm so\nexcited about it is because it lets you [enter into a Docker container].\n\n\n## Why build `nsenter` in a container?\n\nThis is because my preferred distros (Debian and Ubuntu) ship with an\noutdated version of `util-linux` (the package that should contain `nsenter`).\nTherefore, if you need `nsenter` on those distros, you have to juggle with\nAPT repository, or compile from source, or… Ain't nobody got time for that.\n\nI'm going to make a very bold assumption: if you landed here, it's because\nyou want to enter a Docker container. Therefore, you won't mind if my\nmethod to build `nsenter` uses Docker itself.\n\n\n## How do I install `nsenter` with this?\n\nIf you want to install `nsenter` into `/usr/local/bin`, just do this:\n\n    docker run --rm -v /usr/local/bin:/target jpetazzo/nsenter\n\nThe `jpetazzo/nsenter` container will detect that `/target` is a\nmountpoint, and it will copy the `nsenter` binary into it.\n\nIf you don't trust me, and prefer to extract the `nsenter` binary,\nrather than allowing my container to potentially wreak havoc into\nyour system's `$PATH`, you can also do this:\n\n    docker run --rm jpetazzo/nsenter cat /nsenter \u003e /tmp/nsenter \u0026\u0026 chmod +x /tmp/nsenter\n\nThen do whatever you want with the binary in `/tmp/nsenter`.\n\n\n##  How do I *use* `nsenter`?\n\nFirst, figure out the PID of the container you want to enter:\n\n    PID=$(docker inspect --format {{.State.Pid}} \u003ccontainer_name_or_ID\u003e)\n\nThen enter the container:\n\n    nsenter --target $PID --mount --uts --ipc --net --pid\n\n\n## What's that docker-enter thing?\n\nIt's just a small shell script that wraps up the steps described above into\na tiny helper. It takes the name or ID of a container and optionally the name\nof a program to execute inside the namespace. If no command is specified a\nshell will be invoked instead.\n\n    # list the root filesystem\n    docker-enter my_awesome_container ls -la\n\n\n## Docker toolbox usage for OS X or Windows user\n\n\n### SSH to the Docker Toolbox virtual machine\n\n    docker-machine ssh default\n\n\n### Install nsenter, docker-enter, and importenv into the VM\n\n    docker run --rm -v /usr/local/bin:/target jpetazzo/nsenter\n\nYou can also install `nsenter` to another folder. In that case, you will\nneed to specify the full path of `nsenter` to run it.\n\n    docker run --rm -v /tmp:/target jpetazzo/nsenter\n\n\n### Using nsenter\n\nList running containers:\n\n    docker ps\n\nIdentify the ID of the container that you want to get into; and retrieve\nits associated PID:\n\n    PID=$(docker inspect --format {{.State.Pid}} 08a2a025e05f)\n\nEnter the container:\n\n    sudo nsenter --target $PID --mount --uts --ipc --net --pid\n\nRemember to run those commands in the Docker Toolbox virtual machine; not\nin your host environment.\n\n\n### Using docker-enter\n\nWith `docker-enter`, you don't need to lookup the container PID.\n\nYou can get a shell inside the container:\n\n    docker-enter 08a2a025e05f\n\nOr run commands directly:\n\n    docker-enter 08a2a025e05f ls /var/log\n    docker-enter 08a2a025e05f df -h\n\n\n## docker-enter with boot2docker\n\nIf you are using boot2docker, you can use the function below, to:\n\n- install `nsenter` and `docker-enter` into boot2docker's /var/lib/boot2docker/ directory,\n  so they survive restarts.\n- execute `docker-enter` inside of boot2docker combined with ssh\n\n```\ndocker-enter() {\n  boot2docker ssh '[ -f /var/lib/boot2docker/nsenter ] || docker run --rm -v /var/lib/boot2docker/:/target jpetazzo/nsenter'\n  boot2docker ssh -t sudo /var/lib/boot2docker/docker-enter \"$@\"\n}\n```\n\nYou can use it directly from your host (OS X/Windows), no need to ssh into boot2docker.\n\n\n## Caveats\n\n- This only works on Intel 64 bits platforms. It should be relatively\n  easy to adapt to other architectures, though.\n- `nsenter` still needs to run from the host; it cannot run inside a\n  container (yet).\n\n\n[container namespaces]: https://www.youtube.com/watch?v=sK5i-N34im8\n[enter into a Docker container]: http://jpetazzo.github.io/2014/03/23/lxc-attach-nsinit-nsenter-docker-0-9/\n[Debugging a Docker container]: http://blog.loof.fr/2014/06/debugging-docker-container.html\n[Nicolas De Loof]: https://twitter.com/ndeloof\n","funding_links":[],"categories":["Container Operations","Shell","Dev Tools"],"sub_categories":["User Interface"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpetazzo%2Fnsenter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjpetazzo%2Fnsenter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjpetazzo%2Fnsenter/lists"}