Docker-compose标记和推送 [英] Docker-compose tagging and pushing

查看:294
本文介绍了Docker-compose标记和推送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些Docker容器,我尝试与 docker-compose 同步(当前正在由bash脚本运行)。我正在寻找一种标记并将其推送到基于ec2的dockerhub(专用服务器)的方法。

I have a few docker containers that I try to sync with docker-compose (currently are being run by bash scripts). I'm looking for a way to tag and push them to our ec2 based dockerhub (private server).

仅使用 docker (对于每个容器),我们做了这样的事情:

Using simply docker we did something like this (for each container):

$ docker build -f someDockerfile -t some
$ docker tag some <docker_hub_server>/some
$ docker push <docker_hub_server>/some

我正在尝试在 docker-compose 中复制它。我尝试了一些方法,但是这一方法似乎很有效(但是当然没有用):

I'm trying to replicate this in docker-compose. I tried a few things but this one seems close to working (but didn't work of course):


docker-compose.yml:

docker-compose.yml:



version: '3'
services:
  some:
    container_name:some
    image: some:<docker_hub_server>/some

但是当我运行时:

$ docker-compose push

我得到:

Pushing some (base:<docker_hub_server>/base:latest)...
ERROR: invalid reference format

关于如何处理的任何想法标记并推送我的容器?

Any ideas on how I can tag and push my containers?

ps:我知道这不是 docker-compose 的意思。

p.s.: I know that this is not the way docker-compose is meant to be used, but I also know it's possible and it fits my needs.

推荐答案

我已经在Docker Hub上测试了这种方法,您应该可以通过以下配置和shell来实现所需的功能ession:

I have tested this approach with Docker Hub, so you should be able to achieve what you want with the following configuration and shell session:


docker-compose.yml

docker-compose.yml



version: '3'
services:
  build-1:
    build:
      context: ./build-1
    image: user/project-1
  build-2:
    build:
      context: ./build-2
    image: user/project-2

(在这里,您应将 user / project-1 替换为 registry.name/user/project-1 (如果您未使用Docker Hub,而是另一个Docker注册表,例如, quay.io/user/project-1 。)

(Here, you should replace user/project-1 with registry.name/user/project-1 if you are not using Docker Hub but another Docker registry, e.g., quay.io/user/project-1.)

此处涉及的各个字段( build:上下文:等)在此泊坞窗的页面中进行了描述-撰写文档

The various fields involved here (build:, context:, etc.) are described in this page of the docker-compose documentation.

上面的 docker-compose.yml 文件假定您具有以下树(包括 .gitignore 和d某些 .dockerignore 文件,以符合最佳做法):

The docker-compose.yml file above assume you have the following tree (including a .gitignore and some .dockerignore files, to comply with best practices):

.
├── build-1
│   ├── Dockerfile
│   └── .dockerignore
├── build-2
│   ├── Dockerfile
│   └── .dockerignore
├── docker-compose.yml
└── .gitignore

然后在终端上执行:

$ docker login
  # → append the domain name of your Docker registry
  #   if you are not using Docker Hub; for example:
  # docker login quay.io
$ docker-compose build --pull
$ docker-compose push
  # and optionally:
$ docker logout

最后,以下是一些注释,以澄清与您的问题有关的一些细节:

Finally, below are some remarks to clarify a few details related to your question:


  • 在您的示例会话中

  • In your example session

$ docker build -f someDockerfile -t some .  # with "." as context build path
$ docker tag some …/some
$ docker push …/some

some 是一个临时映像名称(不是容器),因此似乎没有必要:您也可以运行以下命令,并得到相同的结果。

some is a temporary image name (not a container) so it seems unnecessary: you could just as well have run the following, with the same outcome.

$ docker build -f someDockerfile -t …/some .
$ docker push …/some


  • 您的 docker -compose.yml 示例包含以下行:

    image: some:<docker_hub_server>/some
    

    实际上,图像标签可以包含指定一个版本,但不能以这种方式指定(应该是后缀)。例如,您可以标记图像 user / some:1.0 user / some:latest ,按照惯例,后一个示例 user / some:latest 承认 user / some 是一个较短的等效名称。

    Actually, the image tags can contain : to specify a version, but not in this way (it should be a suffix). For example, you could tag an image user/some:1.0 or user/some:latest, and by convention this latter example user/some:latest admits user/some as a shorter, equivalent name.

    请注意,图像标签的完整语法为

    Note that the full syntax for image tags is

    registry.name:port/user/project:version
    

    其中 registry.name 应该是所需Docker注册表的域名或主机名(如果省略,它将默认为Docker Hub)。

    where registry.name should be the domain name or hostname of the desired Docker registry (if omitted, it will default to Docker Hub).

    该官方文档的页面

    因此,例如,如果您使用Quay Docker注册表,则图像标签可能是 quay.io/user/some:latest 或更简洁地 quay.io/user/some

    So for example, if you use the Quay Docker registry, the image tag could be quay.io/user/some:latest or more succinctly quay.io/user/some.

    这篇关于Docker-compose标记和推送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆