docker-enter
is nothing more than a wrapper around
nsenter
. You could use
nsen
ter
directly after finding the process ID of the container with
docker inspect
,
like so:
$ docker inspect --format {{.State.Pid}} sleep
9302
$ sudo nsenter --target 9302 --mount --uts --ipc --net --pid
root@db9675525fab:/#
Discussion
Starting with Docker 1.3, you do not need to use
nsenter
; use
docker exec
instead:
$
docker exec -h
Usage: docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
Run a command in a running container
-d, --detach=false Detached mode: run command in the background
--help=false Print usage
-i, --interactive=false Keep STDIN open even if not attached
-t, --tty=false Allocate a pseudo-TTY
See Also
• GitHub
page from
Jerome Petazzoni
nsenter
repository
4.6 Introducing runc
Problem
You want to become familiar with the upcoming standard around the container for‐
mat and runtime
runc
.
Solution
The Open Container Project (OCP) was established in June 2015, and the specifica‐
tions coming from that project are still not done. However, Docker Inc. donated its
libcontainer
codebase as an early implementation of a standard runtime for contain‐
ers. This runtime is called
runc
.
The
OCP was just launched, so the specifications are not out yet.
Expect many changes until the specifications and reference imple‐
mentations are considered stable and official.
4.6 Introducing runc | 115
This recipe will give you a quick feel for
runc
, including instructions to compile the
Go codebase. As always, I prepared a Vagrant box that gives you a Docker host, a Go
1.4.2 installation,
and a clone of the
runc
code. To get started with this box, use the
following:
$ git clone https://github.com/how2dock/docbook.git
$ cd dockbook/ch04/runc
$ vagrant up
$ vagrant ssh
Once you are on a terminal inside this VM, you need to
grab all the dependencies of
runc
by using the
go get
command. Once this completes, you can build
runc
and
install. Verify that you have a running
runc
in your path:
Expect a change in the build process sometime soon. Most likely
the build will use Docker itself.
$ cd go/src
$ go get github.com/opencontainers/runc
$ cd github.com/opencontainers/runc/
$ make
$
sudo make install
$ runc -v
runc version 0.2
To run a container with
runc
, you need a root filesystem describing your container
image. The easiest way to get one is to use Docker itself and the
docker export
com‐
mand. So let’s
pull a Docker image, start a container, and export it to a tarball:
$ cd ~
$ mkdir foobar
$ cd foobar
$ docker run --name foobar -d ubuntu:14.04 sleep 30
$ docker export -o foobar.tar foobar
$ sudo -xf foobar.tar
$ rm foobar.tar
To run this container, you need to generate a configuration file.
This is most easily
done with the
runc spec
command. To get a container started quickly, you will need
to get only one change, which is the location of the root filesystem. In that JSON file,
edit
the path to it; you see an excerpt here:
$ runc spec > config.json
$ vi config.json
...
"root": {
"path": "./",
Do'stlaringiz bilan baham: