修复Docker中的Bash错误

I really enjoy working with Docker because it gives me more insight into creating and maintaining your own environments, mostly from scratch.  I instantly gained a greater appreciation for Ops engineers, package creators, and other engineers who work on low level software.  I think what I'm trying to say is that I've made a whole bunch of mistakes and completed an insane amount of Google searches for help.

我真的很喜欢与Docker合作,因为它使我对创建和维护自己的环境(主要是从头开始)有了更多的了解。 我立即对Ops工程师,程序包创建者和其他从事底层软件工作的工程师产生了更大的赞赏。 我想说的是,我犯了很多错误,并完成了疯狂的Google搜索以寻求帮助。

One of the more basic errors I've recently encountered was trying to run a bash script within the container, only to get the following error:  env: can't execute 'bash': No such file or directory.  I was under the impression that bash was always a given in Linux machines, but apparently not in alpine images.  The fix was adding the following to my Dockerfile file:

我最近遇到的最基本的错误之一是试图在容器中运行bash脚本,只是得到以下错误: env: can't execute 'bash': No such file or directory 。 我给人的印象是bash在Linux机器中总是被给定的,但显然不是在alpine图像中。 该修复程序将以下内容添加到我的Dockerfile文件中:


RUN apk update && apk add bash


Or if you're in the machine, just run:

或者,如果您在计算机中,请运行:


apk update && apk add bash


That command installs bash and your bash scripts should then work!

该命令将安装bash,然后您的bash脚本应该可以工作了!

翻译自: https://davidwalsh.name/docker-bash

出现"bash: docker: command not found"的错误提示时,表示系统无法找到docker命令。这可能是由于以下几个原因导致的: 1. Docker未正确安装:请确保已正确安装Docker,并且安装路径已正确配置。重新安装Docker可能会解决此问题。\[3\] 2. Docker命令不在系统的PATH环境变量:请检查系统的PATH环境变量,确保Docker命令所在的路径已正确添加到PATH。可以使用以下命令来查看PATH环境变量的值:`echo $PATH`。如果Docker命令所在的路径不在其,可以通过编辑`~/.bashrc`文件或者`/etc/profile`文件来添加路径。添加完成后,记得执行`source ~/.bashrc`或者`source /etc/profile`来使修改生效。 3. Docker服务未启动:请确保Docker服务已正确启动。可以使用以下命令来启动Docker服务:`systemctl start docker`。如果服务已经启动,可以尝试重启服务:`systemctl restart docker`。 4. Docker命令被删除或损坏:如果以上方法都无效,可能是由于Docker命令文件被删除或损坏导致的。可以尝试重新安装Docker修复此问题。\[3\] 总结起来,解决"bash: docker: command not found"错误的方法包括重新安装Docker、检查PATH环境变量、启动或重启Docker服务以及修复可能损坏的Docker命令文件。希望这些方法能够帮助您解决问题。 #### 引用[.reference_title] - *1* *2* *3* [一次bash: docker: command not found bash: yum: command not found的解决](https://blog.csdn.net/two_brother_/article/details/128826780)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值