10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

dockerでbad interpreter: Text file busyが出るときの対処法

Last updated at Posted at 2015-07-10

(下部に追記あり)

問題

DockerのDockerfileの中でRUNコマンドを使ってシェルスクリプトを実行しようとするとbad interpreter: Text file busyが表示されることがある。

  • Dockerfileの一部
# Installing Xymon
ADD ./xymon-4.3.21.tar.gz /usr/local/src/
WORKDIR /usr/local/src/xymon-4.3.21
RUN /bin/bash configure --server #ここで落ちる
RUN make
RUN make install
  • 実行結果
configure: /usr/local/src/xymon-4.3.21/configure.server: /bin/sh: bad interpreter: Text file busy
configure: line 21: /usr/local/src/xymon-4.3.21/configure.server: Success
The command '/bin/sh -c /bin/bash configure --server' returned a non-zero code: 1

原因

ググると色々な原因があるみたいだけど、私の場合はファイルに実行権限を与えたのが良くなかったみたい。

対策

RUN chmod 755 sample.sh
RUN ./sample.sh

等でファイルに実行権限を与えた後はsyncコマンドを実行することでエラーを回避できる事がある。

RUN chmod 755 sample.sh
RUN sync #追加
RUN ./sample.sh

今回の場合はXymonのconfigureスクリプトの中で実行権限を変更していたのが原因。

#!/bin/sh

# Configuration script for Xymon.
# $Id: configure 7474 2014-09-28 09:39:28Z storner $

BASEDIR="`dirname $0`"
TARGET="$1"
if test "$TARGET" != ""; then shift; fi

# Make sure that all shell-scripts are executable.
# Subversion has a habit of exporting without the
# execute-bit set.
chmod 755 $BASEDIR/configure* $BASEDIR/build/*.sh $BASEDIR/client/*.sh #コレが原因

case "$TARGET" in
  "--client")
        exec $BASEDIR/configure.client $*
        ;;
(略)

こういう場合はsedでシェルスクリプトを書き換えてしまおう。

# Installing Xymon
ADD ./xymon-4.3.21.tar.gz /usr/local/src/
WORKDIR /usr/local/src/xymon-4.3.21
RUN sed -i -e '/^chmod 755/a sync' configure #chmod 755の後の行にsyncを挿入
RUN /bin/bash configure --server
RUN make
RUN make install

configureスクリプトは次のように書き換わるはず。

#!/bin/sh

# Configuration script for Xymon.
# $Id: configure 7474 2014-09-28 09:39:28Z storner $

BASEDIR="`dirname $0`"
TARGET="$1"
if test "$TARGET" != ""; then shift; fi

# Make sure that all shell-scripts are executable.
# Subversion has a habit of exporting without the
# execute-bit set.
chmod 755 $BASEDIR/configure* $BASEDIR/build/*.sh $BASEDIR/client/*.sh
sync

case "$TARGET" in
  "--client")
        exec $BASEDIR/configure.client $*
        ;;
(略)

これでうまく動作しました。

参考リンク

追記

DockerのStorage Driverがaufsの時に発生する現象のようです。devicemapper等に変更しましょう。

Docker Machineを使ってVirtualBoxに仮想マシンを作る時の例

$ docker-machine create --driver virtualbox --engine-storage-driver devicemapper develop
10
8
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?