从docker-compose重构为每个项目的单独Docker文件后,我无法运行该容器,只是退出了。我同时使用docker和docker-compose,因为将来还会有更多项目。
我的docker文件如下。
docker-compose.yml
version: '3'
services:
customer:
image: customer
container_name: customer
build:
context: ./Customer
dockerfile: Dockerfile
客户/ Dockerfile
FROM mcr.microsoft.com/dotnet/core/runtime:2.2
WORKDIR /Customer
EXPOSE 80
COPY ./bin/Release/netcoreapp2.2/ service/
ENTRYPOINT ["dotnet", "service/Customer.dll"]
我之前在docker-compose文件中也有这个。如何在6001
内将80
映射到Dockerfile
?
ports:
- 6001:80
FROM mcr.microsoft.com/dotnet/core/sdk:2.2
WORKDIR /Customer
ENV DATABASE_HOST=database
ENV DATABASE_NAME=db
ENV DATABASE_USER=sa
ENV DATABASE_PASSWORD=Password
EXPOSE 80
COPY . .
CMD dotnet build
ENTRYPOINT ["dotnet", "Customer/bin/Release/netcoreapp2.2/Department.dll"]
从主站点复制。
从这里https://docs.docker.com/engine/examples/dotnetcore/复制
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "aspnetapp.dll"]
您是要运行dotnet SDK命令吗?请安装dotnet SDK 来自:https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
答案 0 :(得分:1)
这是一个懒惰的基本docker文件。我添加了一些注释和一些有用的构建/调试选项,例如:“ RUN ls -al”以列出当前目录。就像Linux VM。
# step 1 - building you app with SDK as base image
FROM microsoft/dotnet:2.2-sdk AS build-env # call the environment build
WORKDIR /build # create a work dir
COPY . . # you don't need copy everything to build your app, but this is for simplisity
RUN ls -al # linux command to list dir content
RUN cd /Customer && dotnet publish -o out # actually building the app and publishing to /out dir
RUN cd /Customer && ls -al # navigate to the folder you copied and list dir
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS runtime # step 2, runtime env (slimmed down container)
WORKDIR /app # create workdir
COPY --from=build-env /<YOUR_BULD_PATH>/out ./ # copy from prev container build output
RUN ls -al # list again
ENTRYPOINT ["dotnet", "Department.dll", "--urls", "http://*:6001"] # example from .NET Core 2.2 webapi with port 6005, this might not be your case
现在要运行docker-compose,只需像已经完成操作一样指出docker文件即可。但是docker / docker-compose现在应该都可以正常工作了。当然,您需要稍微调整docker文件,我不知道您的应用程序或文件夹结构。
还有一个提示,如果您想独立运行docker文件,启动它映射端口时不要忘记args-> -p 6001:80