lukaszlach / commando

:whale: Container registry which provides you all the commands you need in a lightweight Alpine image. DevOps and SysOps best friend. https://command-not-found.com
Other
539 stars 25 forks source link

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

Open the-hotmann opened 2 years ago

the-hotmann commented 2 years ago

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 commented 2 years ago

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.

lukaszlach commented 2 years ago

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.