1

I'm fresher for docker. I had a bad network. Every time building the asp.net core project,it always stuck at dotnet restore step.

Because the project reference abp myget nightly. The error information:

Step 8/9 : RUN dotnet restore "IC.AuthServer.csproj" ---> Running in 4232f5677921 Failed to download package 'Volo.Abp.Core.0.19.0-preview20190724' from 'https://www.myget.org/F/abp-nightly/api/v3/flatcontainer/volo.abp.core/0.19.0-preview20190724/volo.abp.core.0.19.0-preview20190724.nupkg'. The SSL connection could not be established, see inner exception. Unable to read data from the transport connection: Connection reset by peer. Connection reset by peer Failed to download package 'Volo.Abp.IdentityServer.Domain.Shared.0.19.0-preview20190724' from 'https://www.myget.org/F/abp-nightly/api/v3/flatcontainer/volo.abp.identityserver.domain.shared/0.19.0-preview20190724/volo.abp.identityserver.domain.shared.0.19.0-preview20190724.nupkg'. The SSL connection could not be established, see inner exception. Unable to read data from the transport connection: Connection reset by peer.

I had get abp packages at ~/.nuget/. I attempt copy this to docker. but copy not support absolute path. Through I can copy it to current context directory. but it's so ugly .

Is there any way to mount host directory when building image?

Thanks in advance.

Here is Docker-compose.yml:

version: "3"
services:
  db-mysql:
    image: mysql
    ports:
      - "3308:3306"
    volumes:
      - mysql_data:/var/lib/mysql
      - mysql_init_files:/docker-entrypoint-initdb.d
    environment: 
      MYSQL_DATABASE: "Coriander_Account"
      MYSQL_ROOT_PASSWORD: "123456"

  auth-server:
    build:
      context: ./
      dockerfile: Applications/IC.AuthServer.Host/Dockerfile
    depends_on: 
      - db-mysql
    ports: 
      - "6001:80"

volumes: 
  mysql_data:
  dbdata:
  mysql_init_files:

Here is Dockerfile:

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY . .
WORKDIR "/src/Applications/IC.AuthServer.Host/"

// * I want to let docker mounting host directory at here. * 

RUN dotnet restore "IC.AuthServer.csproj"
RUN dotnet build "IC.AuthServer.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "IC.AuthServer.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "IC.AuthServer.dll"]
Echo
  • 183
  • 2
  • 11

1 Answers1

2

Is there any way to mount host directory when building image?

Mounting host volumes during build is not possible (see this response). However, you could use multistage builds and "mount" your host directory during a first disk space inefficient stage, and copy just what you need in the final step:

FROM ubuntu as intermediate
COPY myFiles /myFiles
RUN ... # some expensive operation

FROM ubuntu
COPY --from=intermediate /result /result
# simply use the result
Thibaud Ledent
  • 1,446
  • 1
  • 7
  • 6
  • my project is /home/user/workspace/CloudStorage/docker-compose.yml and the cache path is /home/user/.nuget . According your operation, i must copy the .nuget directory to /home/user/workspace/CloudStorage/.nuget? Is it? – Echo Aug 02 '19 at 06:28
  • One solution is to `COPY /home/user/workspace/CloudStorage/.nuget /nuget`. Your `nuget` folder will be copied in the docker container in `/nuget` – Thibaud Ledent Aug 02 '19 at 07:01
  • I test with your way. But copy absuolute path is not work . It will special a temp path. Error : failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder494280566/home/echo/.nuget: no such file or directory – Echo Aug 02 '19 at 08:40
  • Probably because you are using path outside of context for ADD/COPY commands. You should use relative path from your build context. See also https://github.com/docker/for-mac/issues/1922#issuecomment-491245969 – Thibaud Ledent Aug 02 '19 at 09:09
  • Thanks Thibaud, I run Dockerfile from Docker-Compose. I'll replenish my answer. – Echo Aug 02 '19 at 10:48