diff --git a/app/react/docker/containers/CreateView/useInitialValues.ts b/app/react/docker/containers/CreateView/useInitialValues.ts index 03811f821..efdb4523d 100644 --- a/app/react/docker/containers/CreateView/useInitialValues.ts +++ b/app/react/docker/containers/CreateView/useInitialValues.ts @@ -66,9 +66,10 @@ export function useInitialValues(submitting: boolean, isWindows: boolean) { const networksQuery = useNetworksForSelector(); - const fromContainerQuery = useContainer(environmentId, from, { + const fromContainerQuery = useContainer(environmentId, from, nodeName, { enabled: !submitting, }); + const runningContainersQuery = useContainers(environmentId, { enabled: !!from, }); diff --git a/app/react/docker/containers/LogView/LogView.tsx b/app/react/docker/containers/LogView/LogView.tsx index ae1961e1b..37454053d 100644 --- a/app/react/docker/containers/LogView/LogView.tsx +++ b/app/react/docker/containers/LogView/LogView.tsx @@ -8,10 +8,10 @@ import { Link } from '@@/Link'; export function LogView() { const { - params: { endpointId: environmentId, id: containerId }, + params: { endpointId: environmentId, id: containerId, nodeName }, } = useCurrentStateAndParams(); - const containerQuery = useContainer(environmentId, containerId); + const containerQuery = useContainer(environmentId, containerId, nodeName); if (!containerQuery.data || containerQuery.isLoading) { return null; } diff --git a/app/react/docker/containers/queries/container.ts b/app/react/docker/containers/queries/container.ts index 5ecb38df2..872c41ab7 100644 --- a/app/react/docker/containers/queries/container.ts +++ b/app/react/docker/containers/queries/container.ts @@ -7,6 +7,7 @@ import { MountPoint, NetworkSettings, } from 'docker-types/generated/1.41'; +import { RawAxiosRequestHeaders } from 'axios'; import { PortainerResponse } from '@/react/docker/types'; import axios, { parseAxiosError } from '@/portainer/services/axios'; @@ -75,11 +76,15 @@ export interface ContainerJSON { export function useContainer( environmentId: EnvironmentId, containerId?: ContainerId, + nodeName?: string, { enabled }: { enabled?: boolean } = {} ) { return useQuery( containerId ? queryKeys.container(environmentId, containerId) : [], - () => (containerId ? getContainer(environmentId, containerId) : undefined), + () => + containerId + ? getContainer(environmentId, containerId, nodeName) + : undefined, { meta: { title: 'Failure', @@ -103,11 +108,19 @@ export type ContainerResponse = PortainerResponse; async function getContainer( environmentId: EnvironmentId, - containerId: ContainerId + containerId: ContainerId, + nodeName?: string ) { try { + const headers: RawAxiosRequestHeaders = {}; + + if (nodeName) { + headers['X-PortainerAgent-Target'] = nodeName; + } + const { data } = await axios.get( - urlBuilder(environmentId, containerId, 'json') + urlBuilder(environmentId, containerId, 'json'), + { headers } ); return data; } catch (error) {