finch icon indicating copy to clipboard operation
finch copied to clipboard

`finch compose run [ARGS...]` is not working with specific command

Open HirokiTomisawa opened this issue 2 years ago • 3 comments

Describe the bug trying to use finch compose run as docker-compose run, but not working.

finch compose run --remove-orphans web rails new . -d mysql --force --skip-test --javascript=importmap
FATA[0000] unknown flag: --force
FATA[0000] exit status 1

finch compose run db ls -d
FATA[0000] currently flag -i and -d cannot be specified together (FIXME)
FATA[0000] exit status 1

seems like finch does not pass the command to the container, but interprets it as a finch command.

Steps to reproduce

Dockerfile

FROM ruby:3.1.0

ENV APP_PATH /myapp

WORKDIR $APP_PATH

COPY Gemfile $APP_PATH/Gemfile
COPY Gemfile.lock $APP_PATH/Gemfile.lock

RUN bundle install

COPY . $APP_PATH

COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000

CMD ["rails", "server", "-b", "0.0.0.0"]

entrypoint.sh

#!/bin/bash
set -e

# Remove a potentially pre-existing server.pid for Rails.
rm -f /myapp/tmp/pids/server.pid

# Then exec the container's main process (what's set as CMD in the Dockerfile).
exec "$@"

docker-compose.yml

version: "3.7"

services:
  db:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: password
    ports:
      - '3306:3306'
    volumes:
      - mysql-data:/var/lib/mysql

  web:
    build:
      context: .
      dockerfile: Dockerfile
    command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
    ports:
      - "3000:3000"
    volumes:
      - .:/myapp
    environment:
      RAILS_ENV: development
    depends_on:
      - db
volumes:
  mysql-data:
touch Gemfile.lock
finch compose build
finch compose run --remove-orphans web rails new . -d mysql --force --skip-test --javascript=importmap

# Success without options
finch compose run --remove-orphans web rails new .

Expected behavior working like docker-compose

HirokiTomisawa avatar Dec 04 '22 00:12 HirokiTomisawa

This behavior is from containerd/nerdctl because finch uses it internally. And containerd/nerdctl uses spf13/cobra that is not accepted extra arguments with hyphens. If you want to run the command anyway, you can run it by inserting -- before service, like the following command.

finch compose run --remove-orphans -- web rails new . -d mysql --force --skip-test --javascript=importmap

sawadashota avatar Dec 04 '22 09:12 sawadashota

Thanks for the response @sawadashota. That is correct.

@HirokiTomisawa, Here is couple of issues where it was suggested to use -- for a workaround (as @sawadashota mentioned). https://github.com/spf13/cobra/issues/739 https://github.com/spf13/cobra/issues/1025

monirul avatar Dec 05 '22 18:12 monirul

This issue should be fixed now in nerdctl.

https://github.com/containerd/nerdctl/issues/1666

djdongjin avatar Dec 21 '22 16:12 djdongjin