-1

I use dockerfile to build docker image, then using docker-compose for deployment. I want run a shell script in container-1 to start container-2.

I followed "Restart a docker container from another running container" and "Is it possible to start a stopped container from another container", but it was not work. Please suggest, How could I achieve this in the simplest way? The following is the file configuration

The dockerfile is automatically generated by vs.

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base WORKDIR /app EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build WORKDIR /src COPY ["Backend/Backend.API.csproj", "Backend/"] COPY ["BuildingBlock/CacheHandler/CacheHandler.csproj", "BuildingBlock/CacheHandler/"] COPY ["Backend.Domain/Backend.Domain.csproj", "Backend.Domain/"] RUN dotnet restore "Backend/Backend.API.csproj" COPY . . WORKDIR "/src/Backend" RUN dotnet build "Backend.API.csproj" -c Release -o /app/build

FROM build AS publish RUN dotnet publish "Backend.API.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS install-docker-cli RUN apt-get update && apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg RUN echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null RUN apt-get update && apt-get install -y docker-ce-cli

FROM base AS final WORKDIR /app COPY --from=publish /app/publish . COPY --from=install-docker-cli /usr/bin/docker /usr/bin/docker ENTRYPOINT ["dotnet", "Backend.API.dll"]

The docker-compose:

Backendbuild:
    context: .
    dockerfile: Dockerfile
volumes:
    - /var/run/docker.sock:/var/run/docker.sock

The error :

line 11: docker-compose: command not found
Kim NANA
  • 1
  • 1
  • 1
    share the dockerfile, please – BrownieInMotion May 21 '23 at 19:55
  • @BrownieInMotion I added the dockerfile. – Kim NANA May 22 '23 at 01:59
  • The error is literally what it says: your image doesn't contain the `docker-compose` command. There are a number of complexities around trying to use Docker this way, including the very real possibility of using the Docker socket to compromise the host system; can you redesign your application to not need this? – David Maze May 22 '23 at 10:56

1 Answers1

-1

Use the Docker API to programatically control containers from another server. See Examples using the Docker Engine SDKs and Docker API.

Run a container

This first example shows how to run a container using the Docker API.

curl --unix-socket /var/run/docker.sock -H "Content-Type: application/json" \
  -d '{"Image": "alpine", "Cmd": ["echo", "hello world"]}' \
  -X POST http://localhost/v1.43/containers/create
{"Id":"1c6594faf5","Warnings":null}
curl --unix-socket /var/run/docker.sock -X POST http://localhost/v1.43/containers/1c6594faf5/start
curl --unix-socket /var/run/docker.sock -X POST http://localhost/v1.43/containers/1c6594faf5/wait
{"StatusCode":0}
curl --unix-socket /var/run/docker.sock "http://localhost/v1.43/containers/1c6594faf5/logs?stdout=1"
hello world
Ronnie Royston
  • 16,778
  • 6
  • 77
  • 91