如何重新创建 docker-compose?

如何重新创建 docker-compose?

我删除了一个 docker-compose 而不将其推送到 git...我知道我是个白痴。堆栈仍然存在,那么是否有办法重新创建 docker-compose ?我可以进行 docker 检查并查看我需要的所有位,即使用的卷、变量等,但如果有一些技巧可以以最小的努力恢复该组合,那就太好了。

谢谢,

答案1

首先,您需要获得等效的docker run命令,您可以使用此工具来执行此操作:https://github.com/nexdrew/rekcod

获得docker run命令后,您可以使用其他工具将其转换为 docker-compose 文件:https://composerize.com/

例如:

我有以下docker-compose文件:

version: '2'
services:
  logstash:
    image: docker.elastic.co/logstash/logstash:5.6.3
    ports:
      - 9600:9600
    volumes:
      - ./pipeline/logstash.conf:/usr/share/logstash/pipeline/logstash.conf
      - ./config/:/usr/share/logstash/config

我运行docker-compose up并最终得到以下容器:

$ docker ps

CONTAINER ID        IMAGE                                       COMMAND                  CREATED             STATUS              PORTS                              NAMES
5febb7edb627        docker.elastic.co/logstash/logstash:5.6.3   "/usr/local/bin/dock…"   2 minutes ago       Up 2 minutes        5044/tcp, 0.0.0.0:9600->9600/tcp   logstash563_logstash_1

然后,我docker run为底层容器生成等效命令:

$ rekcod 5febb7edb627

docker run --name logstash563_logstash_1 -v /workplace/mariodes/docker/logstash/logstash-5.6.3/pipeline/logstash.conf:/usr/share/logstash/pipeline/logstash.conf:rw -v /workplace/mariodes/docker/logstash/logstash-5.6.3/config:/usr/share/logstash/config:rw -p 9600:9600/tcp --net logstash563_default --restart no -h 2392ddc1cea7 --expose 5044/tcp --expose 9600/tcp -e 'PATH=/usr/share/logstash/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' -e 'ELASTIC_CONTAINER=true' -e 'LANG=en_US.UTF-8' -e 'LC_ALL=en_US.UTF-8' -d --entrypoint "/usr/local/bin/docker-entrypoint" docker.elastic.co/logstash/logstash:5.6.3

现在,复制 rekcod 的输出并将其用于https://composerize.com/将其转换为 docker-compose 文件:

version: 3
services:
    logstash:
        container_name: logstash563_logstash_1
        volumes:
            - '/workplace/mariodes/docker/logstash/logstash-5.6.3/pipeline/logstash.conf:/usr/share/logstash/pipeline/logstash.conf:rw'
            - '/workplace/mariodes/docker/logstash/logstash-5.6.3/config:/usr/share/logstash/config:rw'
        ports:
            - '9600:9600/tcp'
        restart: no
        expose:
            - 5044/tcp
            - 9600/tcp
        environment:
            - 'PATH=/usr/share/logstash/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
            - ELASTIC_CONTAINER=true
            - LANG=en_US.UTF-8
            - LC_ALL=en_US.UTF-8
        entrypoint:
            - /usr/local/bin/docker-entrypoint
        image: 'docker.elastic.co/logstash/logstash:5.6.3'

相关内容