简体   繁体   中英

How to edit files inside a docker container?

I cloned the docker-sinatra from Github ( https://github.com/tcnksm-sample/docker-sinatra ).

Built the image using:

sudo docker build -t sinatra .

Run the container:

sudo docker run -d -p 4567:4567 sinatra 

Everything works fine. Now I want to change the content of the application file inside the container. I tried to attach the container and open the application file with vi and edit it but it's kinda hectic and doesn't work.

Is there a better way to edit files inside the container or a better tool instead of vi that I can use inside the container?

Do you want to permanently change the contents of the app file? Then change it before you do the docker build.

I just installed nano in the docker container so I could use it instead of vi to change to application file.

vi is behaving weirdly when I tried to edit the application file inside the container I don't know if it just me.

The docker-sinatra docker container was built from a ubuntu base. Thus when inside the container, you can install vi/vim by issuing command

sudo apt-get install vi
sudo apt-get install vim

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM