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 unbound.sh 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
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0b69f13af06e mvance/unbound-rpi:latest "/unbound.sh" 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, 0.0.0.0:80->80/tcp, :::80->80/tcp pihole
c4d21f03b89a ghcr.io/home-assistant/aarch64-hassio-dns:2021.06.0 "/init" About an hour ago Up About an hour hassio_dns
7f733857ea35 ghcr.io/home-assistant/aarch64-hassio-multicast:2021.04.0 "/init" 25 hours ago Up 25 hours hassio_multicast
aacc097ef9b2 ghcr.io/home-assistant/aarch64-hassio-cli:2021.08.1 "/init /bin/bash -c …" 25 hours ago Up 25 hours hassio_cli
0c6a08878863 ghcr.io/home-assistant/aarch64-hassio-audio:2021.07.0 "/init" 25 hours ago Up 25 hours hassio_audio
4b11bbe09822 portainer/portainer-ce:latest "/portainer" 2 days ago Up 25 hours 8000/tcp, 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp portainer
08bcc43e7f02 ghcr.io/home-assistant/raspberrypi4-64-homeassistant:2021.9.3 "/init" 2 days ago Up 25 hours homeassistant
76312a05c031 ghcr.io/home-assistant/aarch64-hassio-observer:2021.06.0 "/init" 2 days ago Up 25 hours 0.0.0.0:4357->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
root@2b0ae048c5a0:/opt/unbound#

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

Whispers: A Powerful Static Code Analysis Tool for Credential Detection

“My little birds are everywhere, even in the North, they whisper to me the strangest …

Enabling AMD GPU for Hashcat on Kali Linux: A Quick Guide

Enabling AMD GPU for Hashcat on Kali Linux: A Quick Guide

If you’ve encountered an issue where Hashcat initially only recognizes your CPU and not the …

Leave your solution or comment to help others.

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

Discover more from blackMORE Ops

Subscribe now to keep reading and get access to the full archive.

Continue reading

Privacy Policy on Cookies Usage

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