我正在尝试为'navi'命令创建一个容器,但是当我尝试使用Dockerfile ENTRYPOINT或CMD命令运行该容器时,它会失败。如果我使用bash shell(即CMD [“ bash”])启动容器,请运行“ navi”命令,效果很好。
请让我知道我在做什么错,或者如果依赖项不支持从容器运行。
FROM rust
RUN apt-get -y update \
&& apt-get -y install \
fzf \
&& cargo install navi \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ENV TERM=xterm-256color
ENTRYPOINT ["navi"]
这些是我用来构建和运行它的命令
docker build -t macabees/navi:latest navi/.
docker run -it --rm --name navi macabees/navi
这是我遇到的错误:
panic: runtime error: index out of range
goroutine 40 [running]:
github.com/junegunn/fzf/src.(*Terminal).printItem(0xc000106000, 0xc000155838, 0x0, 0x3, 0x1, 0x53fd00)
github.com/junegunn/fzf/src/terminal.go:827 +0x6b5
github.com/junegunn/fzf/src.(*Terminal).printList(0xc000106000)
github.com/junegunn/fzf/src/terminal.go:802 +0x254
github.com/junegunn/fzf/src.(*Terminal).Loop.func8.1(0xc00000cd60)
github.com/junegunn/fzf/src/terminal.go:1551 +0x1de
github.com/junegunn/fzf/src/util.(*EventBox).Wait(0xc00000cd60, 0xc0001acf98)
github.com/junegunn/fzf/src/util/eventbox.go:34 +0x5e
github.com/junegunn/fzf/src.(*Terminal).Loop.func8(0xc000106000, 0xc0001b00a0)
github.com/junegunn/fzf/src/terminal.go:1538 +0x97
created by github.com/junegunn/fzf/src.(*Terminal).Loop
github.com/junegunn/fzf/src/terminal.go:1534 +0x36f
thread 'main' panicked at 'External command failed:
', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/navi-2.2.0/src/fzf.rs:127:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
回溯输出
panic: runtime error: index out of range goroutine 26 [running]:
github.com/junegunn/fzf/src.(*Terminal).printItem(0xc000116000, 0xc000155838, 0x0, 0x3, 0x1, 0xffffffffffffff00) github.com/junegunn/fzf/src/terminal.go:827 +0x6b5 github.com/junegunn/fzf/src.(*Terminal).printList(0xc000116000) github.com/junegunn/fzf/src/terminal.go:802 +0x254 github.com/junegunn/fzf/src.(*Terminal).Loop.func8.1(0xc00000cd60)
github.com/junegunn/fzf/src/terminal.go:1551 +0x1de
github.com/junegunn/fzf/src/util.(*EventBox).Wait(0xc00000cd60, 0xc00003b798) github.com/junegunn/fzf/src/util/eventbox.go:34 +0x5e
github.com/junegunn/fzf/src.(*Terminal).Loop.func8(0xc000116000, 0xc0001940c0)
github.com/junegunn/fzf/src/terminal.go:1538 +0x97 created by github.com/junegunn/fzf/src.(*Terminal).Loop github.com/junegunn/fzf/src/terminal.go:1534 +0x36f thread 'main' panicked at 'External command failed:', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/navi-2.2.0/src/fzf.rs:127:13 stack backtrace:
0: backtrace::backtrace::libunwind::trace at ./cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
1: backtrace::backtrace::trace_unsynchronized at ./cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
2: std::sys_common::backtrace::_print_fmt at src/libstd/sys_common/backtrace.rs:77
3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt at src/libstd/sys_common/backtrace.rs:59
4: core::fmt::write at src/libcore/fmt/mod.rs:1052
5: std::io::Write::write_fmt at src/libstd/io/mod.rs:1426
6: std::sys_common::backtrace::_print at src/libstd/sys_common/backtrace.rs:62
7: std::sys_common::backtrace::print at src/libstd/sys_common/backtrace.rs:49
8: std::panicking::default_hook::{{closure}} at src/libstd/panicking.rs:204
9: std::panicking::default_hook at src/libstd/panicking.rs:224
10: std::panicking::rust_panic_with_hook at src/libstd/panicking.rs:472
11: rust_begin_unwind at src/libstd/panicking.rs:380
12: std::panicking::begin_panic_fmt at src/libstd/panicking.rs:334
13: navi::fzf::call
14: navi::flows::core::main
15: navi::handler::handle_config
16: navi::main
17: std::rt::lang_start::{{closure}}
18: std::rt::lang_start_internal::{{closure}} at src/libstd/rt.rs:52
19: std::panicking::try::do_call at src/libstd/panicking.rs:305
20: __rust_maybe_catch_panic at src/libpanic_unwind/lib.rs:86
21: std::panicking::try at src/libstd/panicking.rs:281
22: std::panic::catch_unwind at src/libstd/panic.rs:394
23: std::rt::lang_start_internal at src/libstd/rt.rs:51
24: main
25: __libc_start_main
26: _start
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
答案 0 :(得分:1)
我不太熟悉如何在内部编写navi,但是我发现当我重复运行命令docker run -it --rm --name navi macabees/navi
时,它将在大约20%的时间内起作用。
现在,这是对该命令的一些更改,这些更改将在100%的时间内起作用:
docker run -it --rm \
--name navi \
--entrypoint bash \
macabees/navi \
-c "sleep 1; navi"
我的猜测是,为了使navi
命令正常运行,首先需要运行或初始化某些进程,如果我们等待一会儿(1秒或更长时间),这些进程将在运行之前完成运行主要navi
命令正在执行。
要改善Dockerfile,可以创建一个shell脚本作为入口点,该脚本将在运行navi
之前等待1秒。