Skip to content

Commit

Permalink
modify commit command
Browse files Browse the repository at this point in the history
  • Loading branch information
xwjahahahaha committed Nov 15, 2021
1 parent ecb22a3 commit f08cc3e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions cmd/commands.go
Expand Up @@ -60,12 +60,12 @@ var runDocker = &cobra.Command{
}

var commitCommand = &cobra.Command{
Use: "commit [image_name]",
Use: "commit [container_id] [image_tar_name]",
Short: "commit a container into image",
Long: "commit a container into image",
Args: cobra.ExactArgs(1),
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
container.CommitContainer(args[0])
container.CommitContainer(args[0], args[1])
},
}

Expand Down
5 changes: 3 additions & 2 deletions container/commit.go
Expand Up @@ -2,14 +2,15 @@ package container

import (
"os/exec"
"path/filepath"
"xwj/mydocker/log"
)

// CommitContainer
// @Description: 打包一个容器
// @param imageName
func CommitContainer(imageName string) {
mntUrl := "./mnt"
func CommitContainer(containerID, imageName string) {
mntUrl := filepath.Join(ROOTURL, "mnt", containerID)
imageTarUrl := "./" + imageName + ".tar"
if _, err := exec.Command("tar", "-czf", imageTarUrl, "-C", mntUrl, ".").CombinedOutput(); err != nil {
log.LogErrorFrom("CommitContainer", "tar", err)
Expand Down

0 comments on commit f08cc3e

Please sign in to comment.