简体   繁体   English

如何在 docker-compose 文件中将 url 作为图像名称

[英]How to have a url as image name in a docker-compose file

I'm trying to write a docker-compose file that will build and push a versioned (1.0, 1.1...) and latest build of my image to my local v2 docker registry.我正在尝试编写一个 docker-compose 文件,该文件将构建并将我的映像的版本(1.0、1.1 ...)和最新版本推送到我的本地 v2 docker 注册表。 However when I run docker-compose build I get the following error:但是,当我运行docker-compose build ,出现以下错误:

ERROR: Couldn't connect to Docker daemon - you might need to run `docker-machine start default`.

I found a lot of people complaining about this error for many different reasons, in my case it has nothing to do with permissions or weather or not the docker service is running, I narrowed it down to my image naming having a URL on it (the URL of my local registry), I know that because if I name my image normally (like '/app:latest'), then the commands runs fine.我发现很多人出于许多不同的原因抱怨此错误,在我的情况下,它与权限或天气无关,或者 docker 服务是否正在运行,我将其范围缩小到我的图像命名上有一个 URL(我的本地注册表的 URL),我知道这是因为如果我正常命名我的图像(如“/app:latest”),那么命令运行良好。 So how can I have a URL as the image name?那么如何将 URL 作为图像名称呢?

Here is what I'm trying to do (docker-compose.yaml):这是我想要做的(docker-compose.yaml):

version: "3.8"

x-marvin-backend: &default-marvin-backend
  container_name: marvin_backend
  build: ./marvin-api
  image: "http://my_registry_url:5000/marvin/backend:latest"
  ports:
    - "3000:3000"
  networks:
    - backend

x-marvin-frontend: &default-marvin-frontend
  container_name: marvin_frontend
  image: http://my_registry_url:5000/marvin/frontend:latest
  build:
    context: ./marvin-front
    args:
      - REACT_APP_SERVICES_HOST=http://marvin_backend:3000/
  ports:
    - "80:80"
  networks:
    - backend
  depends_on:
    - backend

services:
  backend: *default-marvin-backend

  backend_versioned:
      << : *default-marvin-backend
      image: http://my_registry_url:5000/marvin/backend:1.0

  frontend: *default-marvin-frontend

  frontend_versioned:
      << : *default-marvin-frontend
      image: http://my_registry_url:5000/marvin/frontend:1.0

networks:
  backend:

I'm new to docker in general, my main goal here is to have a simple, preferably one command (eg docker-compose build ), that will build and tag both my front end and back end images so that I can just execute docker-compose push to push those newly created images to my registry running on AWS.我一般是 docker 新手,我的主要目标是有一个简单的,最好是一个命令(例如docker-compose build ),它将构建和标记我的前端和后端图像,以便我可以执行docker-compose push将这些新创建的图像推送到我在 AWS 上运行的注册表。 With that I also want to be able to override the latest version of those images in the registry while also adding a versioned image for backup purposes, in case I want to revisit any of those version in the future.有了这个,我还希望能够覆盖注册表中这些图像的最新版本,同时还添加一个版本化的图像以进行备份,以防将来我想重新访问这些版本中的任何一个。

Then in the AWS EC2 machine I have another docker-compose.yaml file that just fetches the latest versions of both images and run their containers.然后在 AWS EC2 机器中,我有另一个docker-compose.yaml文件, docker-compose.yaml获取两个图像的最新版本并运行它们的容器。

So to summarize I would develop the application on my local machine, then add the new version manually to the versioned services in the local docker-compose.yaml file, then run docker-compose build followed by docker-compose push ;总而言之,我将在我的本地机器上开发应用程序,然后手动将新版本添加到本地docker-compose.yaml文件中的版本化服务,然后运行docker-compose.yaml docker-compose build然后运行docker-compose.yaml docker-compose push then ssh into my AWS machine and run docker-compose up to fetch the latest and newly updated images and run them.然后 ssh 进入我的 AWS 机器并运行docker-compose up以获取最新和新更新的图像并运行它们。

This could later evolve into a CI/CD pipeline, but right now I'm taking baby steps and trying to get my image name to have a URL in it.这以后可能会演变成 CI/CD 管道,但现在我正在采取一些小步骤,并试图让我的图像名称在其中包含一个 URL。

Thank you.谢谢你。

Edit编辑

I tried using a .env with REGISTRY=http://my_registry_url:5000/marvin and then using image: "${REGISTRY}/frontend:latest" or image: "$${REGISTRY}/frontend:latest" but that also didn't work我尝试将.envREGISTRY=http://my_registry_url:5000/marvin使用,然后使用image: "${REGISTRY}/frontend:latest"image: "$${REGISTRY}/frontend:latest"但这也是没用

只需从图像中删除http://部分即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM