def create_container(image,
                     command=None,
                     hostname=None,
                     user=None,
                     detach=True,
                     stdin_open=False,
                     tty=False,
                     mem_limit=None,
                     ports=None,
                     environment=None,
                     dns=None,
                     volumes=None,
                     volumes_from=None,
                     name=None,
                     cpu_shares=None,
                     cpuset=None,
                     binds=None):
    '''
    Create a new container

    image
        image to create the container from
    command
        command to execute while starting
    hostname
        hostname of the container
    user
        user to run docker as
    detach
        daemon mode, Default is ``True``
    environment
        environment variable mapping ``({'foo':'BAR'})``
    ports
        port redirections ``({'222': {}})``
    volumes
        list of volume mappings in either local volume, bound volume, or read-only
        bound volume form::

            (['/var/lib/mysql/', '/usr/local/etc/ssl:/etc/ssl', '/etc/passwd:/etc/passwd:ro'])
    binds
        complete dictionary of bound volume mappings::

            { '/usr/local/etc/ssl/certs/internal.crt': {
                'bind': '/etc/ssl/certs/com.example.internal.crt',
                'ro': True
                },
              '/var/lib/mysql': {
                'bind': '/var/lib/mysql/',
                'ro': False
                }
            }

        This dictionary is suitable for feeding directly into the Docker API, and all
        keys are required.
        (see http://docker-py.readthedocs.org/en/latest/volumes/)
    tty
        attach ttys, Default is ``False``
    stdin_open
        let stdin open, Default is ``False``
    name
        name given to container
    cpu_shares
        CPU shares (relative weight)
    cpuset
        CPUs in which to allow execution ('0-3' or '0,1')

    CLI Example:

    .. code-block:: bash

        salt '*' docker.create_container o/ubuntu volumes="['/s','/m:/f']"

    '''
    log.trace("modules.dockerio.create_container() called for image " + image)
    status = base_status.copy()
    client = _get_client()

    # In order to permit specification of bind volumes in the volumes field,
    #  we'll look through it for bind-style specs and move them. This is purely
    #  for CLI convenience and backwards-compatibility, as states.dockerio
    #  should parse volumes before this, and the binds argument duplicates this.
    # N.B. this duplicates code in states.dockerio._parse_volumes()
    if isinstance(volumes, list):
        for volume in volumes:
            if ':' in volume:
                volspec = volume.split(':')
                source = volspec[0]
                target = volspec[1]
                ro = False
                try:
                    if len(volspec) > 2:
                        ro = volspec[2] == "ro"
                except __HOLE__:
                    pass
                binds[source] = {'bind': target, 'ro': ro}
                volumes.remove(volume)

    try:
        if salt.utils.version_cmp(client.version()['ApiVersion'], '1.18') == 1:
            container_info = client.create_container(
                image=image,
                command=command,
                hostname=hostname,
                user=user,
                detach=detach,
                stdin_open=stdin_open,
                tty=tty,
                ports=ports,
                environment=environment,
                dns=dns,
                volumes=volumes,
                volumes_from=volumes_from,
                name=name,
                cpu_shares=cpu_shares,
                cpuset=cpuset,
                host_config=docker.utils.create_host_config(binds=binds,
                                                            mem_limit=mem_limit)
            )
        else:
            container_info = client.create_container(
                image=image,
                command=command,
                hostname=hostname,
                user=user,
                detach=detach,
                stdin_open=stdin_open,
                tty=tty,
                mem_limit=mem_limit,
                ports=ports,
                environment=environment,
                dns=dns,
                volumes=volumes,
                volumes_from=volumes_from,
                name=name,
                cpu_shares=cpu_shares,
                cpuset=cpuset,
                host_config=docker.utils.create_host_config(binds=binds)
            )

        log.trace("docker.client.create_container returned: " + str(container_info))
        container = container_info['Id']
        callback = _valid
        comment = 'Container created'
        out = {
            'info': _get_container_infos(container),
            'out': container_info
        }
        __salt__['mine.send']('dockerng.ps', verbose=True, all=True, host=True)
        return callback(status, id_=container, comment=comment, out=out)
    except Exception as e:
        _invalid(status, id_=image, out=traceback.format_exc())
        raise e
    __salt__['mine.send']('dockerng.ps', verbose=True, all=True, host=True)
    return status
dataset/ETHPy150Open saltstack/salt/salt/modules/dockerio.py/create_container