How to install vim in docker container
Cause:
(Learning video sharing: Programming video)
Need to change some configuration files, but suddenly found that there is no Install vi command.
jenkins@jenkins-ci-jenkins-primary-1:/$ vimbash: vim: command not found
Now I go into the docker container and find that there is no vi or vim. So I wanted to install it
jenkins@jenkins-ci-jenkins-primary-1:/$ apt-get install viE: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?jenkins@jenkins-ci-jenkins-primary-1:/$
When I installed it, I found that I didn’t have root permissions, so I had to run to the host host to get root permissions
[root@rancher ~]# sudo docker exec -it -u root 8745541a21226a2a064219da9b55b04aa5c43ceed84195b8555531026a5f6f56 bashroot@jenkins-ci-jenkins-primary-1:/# root@jenkins-ci-jenkins-primary-1:/# root@jenkins-ci-jenkins-primary-1:/# apt-get installReading package lists... DoneBuilding dependency treeReading state information... Done0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.root@jenkins-ci-jenkins-primary-1:/# apt-get install viReading package lists... DoneBuilding dependency treeReading state information... DoneE: Unable to locate package vi
I found that I still couldn’t install it with root. The reason was: If the APT library has not been updated, then we can update it
apt-get updateapt-get upgrade
Execute the command as follows
root@jenkins-ci-jenkins-primary-1:/# apt-get updateGet:1 http://security.debian.org stretch/updates InRelease [94.3 kB]Ign:2 http://deb.debian.org/debian stretch InReleaseGet:3 http://deb.debian.org/debian stretch-updates InRelease [91.0 kB]Get:4 http://deb.debian.org/debian stretch Release [118 kB]Get:5 http://security.debian.org stretch/updates/main amd64 Packages [650 kB]Get:6 http://deb.debian.org/debian stretch-updates/main amd64 Packages [33.7 kB]Get:7 http://deb.debian.org/debian stretch Release.gpg [2410 B]Get:8 http://deb.debian.org/debian stretch/main amd64 Packages [9476 kB]Fetched 10.5 MB in 13min 51s (12.6 kB/s) Reading package lists... Doneroot@jenkins-ci-jenkins-primary-1:/# apt-get upgradeReading package lists... DoneBuilding dependency treeReading state information... DoneCalculating upgrade... DoneThe following packages will be upgraded: apt base-files bsdutils bzr ca-certificates ca-certificates-java curl dbus debian-archive-keyring dirmngr dpkg e2fslibs e2fsprogs gcc-6-base git git-man gnupg gnupg-agent gpgv iproute2 java-common libapparmor1 libapt-pkg5.0 libatk-wrapper-java libatk-wrapper-java-jni libblkid1 libc-bin libc6 libcomerr2 libcups2 libcurl3 libcurl3-gnutls libdbus-1-3 libexpat1 libfdisk1 libfreetype6 libgcc1 libgcrypt20 libgdk-pixbuf2.0-0 libgdk-pixbuf2.0-common libglib2.0-0 libglib2.0-data libgnutls30 libicu57 libidn11 liblcms2-2 libldap-2.4-2 libldap-common libmount1 libncurses5 libncursesw5 libnghttp2-14 libperl5.24 libpng16-16 libprocps6 libpython2.7-minimal libpython2.7-stdlib libsasl2-2 libsasl2-modules-db libserf-1-1 libsmartcols1 libsoup-gnome2.4-1 libsoup2.4-1 libsqlite3-0 libss2 libssh2-1 libssl1.0.2 libssl1.1 libstdc++6 libsvn1 libsystemd0 libtasn1-6 libtiff5 libtinfo5 libudev1 libuuid1 libvorbis0a libvorbisenc2 libwayland-client0 libwayland-cursor0 libwayland-server0 libx11-6 libx11-data libx11-dev libx11-doc libx11-xcb1 libxcursor1 libxkbcommon0 libxml2 mount multiarch-support ncurses-base ncurses-bin openjdk-8-jdk openjdk-8-jdk-headless openjdk-8-jre openjdk-8-jre-headless openssh-client openssl perl perl-base perl-modules-5.24 procps python-bzrlib python2.7 python2.7-minimal sensible-utils shared-mime-info subversion tzdata unzip util-linux wget113 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.Need to get 108 MB of archives.After this operation, 2933 kB of additional disk space will be used.Do you want to continue? [Y/n]
Install vi
root@jenkins-ci-jenkins-primary-1:/# apt-get install vimReading package lists... DoneBuilding dependency treeReading state information... DoneThe following additional packages will be installed: libgpm2 vim-common vim-runtime xxdSuggested packages: gpm ctags vim-doc vim-scriptsThe following NEW packages will be installed: libgpm2 vim vim-common vim-runtime xxd0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.Need to get 6769 kB of archives.After this operation, 31.2 MB of additional disk space will be used.Do you want to continue? [Y/n] yGet:1 http://deb.debian.org/debian stretch/main amd64 xxd amd64 2:8.0.0197-4+deb9u3 [132 kB]Get:2 http://deb.debian.org/debian stretch/main amd64 vim-common all 2:8.0.0197-4+deb9u3 [159 kB]Get:3 http://deb.debian.org/debian stretch/main amd64 libgpm2 amd64 1.20.4-6.2+b1 [34.2 kB]Get:4 http://deb.debian.org/debian stretch/main amd64 vim-runtime all 2:8.0.0197-4+deb9u3 [5409 kB]48% [4 vim-runtime 2717 kB/5409 kB 50%]
Test:
Vi 1.txt
Related recommendations: docker tutorial
The above is the detailed content of How to install vim in docker container. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use Docker Desktop? Docker Desktop is a tool for running Docker containers on local machines. The steps to use include: 1. Install Docker Desktop; 2. Start Docker Desktop; 3. Create Docker image (using Dockerfile); 4. Build Docker image (using docker build); 5. Run Docker container (using docker run).

To get the Docker version, you can perform the following steps: Run the Docker command "docker --version" to view the client and server versions. For Mac or Windows, you can also view version information through the Version tab of the Docker Desktop GUI or the About Docker Desktop menu.

Steps to create a Docker image: Write a Dockerfile that contains the build instructions. Build the image in the terminal, using the docker build command. Tag the image and assign names and tags using the docker tag command.

The steps to update a Docker image are as follows: Pull the latest image tag New image Delete the old image for a specific tag (optional) Restart the container (if needed)

Methods for copying files to external hosts in Docker: Use the docker cp command: Execute docker cp [Options] <Container Path> <Host Path>. Using data volumes: Create a directory on the host, and use the -v parameter to mount the directory into the container when creating the container to achieve bidirectional file synchronization.

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

You can switch to the domestic mirror source. The steps are as follows: 1. Edit the configuration file /etc/docker/daemon.json and add the mirror source address; 2. After saving and exiting, restart the Docker service sudo systemctl restart docker to improve the image download speed and stability.

To save the image in Docker, you can use the docker commit command to create a new image, containing the current state of the specified container, syntax: docker commit [Options] Container ID Image name. To save the image to the repository, you can use the docker push command, syntax: docker push image name [: tag]. To import saved images, you can use the docker pull command, syntax: docker pull image name [: tag].
