Docker manager¶
-
class
docker.manager.
Docker
(image='ubuntu', name_prefix='dyn', timeout=3600, privilege=False, combine_outputs=False, env_variables=None, ports_mapping=None)[source]¶ Docker manager which can start and stop containers in addition to run commands with docker exec. The manager also have a few helper functions for things like listing files and directories.
-
directory_exist
(path)[source]¶ Checks whether a directory exists or not.
Parameters: path (str) – The path to the directory. Return type: bool
-
file_exist
(path)[source]¶ Checks whether a file exists or not.
Parameters: path (str) – The path to the file. Return type: bool
-
list_directories
(path, include_trailing_slash=True)[source]¶ List directories on a given path.
Parameters: path (str) – The path to the directory.
Returns: An list of directory names
Return type: list
Raises: - DockerFileNotFoundError – If given an invalid path
- DockerWrapperBaseError – For other errors
-
list_files
(path, include_hidden=False)[source]¶ List files on a given path.
Parameters: - path (str) – The path to the directory.
- include_hidden (bool) – Include hidden files in output
Returns: An list of file names
Return type: list
Raises: - DockerFileNotFoundError – If given an invalid path
- DockerWrapperBaseError – For other errors
-
read_file
(path)[source]¶ Reads the content of the file on the given path. Returns None if the file does not exist.
Parameters: path (str) – The path to the file.
Returns: The content of the file
Return type: str
Raises: - DockerFileNotFoundError – If given an invalid path
- DockerWrapperBaseError – For other errors
-
run
(command, working_directory='', stdin='', login=False, tty=False)[source]¶ Runs the command with docker exec in the given working directory.
Parameters: - command (str) – The command that should be run with docker exec. The command will be wrapped in `bash -c ‘command’”.
- working_directory (str) – The path to the directory where the command should be run. This
will be evaluated with
_get_working_directory
, thus relative paths will become absolute paths. - login (boolean) – Will add –login on the bash call.
- tty (boolean) – Will add -t on the bash call.
Returns: A ProcessResult object containing information on the result of the command.
Return type: ProcessResult
-
start
()[source]¶ Starts a container based on the parameters passed to __init__.
Returns: The docker object
-
static
wrap
(*wrap_args, **wrap_kwargs)[source]¶ Decorator that wraps the function call in a Docker with statement. It accepts the same arguments. This decorator adds a docker manager instance to the kwargs passed into the decorated function.
Returns: The decorated function.
-
write_file
(path, content, append=False)[source]¶ Write the given content to path. Overwrites the file if append is set to False.
Parameters: - path (str) – The path to the file.
- content (str) – The content of the file.
- append (bool) – Set to False to overwrite file, defaults to False.
Returns: A object with the result of the create command.
Return type: ProcessResult
-