Docker Community Forums

Share and learn in the Docker community.

Edit text file inside docker


(Lucacasa) #1

Hi everybody!
I am very new to docker, as a matter of fact I stumbled upon it because I am using openFOAM for mac.
I am having some troubles editing text file inside of the docker, which is an action I need to perform pretty often when working with openFOAM.
I usually start openFOAM, which I suppose works inside a docker container. Once I do, I log in as “ofuser…” and I can navigate through my files in Mac. The problem is that when I try to use nano to edit files i receive a:

bash: nano: command not found

I tried to do a “apt-get install nano” but i get this instead:

bash: apt-get: command not found

I also tried to use the “cat” function, but it’s not really what I am looking for.
At the moment I’m using two different terminal windows, one logged in the docker the other as mac user. The problem is that this way I have to navigate to the folders twice, which slows down the process considerably.

Is there a way to install nano (or any other text editor) inside the docker?
Thanks :slight_smile:

(Sam) #2

i installed the openFoam image, see

and nano is available without problem.

the mac instructions load the same ubuntu based image

(Lucacasa) #3

I followed the instructions from the official open foam page, not the foundation.
I’ll try your solution right away and i’ll let you know.
Thanks :slight_smile:

(Sam) #4

i searched dockerhub for images, and not knowing anything, I picked one… that sent me to the link I posted

(Don McCullough) #5

Have you tried this command
cat /etc/*-release
may not be Ubuntu base image,

many new application containers have switched to Alpine Linux their package management tool is apk install …

also vi or vim are probably there…

(Lucacasa) #6

now I have nano, but apparently I have lost access to my home folder, which is kind of a bummer. Somtimes navigating through many folders through terminal is a bit painful (to me) and i’d rather do that via finder. Also it happens at times that I might just wanna have a look at a file without having to go into the container through terminal…
Do you know of a way to use your home folder inside the container?

(Sam) #7

what do you mean home folder?

the docker HOST file system is hidden from the container, unless some part of it is mounted as a container volume.

(Lucacasa) #8

if i insert that command this is what i get:

CentOS Linux release 7.3.1611 (Core)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID_LIKE="rhel fedora"
PRETTY_NAME="CentOS Linux 7 (Core)"


CentOS Linux release 7.3.1611 (Core)
CentOS Linux release 7.3.1611 (Core)

apparently it’s running a fedora. I’ll try to install it following fedora instructions :slight_smile:

(Lucacasa) #9

using the version of OpenFOAM on the it’s still possible to access my /Users/MyName folder. With the version from openfoam foundation it is not. I was wondering if there was a way to access that folder… I don’t know if it is any more clear now…

(Sam) #10

i have no idea how they did that

(Don McCullough) #11

The -v option allows you to map folder in your container with a folder on you PC here is an example docker run command.
docker run --name containername -d -it -v ~/PCdir/:/Containerdir containername /bin/zsh you can then edit files on your pc and have the changes saved in the container…

(Lucacasa) #12

In the end the problem was that I was running a version of Fedora, not Ubuntu. Entering the docker as root and using yum, allowed me finally to install nano. In case someone happens to have the same issue this is how to:

  1. run your container
  2. in a separate terminal window use this: docker exec -it bash
  3. now run: yum -y install nano

As for accessing the home folder from my second container, I’ll try to meddle with it for a while and see if I manage to do it.

Thanks to both of you! :smiley: