在 bash 脚本中运行 docker 命令会导致分段错误

Running docker commands in bash script leads to segmentation fault

提问人:silencej 提问时间:3/1/2017 最后编辑:silencej 更新时间:3/2/2017 访问量:1174

问:

这些命令如下:

docker run / stop / rm ...

这在终端中起作用,同时导致 bash 脚本中的分段错误。

我比较了 bash 脚本和终端之间的环境,如下所示。

    2c2
    < BASHOPTS=cmdhist:complete_fullquote:extquote:force_fignore:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
    ---
    > BASHOPTS=cmdhist:complete_fullquote:expand_aliases:extquote:force_fignore:hostcomplete:interactive_comments:login_shell:progcomp:promptvars:sourcepath
    7,8c7,8
    < BASH_LINENO=([0]="0")
    < BASH_SOURCE=([0]="./devRun.sh")
    ---
    > BASH_LINENO=()
    > BASH_SOURCE=()
    10a11
    > COLUMNS=180
    14a16,18
    > HISTFILE=/home/me/.bash_history
    > HISTFILESIZE=500
    > HISTSIZE=500
    19a24
    > LINES=49
    22a28
    > MAILCHECK=60
    28c34,37
    < PPID=12558
    ---
    > PIPESTATUS=([0]="0")
    > PPID=12553
    > PS1='[\u@\h \W]\$ '
    > PS2='> '
    32,33c41,42
    < SHELLOPTS=braceexpand:hashall:interactive-comments
    < SHLVL=2
    ---
    > SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
    > SHLVL=1
    42,52c51
    < _=./devRun.sh
    < dao () 
    < { 
    <     echo "Dao";
    <     docker run -dti -v /tmp/projStatic:/var/projStatic -v ${PWD}:/home --restart always -p 50000:50000 --name projDev daocloud.io/silencej/python3-uwsgi-alpine-docker sh;
    <     echo "Dao ends."
    < }
    < docker () 
    < { 
    <     docker run -dti -v ${PWD}:/home --restart always -p 50000:50000 --name projDev owen263/python3-uwsgi-alpine-docker sh
    < }
    ---
    > _=/tmp/env.log

更新:

信息和版本:

docker version

Client:
 Version:      1.13.1
 API version:  1.26
 Go version:   go1.7.5
 Git commit:   092cba3727
 Built:        Sun Feb 12 02:40:56 2017
 OS/Arch:      linux/amd64
Server:
 Version:      1.13.1
 API version:  1.26 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   092cba3727
 Built:        Sun Feb 12 02:40:56 2017
 OS/Arch:      linux/amd64
 Experimental: false
docker info

Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 1
Server Version: 1.13.1
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: aa8187dbd3b7ad67d
bash docker 分段错误

评论

0赞 user2915097 3/1/2017
您使用哪个 Docker 映像?“图像描述”不存在,顺便说一句,添加和docker versiondocker info

答:

2赞 BMitch 3/2/2017 #1

你已经在 shell 中重写了 docker 命令,这完全有可能甚至是一个递归定义。从您的环境中删除此内容:

docker () 
{ 
    docker run -dti -v ${PWD}:/home --restart always -p 50000:50000 --name projDev owen263/python3-uwsgi-alpine-docker sh
}

评论

1赞 silencej 3/2/2017
哇,非常感谢。@BMitch我太关心 Docker。并且还试图找到倾倒的核心。从没想过是因为bash函数名称。