Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,27 @@ sudo make install

### Using:

To run a container that you received just execute `runc` with the JSON format as the argument or have a
`config.json` file in the current working directory.
To run a container, execute `runc start` in the bundle's root directory:
```bash
runc start
/ $ ps
PID USER COMMAND
1 daemon sh
5 daemon sh
/ $
```

Or you can specify the path to a JSON configuration file:
```bash
runc
runc start config.json
/ $ ps
PID USER COMMAND
1 daemon sh
5 daemon sh
/ $
```
Note: the use of the `start` command is required when specifying a
configuration file.

### OCF Container JSON Format:

Expand Down Expand Up @@ -210,9 +220,9 @@ tar -C rootfs -xf busybox.tar
```
* Create a file called `config.json` using the example from above. You can also
generate a spec using `runc spec`, redirecting the output into `config.json`
* Execute `runc` and you should be placed into a shell where you can run `ps`:
* Execute `runc start` and you should be placed into a shell where you can run `ps`:
```
$ runc
$ runc start
/ # ps
PID USER COMMAND
1 root sh
Expand Down
10 changes: 8 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ After creating a spec for your root filesystem with runc, you can execute a
container in your shell by running:

cd /mycontainer
runc [ spec-file ]
runc start

or
cd /mycontainer
runc start [ spec-file ]

If not specified, the default value for the 'spec-file' is 'config.json'. `
)
Expand Down Expand Up @@ -56,6 +60,7 @@ func main() {
},
}
app.Commands = []cli.Command{
startCommand,
checkpointCommand,
eventsCommand,
restoreCommand,
Expand All @@ -69,7 +74,8 @@ func main() {
return nil
}

app.Action = runAction
// Default to 'start' is no command is specified
app.Action = startCommand.Action
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you still leave this here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to break existing functionality - meaning "runc" by itself. I believe this line makes it default to "start" if no command is given. Is that not correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, just checking. we could probably remove it soon right? maybe in the docs not have the runc example without using runc start

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep we could if the long-term direction is to always require an 'action' verb. Want me to update the docs to always show an action?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok done!


if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)
Expand Down
51 changes: 28 additions & 23 deletions run.go → start.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,33 @@ import (
"github.com/opencontainers/specs"
)

var startCommand = cli.Command{
Name: "start",
Usage: "create and run a container",
Action: func(context *cli.Context) {
spec, err := loadSpec(context.Args().First())

notifySocket := os.Getenv("NOTIFY_SOCKET")
if notifySocket != "" {
setupSdNotify(spec, notifySocket)
}

if err != nil {
fatal(err)
}
if os.Geteuid() != 0 {
logrus.Fatal("runc should be run as root")
}
status, err := startContainer(context, spec)
if err != nil {
logrus.Fatalf("Container start failed: %v", err)
}
// exit with the container's exit status so any external supervisor is
// notified of the exit with the correct exit status.
os.Exit(status)
},
}

func init() {
if len(os.Args) > 1 && os.Args[1] == "init" {
runtime.GOMAXPROCS(1)
Expand All @@ -25,7 +52,7 @@ func init() {
}
}

func execContainer(context *cli.Context, spec *specs.LinuxSpec) (int, error) {
func startContainer(context *cli.Context, spec *specs.LinuxSpec) (int, error) {
config, err := createLibcontainerConfig(context.GlobalString("id"), spec)
if err != nil {
return -1, err
Expand Down Expand Up @@ -65,28 +92,6 @@ func execContainer(context *cli.Context, spec *specs.LinuxSpec) (int, error) {
}

// default action is to execute a container
func runAction(context *cli.Context) {
spec, err := loadSpec(context.Args().First())

notifySocket := os.Getenv("NOTIFY_SOCKET")
if notifySocket != "" {
setupSdNotify(spec, notifySocket)
}

if err != nil {
fatal(err)
}
if os.Geteuid() != 0 {
logrus.Fatal("runc should be run as root")
}
status, err := execContainer(context, spec)
if err != nil {
logrus.Fatalf("Container start failed: %v", err)
}
// exit with the container's exit status so any external supervisor is
// notified of the exit with the correct exit status.
os.Exit(status)
}

// If systemd is supporting sd_notify protocol, this function will add support
// for sd_notify protocol from within the container.
Expand Down