本文整理汇总了Python中dockerpty.pty.PseudoTerminal.start方法的典型用法代码示例。如果您正苦于以下问题:Python PseudoTerminal.start方法的具体用法?Python PseudoTerminal.start怎么用?Python PseudoTerminal.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dockerpty.pty.PseudoTerminal
的用法示例。
在下文中一共展示了PseudoTerminal.start方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: exec_command
# 需要导入模块: from dockerpty.pty import PseudoTerminal [as 别名]
# 或者: from dockerpty.pty.PseudoTerminal import start [as 别名]
def exec_command(self, options):
"""
Execute a command in a running container
Usage: exec [options] SERVICE COMMAND [ARGS...]
Options:
-d Detached mode: Run command in the background.
--privileged Give extended privileges to the process.
--user USER Run the command as this user.
-T Disable pseudo-tty allocation. By default `docker-compose exec`
allocates a TTY.
--index=index index of the container if there are multiple
instances of a service [default: 1]
"""
index = int(options.get('--index'))
service = self.project.get_service(options['SERVICE'])
detach = options['-d']
if IS_WINDOWS_PLATFORM and not detach:
raise UserError(
"Interactive mode is not yet supported on Windows.\n"
"Please pass the -d flag when using `docker-compose exec`."
)
try:
container = service.get_container(number=index)
except ValueError as e:
raise UserError(str(e))
command = [options['COMMAND']] + options['ARGS']
tty = not options["-T"]
create_exec_options = {
"privileged": options["--privileged"],
"user": options["--user"],
"tty": tty,
"stdin": tty,
}
exec_id = container.create_exec(command, **create_exec_options)
if detach:
container.start_exec(exec_id, tty=tty)
return
signals.set_signal_handler_to_shutdown()
try:
operation = ExecOperation(
self.project.client,
exec_id,
interactive=tty,
)
pty = PseudoTerminal(self.project.client, operation)
pty.start()
except signals.ShutdownException:
log.info("received shutdown exception: closing")
exit_code = self.project.client.exec_inspect(exec_id).get("ExitCode")
sys.exit(exit_code)
示例2: run_one_off_container
# 需要导入模块: from dockerpty.pty import PseudoTerminal [as 别名]
# 或者: from dockerpty.pty.PseudoTerminal import start [as 别名]
def run_one_off_container(container_options, project, service, options):
if not options['--no-deps']:
deps = service.get_dependency_names()
if deps:
project.up(
service_names=deps,
start_deps=True,
strategy=ConvergenceStrategy.never,
rescale=False
)
project.initialize()
container = service.create_container(
quiet=True,
one_off=True,
**container_options)
if options['-d']:
service.start_container(container)
print(container.name)
return
def remove_container(force=False):
if options['--rm']:
project.client.remove_container(container.id, force=True, v=True)
signals.set_signal_handler_to_shutdown()
try:
try:
if IS_WINDOWS_PLATFORM:
service.connect_container_to_networks(container)
exit_code = call_docker(["start", "--attach", "--interactive", container.id])
else:
operation = RunOperation(
project.client,
container.id,
interactive=not options['-T'],
logs=False,
)
pty = PseudoTerminal(project.client, operation)
sockets = pty.sockets()
service.start_container(container)
pty.start(sockets)
exit_code = container.wait()
except signals.ShutdownException:
project.client.stop(container.id)
exit_code = 1
except signals.ShutdownException:
project.client.kill(container.id)
remove_container(force=True)
sys.exit(2)
remove_container()
sys.exit(exit_code)
示例3: run_one_off_container
# 需要导入模块: from dockerpty.pty import PseudoTerminal [as 别名]
# 或者: from dockerpty.pty.PseudoTerminal import start [as 别名]
def run_one_off_container(container_options, project, service, options):
if not options['--no-deps']:
deps = service.get_linked_service_names()
if deps:
project.up(
service_names=deps,
start_deps=True,
strategy=ConvergenceStrategy.never)
project.initialize()
container = service.create_container(
quiet=True,
one_off=True,
**container_options)
if options['-d']:
service.start_container(container)
print(container.name)
return
def remove_container(force=False):
if options['--rm']:
project.client.remove_container(container.id, force=True)
signals.set_signal_handler_to_shutdown()
try:
try:
pty = PseudoTerminal(
project.client,
container.id,
interactive=not options['-T'],
logs=False,
)
sockets = pty.sockets()
service.start_container(container)
pty.start(sockets)
exit_code = container.wait()
except signals.ShutdownException:
project.client.stop(container.id)
exit_code = 1
except signals.ShutdownException:
project.client.kill(container.id)
remove_container(force=True)
sys.exit(2)
remove_container()
sys.exit(exit_code)