gpt4 book ai didi

docker - docker-compose up -d --build “$@”使用错误的名称构建镜像

转载 作者:行者123 更新时间:2023-12-02 19:27:00 25 4
gpt4 key购买 nike

docker-compose up -d --build“$ @”用错误的名字建立镜像

我想用以下名称构建Docker镜像:

denpal_cli:latest
denpal_php:latest
denpal_nginx:latest

不幸的是, docker 图像会产生以下结果:
workspace_php:latest
workspace_nginx:latest
denpal:latest

这样,我就不能使用它们的专有名称将它们推送到Docker pub,或者我不得不做一个hackey:
docker tag denpal:latest denpal_cli:latest
docker tag workspace_php:latest denpal_php:latest
docker tag workspace_nginx:latest denpal_nginx:latest

Docker ps将其显示为结果:
workspace_cli_1       /sbin/tini -- /lagoon/entr ...   Up      9000/tcp
workspace_mariadb_1 /sbin/tini -- /lagoon/entr ... Up 0.0.0.0:32768->3306/tcp
workspace_nginx_1 /sbin/tini -- /lagoon/entr ... Up 8080/tcp
workspace_php_1 /sbin/tini -- /lagoon/entr ... Up 9000/tcp
workspace_redis_1 /sbin/tini -- /lagoon/entr ... Up 6379/tcp
workspace_solr_1 /sbin/tini -- /lagoon/entr ... Up 0.0.0.0:32769->8983/tcp
workspace_varnish_1 /sbin/tini -- /lagoon/entr ... Up 8080/tcp

这是docker-compose文件:
version: '2.3'

x-test-project:
# Project name (leave `&test-project` when you edit this)
&test-project denpal

x-volumes:
&default-volumes
# Define all volumes you would like to have real-time mounted into the docker containers
volumes:
- .:/app:delegated

x-environment:
&default-environment
TEST_PROJECT: *test-project

x-user:
&default-user
# The default user under which the containers should run. Change this if you are on linux and run with another user than id `1000`
user: '1000'

services:

cli: # cli container, will be used for executing composer and any local commands (drush, drupal, etc.)
build:
context: .
dockerfile: Dockerfile.cli
image: *test-project # this image will be reused as `CLI_IMAGE` in subsequent Docker builds
<< : *default-volumes # loads the defined volumes from the top
user: root
environment:
<< : *default-environment # loads the defined environment variables from the top

nginx:
build:
context: .
dockerfile: Dockerfile.nginx
args:
CLI_IMAGE: *test-project # Inject the name of the cli image
<< : *default-volumes # loads the defined volumes from the top
<< : *default-user # uses the defined user from top
depends_on:
- cli # basically just tells docker-compose to build the cli first
networks:
- test-network
- default

php:
build:
context: .
dockerfile: Dockerfile.php
args:
CLI_IMAGE: *test-project
<< : *default-volumes # loads the defined volumes from the top
<< : *default-user # uses the defined user from top
depends_on:
- cli # basically just tells docker-compose to build the cli first
environment:
<< : *default-environment # loads the defined environment variables from the top


mariadb:
image: mariadb-drupal
ports:
- "3306" # exposes the port 3306 with a random local port, find it with `docker-compose port mariadb 3306`
<< : *default-user # uses the defined user from top
environment:
<< : *default-environment

redis:
image: redis
<< : *default-user # uses the defined user from top
environment:
<< : *default-environment

solr:
image: solr:6.6-drupal
<< : *default-user # uses the defined user from top
ports:
- "8983" # exposes the port 8983 with a random local port, find it with `docker-compose port solr 8983`
environment:
<< : *default-environment


varnish:
image: varnish-drupal
links:
- nginx # links varnish to the nginx in this docker-compose project, or it would try to connect to any nginx running in docker
<< : *default-user # uses the defined user from top
environment:
<< : *default-environment
VARNISH_BYPASS: "true" # by default we bypass varnish, change to 'false' or remove in order to tell varnish to cache if possible
networks:
- test-network
- default

networks:
test-network:
external: true

工作区是构建所在的Jenkins目录的名称。

我还希望这些容器以denpal_cli_1,denpal_mariadb_1等名称联机。

这可能吗?

最佳答案

默认情况下,compose会将当前目录名称用作“项目名称”,并将为所有图像/服务/卷/网络/等添加前缀。那个名字。您可以使用-p选项或通过设置COMPOSE_PROJECT_NAME环境变量来set a project name explicitly。因此,对于您的用例,可以将COMPOSE_PROJECT_NAME设置为denali

关于docker - docker-compose up -d --build “$@”使用错误的名称构建镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55455425/

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