gpt4 book ai didi

docker - 如何在Docker Compose中为容器和图像命名?

转载 作者:行者123 更新时间:2023-12-02 21:09:39 25 4
gpt4 key购买 nike

我有一个简单的ASP.NET Core Web with SQL Server项目,名为PostOptimizer,由Visual Studio 2017创建并部署到Docker容器。我想给由Docker-compose创建的每个图像和容器命名,因为它会自动给出如下名称:
“dockercompose7669752967822022310_postoptimizer_1” “dockercompose7669752967822022310_sql.data_1”

即使在阅读了Docker Compose的Service configuration reference之后,我仍然不知道该怎么做,我希望它能够像 name:“thecontainername” 一样放置构建的子项,但是它不可用。怎么做?

这是我的 docker-compose.yml 文件的内容:

version: '3.4'

services:
sql.data:
image: microsoft/mssql-server-linux:2017-latest
environment:
- SA_PASSWORD=Sql_Password1
- ACCEPT_EULA=Y
ports:
- "5434:1433"

postoptimizer:
image: ${DOCKER_REGISTRY-}postoptimizer
build:
context: .
dockerfile: PostOptimizer/Dockerfile
depends_on:
- sql.data

这是Dockerfile之一:
FROM build AS publish
RUN dotnet publish PostOptimizer.csproj -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "PostOptimizer.dll"]

最佳答案

您可以使用子项container_name,它将使用您的给定名称命名容器。

version: '3.4'

services:
sql.data:
image: microsoft/mssql-server-linux:2017-latest
environment:
- SA_PASSWORD=Sql_Password1
- ACCEPT_EULA=Y
ports:
- "5434:1433"
container_name: sqldata

postoptimizer:
image: ${DOCKER_REGISTRY-}postoptimizer
build:
context: .
dockerfile: PostOptimizer/Dockerfile
depends_on:
- sql.data
container_name: postoptimizer

关于docker - 如何在Docker Compose中为容器和图像命名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55486926/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com