docker compose up-d--build“$@&引用;使用错误的名称构建图像

docker compose up-d--build“$@&引用;使用错误的名称构建图像,docker,docker-compose,Docker,Docker Compose,docker compose up-d--使用错误的名称构建“$@”建筑图像 我想用以下名称构建Docker映像: denpal_cli:latest denpal_php:latest denpal_nginx:latest 不幸的是,docker images产生了以下结果: workspace_php:latest workspace_nginx:latest denpal:latest 这样我就不能用他们的专有名称把他们推到Docker酒吧,否则我就得做一个黑客: docker ta

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

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

denpal_cli:latest
denpal_php:latest
denpal_nginx:latest
不幸的是,docker images产生了以下结果:

workspace_php:latest
workspace_nginx:latest
denpal:latest
这样我就不能用他们的专有名称把他们推到Docker酒吧,否则我就得做一个黑客:

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
版本:“2.3”
x-test-project:
#项目名称(编辑此项目时保留`&test Project`)
&测试项目denpal
x卷:
&默认卷
#定义要实时装入docker容器的所有卷
卷数:
-.:/app:委派
x环境:
&默认环境
测试项目:*测试项目
x用户:
&默认用户
#容器应在其下运行的默认用户。如果您在linux上,并且使用id`1000以外的其他用户运行,请更改此选项`
用户:“1000”
服务:
cli:#cli容器,将用于执行composer和任何本地命令(drush、drupal等)
建造:
上下文:。
dockerfile:dockerfile.cli
图像:*测试项目#此图像将在后续Docker构建中作为“CLI_图像”重用

要生成带有特定前缀的图像,您应该在
image
上指定它

要随意命名容器,请使用
container\u name
配置

例如,您希望容器的名称类似于apache,但映像名为httpd:

version: '3'

services:
  apache:
    image: apache_2.4:latest (my custom tag)
    container_name: my-apache
    build:
      context: my_dockerfile_folder/
      dockerfile: Dockerfile-apache (The dockerfile which will build from httpd:2.4)
[...]
结果:

图片:apache_2.4:最新版本


容器名称:my apache

默认情况下,compose将使用当前目录名称作为“项目名称”,并将所有图像/服务/卷/网络等以该名称作为前缀。您可以使用
-p
选项,或通过设置
COMPOSE\u PROJECT\u NAME
环境变量。因此,对于您的用例,您可以将
COMPOSE\u PROJECT\u NAME
设置为
denali

您是否尝试为每个服务使用“container\u NAME”?这将强制docker使用指定的名称,如果该名称已存在,则将失败。