Edit a file in a Docker container

Source: Internet
Author: User

Edit a file in a Docker container

I hope that every time I install vi in a docker container, who will give me $1... I want a simpler way to edit files in a running docker container. First, try to avoid editing files, which violates the philosophy of the container (see the last section ).

But if you have a legitimate reason, let's teach you how to do it.

Why is Zedapp?

Most of the time I used vi or Atom, just a few months ago I accidentally found Zedapp, a self-use editor. It simplifies editing. For example, tabs is not used, and recognition loading during editing is reduced.

The good support for remote editing makes it stand out from the remote server, and it can even compile the github source directly.

Zedapp has version 1.0. If you like it, you can consider helping Zef Hemmel in gratipay. He bravely quit his work and devote himself to open-source projects.

Install Zedapp

You can use Zedapp as a chrome plug-in or an independent app. Download zedapp.org. We recommend that you use an independent version.

Install zedrem

You need zedrem for remote editing. It is a small program that provides services for Zedapp file editing. Zedrem is packaged in a docker image: sequenceiq/zedapp

Here is a script to help run the zed server locally and run the zed client: zed in the target container

Install the docker image and shell script:

Docker run -- rm \
-V/usr/local/bin:/target \
-V/usr/local/bin/docker:/usr/local/bin/docker \
-V/var/run/docker. sock:/var/run/docker. sock \
Sequenceiq/zedapp

In fact, there is only one single binary zedrem, which I use to distinguish between the zed server and the zed client when you use it or do not have the -- server option.

Now you can enable a zedrem session to edit the Zedapp file in the Docker container directory.

Enable zedrem session

Enable zedrem sessions in the container

Zed <container> <directory>

If the zedrem server is not enabled, it will enable the-start (Enabled) zedrem server, enable and copy the zedrem client in the selected container, and finally output the remote link of the zedrem session.

Guided Project List window: Command-Shift-O/Ctrl-Shift-O. Select Remote Folder, type a Remote link in the Zedrem URL input box, and click Open.

This is all. Have fun! The following section is intended to satisfy your curiosity.

Boot2docker help functions

Install zedrem this step may have detected that you are using Boot2docker and guided you to create a help function, in case you missed this step or for reference:

Zed () {boot2docker ssh "sudo zed $ @";}

The zed help script installed in Boot2docker requires this sentence, so you need the boot2docker ssh work zone.

After that, you can perform operations directly on the OSX system.

zed <container> <directory>

Local zedrem Server

When you want to use Zedapp for remote editing, two other components are required by default:

  • The zedrem server Zedapp obtains the file content, sends edit commands for the web service protocol, and maintains sessions with the zedrem client.

  • The zedrem client serves small programs for files in the specified path.

When using the zedrem client through the official server, all the editing commands and content must go through blobe:

Compared with docker, docker-based local servers are faster and safer:

 

Nsenter

You may be thinking about this step: copy zedrem into the iner (copy zedrem to the container ). How is it possible? Docker's cp command only supports the opposite direction: from the container to the local directory.

This is an open-source problem that will be fixed soon, but you can also use nesenter to solve the problem. Jér courier me Petazzoni provides a help Script: docker-enter wrapped nsenter. We can use docker-enter to copy files from the local to the container:

Cat local-file | docker-enter $ container sh-c 'cat>/zedrem'

By the way (by the way): docker exec has been merged into the main branch, and it will completely replace nsenter.

Never do this.

You do not need to do this in most cases. It is considered a bad practice to edit a file in a container instead of developing or debugging it.

Are you editing the nginx configuration file? Do not use nginx appliance of Jeff Lindsay.

If you really need to edit the file in the docker container, use the volume.

If you have enabled a container and the problematic file is not on the same volume, this method is quite useful.

Install Docker in CentOS 6/7 Series

Detailed explanation of the entire process of building Gitlab CI for Docker

Docker installation application (CentOS 6.5_x64)

What is the difference between Docker and a normal Virtual Machine?

Use MySQL in Docker

Docker will change everything

Docker installation application (CentOS 6.5_x64)

Docker details: click here
Docker: click here

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.