Shell到Docker容器后如何编辑文件? [英] How do I edit a file after I shell to a Docker container?

查看:80
本文介绍了Shell到Docker容器后如何编辑文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下命令成功地炮击了Docker容器:

I successfully shelled to a Docker container using:

docker exec -i -t 69f1711a205e bash

现在我需要编辑文件,而且内部没有任何编辑器:

Now I need to edit file and I don't have any editors inside:

root@69f1711a205e:/# nano
bash: nano: command not found
root@69f1711a205e:/# pico
bash: pico: command not found
root@69f1711a205e:/# vi
bash: vi: command not found
root@69f1711a205e:/# vim
bash: vim: command not found
root@69f1711a205e:/# emacs
bash: emacs: command not found
root@69f1711a205e:/#

如何编辑文件?

推荐答案

与注释中一样,未设置默认编辑器-奇怪- $ EDITOR 环境变量为空。您可以使用以下命令登录到容器:

As in the comments, there's no default editor set - strange - the $EDITOR environment variable is empty. You can log in into a container with:

docker exec -it <container> bash

然后运行:

apt-get update
apt-get install vim

或者使用以下Dockerfile:

Or use the following Dockerfile:

FROM  confluent/postgres-bw:0.1

RUN ["apt-get", "update"]
RUN ["apt-get", "install", "-y", "vim"]

已将Docker映像修剪到最低限度-因此,随发货的容器未安装任何编辑器。这就是为什么需要手动安装它的原因。

Docker images are delivered trimmed to the bare minimum - so no editor is installed with the shipped container. That's why there's a need to install it manually.

编辑

我也鼓励您阅读有关该主题的帖子

I also encourage you read my post about the topic.

这篇关于Shell到Docker容器后如何编辑文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆