How to edit files inside Docker container?

Just migrating everything to bunch of new RaspberryPi 4 8GB from my VMware farm. Instead of using multiple Raspberry Pi 4, I decided to use Docker and move as many I can into each one of these. I’ve think Home Assistant (with supervisor), Pi-Hole, Pi-VPN, UnBound and my NoIP2 scripts one Raspberry Pi4 8GB Pi running Debian 11 BullsEye and docker and Plex Server onto another Pi should do the trick. Anyhow, ran into an interesting problem with Undound where I needed to edit the configuration file nano application.yaml or vi and it said, nano or vi wasn’t installed. How to fix permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: error

bash: vi: command not found

Asked my best buddy Google and DuckDuckGo and and quickly found the solution.

Apparently, Docker has a principle of keeping the things lightweight so that developers can easily ship the containers to any environment. But you can install packages manually.

So let’s find the name of the docket container I want to login:

root@bullspie4:~# docker ps -a
0b69f13af06e mvance/unbound-rpi:latest "/" 5 minutes ago Up 3 minutes (healthy) 53/tcp, 53/udp unbound-rpi
d147941539a5 pihole/pihole:latest "/s6-init" 55 minutes ago Up 55 minutes (healthy) 53/udp, 53/tcp, 67/udp,>80/tcp, :::80->80/tcp pihole
c4d21f03b89a "/init" About an hour ago Up About an hour hassio_dns
7f733857ea35 "/init" 25 hours ago Up 25 hours hassio_multicast
aacc097ef9b2 "/init /bin/bash -c …" 25 hours ago Up 25 hours hassio_cli
0c6a08878863 "/init" 25 hours ago Up 25 hours hassio_audio
4b11bbe09822 portainer/portainer-ce:latest "/portainer" 2 days ago Up 25 hours 8000/tcp,>9000/tcp, :::9000->9000/tcp portainer
08bcc43e7f02 "/init" 2 days ago Up 25 hours homeassistant
76312a05c031 "/init" 2 days ago Up 25 hours>80/tcp, :::4357->80/tcp hassio_observer
fbb7862b1695 homeassistant/aarch64-hassio-supervisor "/init" 2 days ago Up 25 hours hassio_supervisor

Now let’s login as root user (If you do not put the -u 0 flag inside your docker container then you will be logged as appuser and you will not have root privileges and you will not be able to install any new utility inside your docker container.

root@bullspie4:~# docker exec -u 0 -it unbound-rpi bash

Now rest of it easy, I used apt to install packages, you just replace it with your packager manager’s name like yum, pacman and such.

root@2b0ae048c5a0:/opt/unbound# apt update && apt install nano -y
Reading package lists... Done
Building dependency tree
Reading state information... Done

And now I can edit using nano

root@2b0ae048c5a0:/opt/unbound# nano application.yaml

That’s it.

Check Also

Windows 11 BSOD - blackMORE Ops - 2

Best ways to destroy Microsoft Windows

I take no responsibility for these collection of best ways to destroy Microsoft Windows!

How to unhide menu bar in Virtualbox - blackMORE Ops - 2

How to unhide menu bar in Virtualbox

So I went in and hid the top menu bar and bottom status bar in Virtualbox. After they disappeared, now I cannot find out how to unhide those. Took me a little bit time to figure out, hence this post so that I don't forget it and someone else having the same to unhide menu bar in Virtualbox can find this.

Use, Twitter, Facebook, or Google+ accounts to comment (anonymous comments allowed)

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Privacy Policy on Cookies Usage

Some services used in this site uses cookies to tailor user experience or to show ads.