# Buggy code
def _get_container_create_options(self, override_options, one_off=False):
    container_options = dict(
        (k, self.options[k]) for k in DOCKER_CONFIG_KEYS if k in self.options
    )
    container_options.update(override_options)

    container_options["name"] = self._next_container_name(
        self.containers(stopped=True, one_off=one_off), one_off
    )

    # If a qualified hostname was given, split it into an
    # unqualified hostname and a domainname unless domainname
    # was also given explicitly. This matches the behavior of
    # the official Docker CLI in that scenario.
    if (
        "hostname" in container_options
        and "domainname" not in container_options
        and "." in container_options["hostname"]
    ):
        parts = container_options["hostname"].partition(".")
        container_options["hostname"] = parts[0]
        container_options["domainname"] = parts[2]

    if "ports" in container_options or "expose" in self.options:
        ports = []
        all_ports = container_options.get("ports", []) + self.options.get("expose", [])
        for port in all_ports:
            port = str(port)
            if ":" in port:
                port = port.split(":")[-1]
            if "/" in port:
                port = tuple(port.split("/"))
            ports.append(port)
        container_options["ports"] = ports

    if "volumes" in container_options:
        container_options["volumes"] = dict(
            (parse_volume_spec(v).internal, {}) for v in container_options["volumes"]
        )

    container_options["environment"] = merge_environment(container_options)

    if self.can_be_built():
        container_options["image"] = self.full_name
    else:
        container_options["image"] = self._get_image_name(container_options["image"])

    # Delete options which are only used when starting
    for key in DOCKER_START_KEYS:
        container_options.pop(key, None)

    return container_options


# Traceback (TypeError)
$ fig run -e BLA=bla bliep
Traceback (most recent call last):
File "/usr/local/bin/fig", line 9, in <module>
load_entry_point('fig==1.0.1', 'console_scripts', 'fig')()
File "/usr/local/lib/python2.7/site-packages/fig/cli/main.py", line 31, in main
command.sys_dispatch()
File "/usr/local/lib/python2.7/site-packages/fig/cli/docopt_command.py", line 21, in sys_dispatch
self.dispatch(sys.argv[1:], None)
File "/usr/local/lib/python2.7/site-packages/fig/cli/command.py", line 28, in dispatch
super(Command, self).dispatch(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/fig/cli/docopt_command.py", line 24, in dispatch
self.perform_command(*self.parse(argv, global_options))
File "/usr/local/lib/python2.7/site-packages/fig/cli/command.py", line 56, in perform_command
handler(project, command_options)
File "/usr/local/lib/python2.7/site-packages/fig/cli/main.py", line 312, in run
service.options['environment'][k] = v
TypeError: list indices must be integers, not unicode

# Fixed code
def _get_container_create_options(self, override_options, one_off=False):
    container_options = dict(
        (k, self.options[k]) for k in DOCKER_CONFIG_KEYS if k in self.options
    )
    container_options.update(override_options)

    container_options["name"] = self._next_container_name(
        self.containers(stopped=True, one_off=one_off), one_off
    )

    # If a qualified hostname was given, split it into an
    # unqualified hostname and a domainname unless domainname
    # was also given explicitly. This matches the behavior of
    # the official Docker CLI in that scenario.
    if (
        "hostname" in container_options
        and "domainname" not in container_options
        and "." in container_options["hostname"]
    ):
        parts = container_options["hostname"].partition(".")
        container_options["hostname"] = parts[0]
        container_options["domainname"] = parts[2]

    if "ports" in container_options or "expose" in self.options:
        ports = []
        all_ports = container_options.get("ports", []) + self.options.get("expose", [])
        for port in all_ports:
            port = str(port)
            if ":" in port:
                port = port.split(":")[-1]
            if "/" in port:
                port = tuple(port.split("/"))
            ports.append(port)
        container_options["ports"] = ports

    if "volumes" in container_options:
        container_options["volumes"] = dict(
            (parse_volume_spec(v).internal, {}) for v in container_options["volumes"]
        )

    container_options["environment"] = build_environment(container_options)

    if self.can_be_built():
        container_options["image"] = self.full_name
    else:
        container_options["image"] = self._get_image_name(container_options["image"])

    # Delete options which are only used when starting
    for key in DOCKER_START_KEYS:
        container_options.pop(key, None)

    return container_options