本文整理匯總了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)