Repository: moby/moby
File: api/server/router/container/container_routes.go (Go)

Code before:
		// explicitly set.
		// Both `0` and `-1` are accepted as "unlimited", and historically any
		// negative value was accepted, so treat those as "unlimited" as well.
		hostConfig.PidsLimit = nil
	}

	if hostConfig != nil && versions.LessThan(version, "1.44") {
		for _, m := range hostConfig.Mounts {
			if m.BindOptions != nil {
				// Ignore ReadOnlyNonRecursive because it was added in API 1.44.
				m.BindOptions.ReadOnlyNonRecursive = false
				if m.BindOptions.ReadOnlyForceRecursive {
					return errdefs.InvalidParameter(errors.New("BindOptions.ReadOnlyForceRecursive needs API v1.44 or newer"))
				}
			}
		}
	}

	if versions.LessThan(version, "1.44") {
		// Creating a container connected to several networks is not supported until v1.44.
		if networkingConfig != nil && len(networkingConfig.EndpointsConfig) > 1 {
			l := make([]string, 0, len(networkingConfig.EndpointsConfig))
			for k := range networkingConfig.EndpointsConfig {
				l = append(l, k)
			}
			return errdefs.InvalidParameter(errors.Errorf("Container cannot be connected to network endpoints: %s", strings.Join(l, ", ")))
		}
	}

	ccr, err := s.backend.ContainerCreate(ctx, types.ContainerCreateConfig{
		Name:             name,
		Config:           config,
		HostConfig:       hostConfig,
		NetworkingConfig: networkingConfig,
		AdjustCPUShares:  adjustCPUShares,
		Platform:         platform,
	})
	if err != nil {
		return err
	}

	return httputils.WriteJSON(w, http.StatusCreated, ccr)
}

func (s *containerRouter) deleteContainers(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
	if err := httputils.ParseForm(r); err != nil {
		return err
	}

	name := vars["name"]
	config := &types.ContainerRmConfig{

Review comment (suggestion):
I know this error  was here before but it's an awful way of saying "you can't set multiple networks when you create a container"

Code after:
		// Both `0` and `-1` are accepted as "unlimited", and historically any
		// negative value was accepted, so treat those as "unlimited" as well.
		hostConfig.PidsLimit = nil
	}

	if hostConfig != nil && versions.LessThan(version, "1.44") {
		for _, m := range hostConfig.Mounts {
			if m.BindOptions != nil {
				// Ignore ReadOnlyNonRecursive because it was added in API 1.44.
				m.BindOptions.ReadOnlyNonRecursive = false
				if m.BindOptions.ReadOnlyForceRecursive {
					return errdefs.InvalidParameter(errors.New("BindOptions.ReadOnlyForceRecursive needs API v1.44 or newer"))
				}
			}
		}
	}

	if versions.LessThan(version, "1.44") {
		// Creating a container connected to several networks is not supported until v1.44.
		if networkingConfig != nil && len(networkingConfig.EndpointsConfig) > 1 {
			l := make([]string, 0, len(networkingConfig.EndpointsConfig))
			for k := range networkingConfig.EndpointsConfig {
				l = append(l, k)
			}
			return errdefs.InvalidParameter(errors.Errorf("Container cannot be created with multiple network endpoints: %s", strings.Join(l, ", ")))
		}
	}

	ccr, err := s.backend.ContainerCreate(ctx, types.ContainerCreateConfig{
		Name:             name,
		Config:           config,
		HostConfig:       hostConfig,
		NetworkingConfig: networkingConfig,
		AdjustCPUShares:  adjustCPUShares,
		Platform:         platform,
	})
	if err != nil {
		return err
	}

	return httputils.WriteJSON(w, http.StatusCreated, ccr)
}

func (s *containerRouter) deleteContainers(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
	if err := httputils.ParseForm(r); err != nil {
		return err
	}

	name := vars["name"]
	config := &types.ContainerRmConfig{
		ForceRemove:  httputils.BoolValue(r, "force"),