commando icon indicating copy to clipboard operation
commando copied to clipboard

How to start persistent "tool" container with docker-compose?

Open the-hotmann opened this issue 2 years ago • 2 comments

I tried to set up a little tool-container with tools from cmd.cat to not having to install them on my host machine. But since I want to install and update them with docker-compose and keep the container running I set up my docker-compose file like this:

version: "3.8"
services:
  tools:
    image: cmd.cat/curl/wget
    container_name: tools
    volumes:
      - "/my_volume:/internal_volume"
    restart: unless-stopped

the command: docker-compose pull tools && docker-compose up -d runs through smooth, but then the container keeps on restarting and ends up in a restart loop:

docker exec -it tools /bin/bash
Error response from daemon: Container 4b4af273627611a793715af4c96d43xxxxxxxxxxxxxxxxxxxxxxxxx is restarting, wait until the container is running

Is there any good way, to run these cmd.cat tools in a persistent container so I don't have to start them with docker run -it everytime I want to use them? Thanks in advance!

the-hotmann avatar May 20 '22 10:05 the-hotmann

Found a workaround, so the container stays active and idles so you always have a ready container which you can access with:

docker exec -it tools /bin/bash

The workaround is, using the -d (detatched) parameter to start it, like this:

docker run --name tools -d -it cmd.cat/curl/wget

That gives the container the name tools and starts him in the background, so he does not terminate if you are not active in his terminal.

Sadly this is not a docker-compose way, but the old traditional docker way of starting things. Would be thankful for any hint how to do it with docker-compose, tried it already but nothing worked.

the-hotmann avatar May 22 '22 04:05 the-hotmann

The container has to be interactive, so -it has to be used when running docker run, same for docker-compose. The default command is always shell, so no need to change this one.

lukaszlach avatar Aug 08 '22 21:08 lukaszlach