1

I deleted a docker-compose without pushing it to git...I know I'm an idiot. The stack is still up so is there anyway to recreate that docker-compose ? I can do a docker inspect and see all the bits I need i.e. volumes used, variables etc but if there's some trickery to get that compose back with minimal effort that would be great.

Thanks,

1 Answer 1

1

First, you will need to get the equivalent docker run command, you can use this tool to do it: https://github.com/nexdrew/rekcod.

After you have the docker run command, you can use this other tool to convert it to a docker-compose file: https://composerize.com/.

E.g.:

I have the following docker-compose file:

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

I run docker-compose up and end up with the following container:

$ 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

Then, I generate the docker run equivalent command for the underlying container:

$ 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

Now, copy the output from rekcod and use it on https://composerize.com/ to convert it to a docker-compose file:

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'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .