Edit text file inside docker

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:

i installed the openFoam image, see https://openfoam.org/download/5-0-linux/

and nano is available without problem.

the mac instructions load the same ubuntu based image
https://hub.docker.com/r/openfoam/openfoam5-paraview54/

1 Like

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:

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

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…

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?

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.

if i insert that command this is what i get:

CentOS Linux release 7.3.1611 (Core)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL=“https://bugs.centos.org/

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION=“7”

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:

using the version of OpenFOAM on the https://www.openfoam.com/ 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…

i have no idea how they did that

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…

1 Like

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: