mirror of https://github.com/docker/cli.git
introduce `—workdir` option for docker exec
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
6b63d7b96a
commit
591a1273fd
|
@ -24,6 +24,7 @@ type execOptions struct {
|
|||
user string
|
||||
privileged bool
|
||||
env opts.ListOpts
|
||||
workdir string
|
||||
container string
|
||||
command []string
|
||||
}
|
||||
|
@ -57,6 +58,7 @@ func NewExecCommand(dockerCli command.Cli) *cobra.Command {
|
|||
flags.StringVarP(&options.user, "user", "u", "", "Username or UID (format: <name|uid>[:<group|gid>])")
|
||||
flags.BoolVarP(&options.privileged, "privileged", "", false, "Give extended privileges to the command")
|
||||
flags.VarP(&options.env, "env", "e", "Set environment variables")
|
||||
flags.StringVarP(&options.workdir, "workdir", "w", "", "Working directory inside the container")
|
||||
flags.SetAnnotation("env", "version", []string{"1.25"})
|
||||
|
||||
return cmd
|
||||
|
@ -190,6 +192,7 @@ func parseExec(opts execOptions, configFile *configfile.ConfigFile) *types.ExecC
|
|||
Cmd: opts.command,
|
||||
Detach: opts.detach,
|
||||
Env: opts.env.GetAll(),
|
||||
WorkingDir: opts.workdir,
|
||||
}
|
||||
|
||||
// If -d is not set, attach to everything by default
|
||||
|
|
|
@ -1439,7 +1439,7 @@ _docker_container_exec() {
|
|||
|
||||
case "$cur" in
|
||||
-*)
|
||||
COMPREPLY=( $( compgen -W "--detach -d --detach-keys --env -e --help --interactive -i --privileged -t --tty -u --user" -- "$cur" ) )
|
||||
COMPREPLY=( $( compgen -W "--detach -d --detach-keys --env -e --help --interactive -i --privileged -t --tty -u --user --workdir -w" -- "$cur" ) )
|
||||
;;
|
||||
*)
|
||||
__docker_complete_containers_running
|
||||
|
|
|
@ -174,6 +174,7 @@ complete -c docker -A -f -n '__fish_seen_subcommand_from exec' -s d -l detach -d
|
|||
complete -c docker -A -f -n '__fish_seen_subcommand_from exec' -l help -d 'Print usage'
|
||||
complete -c docker -A -f -n '__fish_seen_subcommand_from exec' -s i -l interactive -d 'Keep STDIN open even if not attached'
|
||||
complete -c docker -A -f -n '__fish_seen_subcommand_from exec' -s t -l tty -d 'Allocate a pseudo-TTY'
|
||||
complete -c docker -A -f -n '__fish_seen_subcommand_from exec' -s w -l workdir -d 'Working directory inside the container'
|
||||
complete -c docker -A -f -n '__fish_seen_subcommand_from exec' -a '(__fish_print_docker_containers running)' -d "Container"
|
||||
|
||||
# export
|
||||
|
|
|
@ -745,6 +745,7 @@ __docker_container_subcommand() {
|
|||
"($help)--privileged[Give extended Linux capabilities to the command]" \
|
||||
"($help -t --tty)"{-t,--tty}"[Allocate a pseudo-tty]" \
|
||||
"($help -u --user)"{-u=,--user=}"[Username or UID]:user:_users" \
|
||||
"($help -w --workdir)"{-w=,--workdir=}"[Working directory inside the container]:directory:_directories"
|
||||
"($help -):containers:__docker_complete_running_containers" \
|
||||
"($help -)*::command:->anycommand" && ret=0
|
||||
case $state in
|
||||
|
|
|
@ -29,6 +29,7 @@ Options:
|
|||
--privileged Give extended privileges to the command
|
||||
-t, --tty Allocate a pseudo-TTY
|
||||
-u, --user Username or UID (format: <name|uid>[:<group|gid>])
|
||||
-w, --workdir Working directory inside the container
|
||||
```
|
||||
|
||||
## Description
|
||||
|
@ -86,6 +87,20 @@ This will create a new Bash session in the container `ubuntu_bash` with environm
|
|||
variable `$VAR` set to "1". Note that this environment variable will only be valid
|
||||
on the current Bash session.
|
||||
|
||||
By default `docker exec` command runs in the same working directory set when container was created.
|
||||
|
||||
```bash
|
||||
$ docker exec -it ubuntu_bash pwd
|
||||
/
|
||||
```
|
||||
|
||||
You can select working directory for the command to execute into
|
||||
|
||||
```bash
|
||||
$ docker exec -it -w /root ubuntu_bash pwd
|
||||
/root
|
||||
```
|
||||
|
||||
|
||||
### Try to run `docker exec` on a paused container
|
||||
|
||||
|
|
Loading…
Reference in New Issue