openshift/dockerexec

Name: dockerexec

Owner: OpenShift

Description: null

Created: 2015-04-30 22:14:38.0

Updated: 2016-01-06 14:37:21.0

Pushed: 2015-05-26 20:03:30.0

Homepage: null

Size: 6907

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

dockerexec

dockerexec provides a library and a utility to execute commands in a running docker container.

Basic usage
art a docker container
t@localhost busybox]# docker run -it --env FOO=BAR -u daemon --rm fedora:latest bash
-4.3$ 
-4.3$ env
NAME=8b1b399c89fd
=xterm
BAR
=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/
L=1
=/sbin
sr/bin/env
-4.3$ id
2(daemon) gid=2(daemon) groups=2(daemon)
-4.3$

n dockerexec specifying the same container id (shortest unique prefix works)
t@localhost containers]# dockerexec exec  -t  --id 8b1b sh
.3$ env
NAME=8b1b399c89fd
=xterm
BAR
=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/
L=1
=/sbin
sr/bin/env
.3$ id
2(daemon) gid=2(daemon) groups=2(daemon)
.3$ ps -ef
       PID  PPID  C STIME TTY          TIME CMD
on       1     0  0 14:31 ?        00:00:00 bash
on      23     0  0 14:37 ?        00:00:00 sh
on      28    23  0 14:37 ?        00:00:00 ps -ef
.3$ 

te that the user and the environment are the same for the two
ck to the docker container
-4.3$ ps -ef
       PID  PPID  C STIME TTY          TIME CMD
on       1     0  0 14:31 ?        00:00:00 bash
on      23     0  0 14:37 ?        00:00:00 sh
on      29     1  0 14:37 ?        00:00:00 ps -ef
-4.3$

By default dockerexec spawns the process as the same user and env as the docker container. User could be modified and more env variables could be specified using command line arguments.

t@localhost containers]# dockerexec exec  -t --user root --env COOL=STUFF  --id 8b1b sh                         
.3# env
NAME=8b1b399c89fd
=xterm
BAR
=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/
L=1
=/root
=STUFF
sr/bin/env
.3# id
0(root) gid=0(root) groups=0(root)

t@localhost containers]# dockerexec help exec
:
xec - execute a new command inside a container

E:
ommand exec [command options] [arguments...]

RIPTION:


ONS:
-tty, -t                            allocate a TTY for the exec process
-id                                 specify the ID of a running docker container
-user, -u                           set the user, uid, and/or gid for the process
-cwd                                set the current working dir
-env '--env option --env option'    set environment variables for the process

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.