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
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
- [:whale: nerdctl network ls](#whale-nerdctl-network-ls)
- [:whale: nerdctl network inspect](#whale-nerdctl-network-inspect)
- [:whale: nerdctl network rm](#whale-nerdctl-network-rm)
- [Volume management](#volume-management)
- [:whale: nerdctl volume create](#whale-nerdctl-volume-create)
- [:whale: nerdctl volume ls](#whale-nerdctl-volume-ls)
- [:whale: nerdctl volume inspect](#whale-nerdctl-volume-inspect)
- [:whale: nerdctl volume rm](#whale-nerdctl-volume-rm)
- [System](#system)
- [:whale: nerdctl events](#whale-nerdctl-events)
- [:whale: nerdctl info](#whale-nerdctl-info)
Expand Down Expand Up @@ -215,7 +220,6 @@ Runtime flags:

Volume flags:
- :whale: `-v, --volume`: Bind mount a volume
- :warning: Bind-mount only. Creating named volumes (`nerdctl volume create`) is not implemented yet.

Rootfs flags:
- :whale: `--read-only`: Mount the container's root filesystem as read only
Expand Down Expand Up @@ -381,6 +385,21 @@ Display detailed information on one or more networks
### :whale: nerdctl network rm
Remove one or more networks

## Volume management
### :whale: nerdctl volume create
Create a volume

### :whale: nerdctl volume ls
List volumes

- :whale: `-q, --quiet`: Only display volume names

### :whale: nerdctl volume inspect
Display detailed information on one or more volumes

### :whale: nerdctl volume rm
Remove one or more volumes

## System
### :whale: nerdctl events
Get real time events from the server.
Expand Down Expand Up @@ -429,9 +448,6 @@ Image:

- `docker manifest *`

Volume management:
- `docker volume *`

Network management:
- `docker network connect`
- `docker network disconnect`
Expand Down
5 changes: 5 additions & 0 deletions docs/dir.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ Files:

Files must be operated with a `LOCK_EX` lock against the `<DATAROOT>/<ADDRHASH>/etchosts` directory.

### `<DATAROOT>/<ADDRHASH>/volumes/<NAMESPACE>/<VOLNAME>/_data`
e.g. `/var/lib/nerdctl/1935db59/volumes/default/foo/_data`

Data volume

## CNI

### `<NETCONFPATH>`
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func newApp() *cli.App {
containerCommand,
imageCommand,
networkCommand,
volumeCommand,
systemCommand,
// Internal
internalCommand,
Expand Down
9 changes: 4 additions & 5 deletions network_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ import (
)

var networkCreateCommand = &cli.Command{
Name: "create",
Usage: "Create a network",
Description: "NOTE: To isolate CNI bridge, CNI isolation plugin needs to be installed: https://github.com/AkihiroSuda/cni-isolation\n" + "\n" +
"No support for looking up container IPs by their names yet",
ArgsUsage: "[flags] NETWORK",
Name: "create",
Usage: "Create a network",
Description: "NOTE: To isolate CNI bridge, CNI isolation plugin needs to be installed: https://github.com/AkihiroSuda/cni-isolation",
ArgsUsage: "[flags] NETWORK",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "subnet",
Expand Down
24 changes: 24 additions & 0 deletions pkg/inspecttypes/native/volume.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Copyright (C) nerdctl authors.
Copyright (C) containerd authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package native

// Volume is also compatible with Docker
type Volume struct {
Name string `json:"Name"`
Mountpoint string `json:"Mountpoint"`
}
11 changes: 9 additions & 2 deletions pkg/mountutil/mountutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,26 @@ import (
"path/filepath"
"strings"

"github.com/AkihiroSuda/nerdctl/pkg/inspecttypes/native"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

func ParseFlagV(s string) (*specs.Mount, error) {
func ParseFlagV(s string, volumes map[string]native.Volume) (*specs.Mount, error) {
split := strings.Split(s, ":")
if len(split) < 2 || len(split) > 3 {
return nil, errors.Errorf("failed to parse %q", s)
}
src, dst := split[0], split[1]
if !strings.Contains(src, "/") {
return nil, errors.Errorf("expected an absolute path, got %q (FIXME: named volume is unsupported yet)", src)
// assume src is a volume name
vol, ok := volumes[src]
if !ok {
return nil, errors.Errorf("unknown volume name %q", src)
}
// src is now full path
src = vol.Mountpoint
}
if !filepath.IsAbs(src) {
logrus.Warnf("expected an absolute path, got a relative path %q (allowed for nerdctl, but disallowed for Docker, so unrecommended)", src)
Expand Down
40 changes: 40 additions & 0 deletions pkg/mountutil/volumestore/volumestore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright (C) nerdctl authors.
Copyright (C) containerd authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package volumestore

import (
"os"
"path/filepath"

"github.com/containerd/containerd/errdefs"
)

// New returns a string like `/var/lib/nerdctl/1935db59/volumes/default`
func New(dataStore, ns string) (string, error) {
if dataStore == "" || ns == "" {
return "", errdefs.ErrInvalidArgument
}
volStore := filepath.Join(dataStore, "volumes", ns)
if err := os.MkdirAll(volStore, 0700); err != nil {
return "", err
}
return volStore, nil
}

// DataDirName is "_data"
const DataDirName = "_data"
15 changes: 4 additions & 11 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (
"github.com/AkihiroSuda/nerdctl/pkg/imgutil"
"github.com/AkihiroSuda/nerdctl/pkg/labels"
"github.com/AkihiroSuda/nerdctl/pkg/logging"
"github.com/AkihiroSuda/nerdctl/pkg/mountutil"
"github.com/AkihiroSuda/nerdctl/pkg/namestore"
"github.com/AkihiroSuda/nerdctl/pkg/netutil"
"github.com/AkihiroSuda/nerdctl/pkg/portutil"
Expand Down Expand Up @@ -319,16 +318,10 @@ func runAction(clicontext *cli.Context) error {
opts = append(opts, oci.WithTTY)
}

if flagVSlice := clicontext.StringSlice("v"); len(flagVSlice) > 0 {
mounts := make([]specs.Mount, len(flagVSlice))
for i, v := range flagVSlice {
m, err := mountutil.ParseFlagV(v)
if err != nil {
return err
}
mounts[i] = *m
}
opts = append(opts, oci.WithMounts(mounts))
if mountOpts, err := generateMountOpts(clicontext); err != nil {
return err
} else {
opts = append(opts, mountOpts...)
}

var logURI string
Expand Down
47 changes: 47 additions & 0 deletions run_mount.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Copyright (C) nerdctl authors.
Copyright (C) containerd authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"github.com/AkihiroSuda/nerdctl/pkg/mountutil"
"github.com/containerd/containerd/oci"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/urfave/cli/v2"
)

func generateMountOpts(clicontext *cli.Context) ([]oci.SpecOpts, error) {
var opts []oci.SpecOpts

if flagVSlice := clicontext.StringSlice("v"); len(flagVSlice) > 0 {
volumes, err := getVolumes(clicontext)
if err != nil {
return nil, err
}
ociMounts := make([]specs.Mount, len(flagVSlice))
for i, v := range flagVSlice {
m, err := mountutil.ParseFlagV(v, volumes)
if err != nil {
return nil, err
}
ociMounts[i] = *m
}
opts = append(opts, oci.WithMounts(ociMounts))
}

return opts, nil
}
45 changes: 45 additions & 0 deletions volume.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Copyright (C) nerdctl authors.
Copyright (C) containerd authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"github.com/AkihiroSuda/nerdctl/pkg/mountutil/volumestore"
"github.com/urfave/cli/v2"
)

var volumeCommand = &cli.Command{
Name: "volume",
Usage: "Manage volumes",
Category: CategoryManagement,
Subcommands: []*cli.Command{
volumeLsCommand,
volumeInspectCommand,
volumeCreateCommand,
volumeRmCommand,
},
}

// getVolumeStore returns a string like `/var/lib/nerdctl/1935db59/volumes/default`
func getVolumeStore(clicontext *cli.Context) (string, error) {
dataStore, err := getDataStore(clicontext)
if err != nil {
return "", err
}
ns := clicontext.String("namespace")
return volumestore.New(dataStore, ns)
}
67 changes: 67 additions & 0 deletions volume_create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
Copyright (C) nerdctl authors.
Copyright (C) containerd authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"fmt"
"os"
"path/filepath"

"github.com/AkihiroSuda/nerdctl/pkg/lockutil"
"github.com/AkihiroSuda/nerdctl/pkg/mountutil/volumestore"
"github.com/containerd/containerd/identifiers"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
)

var volumeCreateCommand = &cli.Command{
Name: "create",
Usage: "Create a volume",
ArgsUsage: "[flags] VOLUME",
Action: volumeCreateAction,
}

func volumeCreateAction(clicontext *cli.Context) error {
if clicontext.NArg() != 1 {
return errors.Errorf("requires exactly 1 argument")
}
name := clicontext.Args().First()
if err := identifiers.Validate(name); err != nil {
return errors.Wrapf(err, "malformed name %s", name)
}

volStore, err := getVolumeStore(clicontext)
if err != nil {
return err
}

volPath := filepath.Join(volStore, name)
volDataPath := filepath.Join(volPath, volumestore.DataDirName)
fn := func() error {
if err := os.Mkdir(volPath, 0700); err != nil {
return err
}
if err := os.Mkdir(volDataPath, 0755); err != nil {
return err
}
fmt.Fprintf(clicontext.App.Writer, "%s\n", name)
return nil
}

return lockutil.WithDirLock(volStore, fn)
}
Loading