How to persist changes to boot2docker in docker-machine? - linux

I am using docker-machine which I use to manage VM running boot2docker with virtualbox as driver. I need to mount directory to this VM. I was able to do that by adding the folder to shared folders list in settings of VM in Virtualbox Manager. Then using sudo mount -t vboxsf -o uid=1000,gid=50 <name of folder in VM settings> <folder name>. It worked & I added the command to create directory & mount without using relative address to etc/rc.local . The changes I made to VM don't persist when I restart the VM. What do I do?
I am working on Ubuntu 14.04.

The persistent directories are documented here: https://github.com/boot2docker/boot2docker/blob/master/doc/FAQ.md#local-customisation-with-persistent-partition
So you can add your mount command to bootlocal.sh under /var/lib/boot2docker/ directory.

Create a folder. Inside, create a Dockerfile. The first line should be FROM plus the name of the image which you currently use.
Then you can add the commands to modify the base image. In your case, put a copy of rc.local in the same folder as the Dockerfile
Now you can copy it into your new image with:
ADD rc.local /etc
You can then build your new image with docker build -t user1932582/myapp .
That creates a new image which you can run with docker run user1932582/myapp
Related:
http://docs.docker.com/reference/builder/

Related

Docker won't copy files from the container to the host's /tmp folder

I am trying to copy a file from a linux container to a linux host using docker cp. I want to copy this file to the /tmp folder on the host machine.
The problem is simple: I can copy to other places, such as my home folder. For example, this works:
docker cp my_container:/certificate.cer /home/adam/Documents/certificate.cer
But this does not work:
docker cp my_container:/certificate.cer /tmp/certificate.cer.
However, the command completes with a zero exit code as if the operation was successful. I get no error feedback, but the file definitely isn't there.
Am I missing something, or is this a bug with the Docker CLI?
edit: From further testing I have noticed that creating a new directory in /tmp, (i.e.
mkdir /tmp/test) Then trying to copy the file into that subfolder, fails with an error: stat /tmp/test/: not a directory.
This seems to indicate that perhaps docker is looking at a different folder? I am not sure where it could be looking though.
Thanks
I believe I have found the answer to this:
Docker was installed as an Ubuntu Snap, which as I understand, is sandboxed. Running sudo ls /tmp/snap.docker/tmp showed me all the files I was missing.
So, it seems the snap version of docker works a little differently than expected. Uninstalling it and reinstalling from apt fixed the problem. :)

How to connect two containers when one of the container is mount to the filesystem?

Container 1 : I have a docker container which is spawned by a Dockerfile image that i built serving Python dependencies to a specific use-case. This container is mount to my file system project directory to /source directory in the Docker container.
Container 2 : Another container contains Jupyter notebook and it is only configured to use Jupyter notebook.
I don't use Jupyter notebook all the time for Python developement, i use my code editor instead. I just want an easier way to mount Jupyter notebook when i want to and edit my project files.
Now, can i mount Container-2 to Container-1 such that contents in the /source directory in Container-1 is persisted to my project directory while enabling Container-1 and Conatiner-2 to take up a shared space? In my case i want Container-1 to be mount to my file system to /source and I want the Jupyter Notebook, running in Container-2 to be able to edit files inside the /source directory in Container-1.
if I'm understanding correctly, what you are trying to do is using one container installed libs in another container
I think that this approach is bad, since there might be some problems with OS level dependencies that are missing. The first possible solution is installing the dependencies in both containers, or at least using the 1st docker image as base to the 2nd
If you yet rather doing it your way, you can try mounting volume between the 1st container virtual env / site-packages with the 2nd

Docker - accessing files inside container from host

I am new to docker.
I ran a node-10 images and inside the running container I cloned a repository, ran the app which started a server with file watcher. I need to access the codebase inside the container, open it up in an IDE running on the windows host. If that is done, then I also want that as I change the files in the IDE these changes induce the filewatcher in the container.
Any help is appreciated. Thanks,
The concept you are looking for is called volumes. You need to start a container and mount a host directory inside it. For the container, it will be a regular folder, and it will create files in it. For you, it will also be a regular folder. Changes made by either side will be visible to another.
docker run -v /a/local/dir:/a/dir/in/your/container
Note though that you can run into permission issues that you will need to figure out separately.
It depends on what you want to do with the files.
There is the docker cp command that you can use to copy files to/from a container.
However, it sounds to me like you are using docker for development, so you should mount a volume instead, that is, you mount a directory on the host as a volume in docker, so anything written to that directory will show up in the container, and vice versa.
For instance if you have the code base that you develop against in C:\src on your windows machine, then you run docker like docker run -v c:\src:/app where /app is the location that node is looking in. However, for Windows there are a few things to consider since Docker is not native in Windows, so have a look at the documentation first.
Hi I think you should use mount volumes for the source code and edit your code from your IDE normally:
docker run -it -v "$PWD":/app -w /app -u node node:10 yarn dev
here docker will create an image setting the working dir to "/app", mount the current dir to "/app" and run "yarn dev" at start up with the "node" user (none root user)
Hope this is helpfull.

What is the file-system of a Docker container? On which file system does an application running inside this container runs on?

Basically, I am running Docker on my Windows 10 machine. I have mounted a windows directory inside this container to access the files on my windows machine, on which a couple of tasks are to be performed.
Which file system runs inside a docker container?
Is it the same as that of the OS on which this container is based? For instance, if I run a container having ubuntu as base OS, will it be the one that the current version of ubuntu (inside this container is running)?
Or is it the one that is running on the docker daemon?
Also, I am running an application inside this container, which accesses files in my windows directory as well as creates a couple of files. Now, these files are being written to Windows, hence follow the file system of Windows(NTFS).
So, how does it work? (Different file system inside the docker container and the windows file system; both in conjunctuion?)
Which file system runs inside a docker container?
The one from the docker host (Windows NTFS or Ubuntu FS).
$ docker run -d -P --name web -v /src/webapp:/opt/webapp training/webapp python app.py
This command mounts the host directory, /src/webapp, into the container at /opt/webapp.
If the path /opt/webapp already exists inside the container’s image, the /src/webapp mount overlays but does not remove the pre-existing content.
Once the mount is removed, the content is accessible again.
Now, these files are being written to Windows, hence follow the file system of Windows(NTFS).
Yes, and that filesystem is case-sensitive (as illustrated in 18756).

How to access share folder in virtualbox. Host Win7, Guest Fedora 16?

I'm a newbie in linux. I installed Fedora 16 OS as guest in virtualbox on Window 7. Now, I want to access share folder from Fedora. Here is something I did:
Install guest addtion [OK]
Make share folder link to virtualbox [OK]. Share folder path in Window 7: D:\share_folder_vm
In terminal program in fedora, I just run some commands:
[hoangphi#localhost ~]$ su
Password:
[root#localhost hoangphi]# cd Desktop/
[root#localhost Desktop]# mkdir share_folder
[root#localhost Desktop]# sudo mount -t vboxsf D:\share_folder_vm \share_folder
/sbin/mount.vboxsf: mounting failed with the error: Protocol error
[root#localhost Desktop]#
I got this message: /sbin/mount.vboxsf: mounting failed with the error: Protocol error
share_folder_vm is the folder in Win7 Host and share_folder is the folder in Fedora Guest.
My question: How can I fix this problem?
Install Oracle Guest Additions:
[host-hotkey (usually right Ctrl)] + [d],
Then:
sudo /media/VBOXADDITIONS_4.*/VBoxLinuxAdditions.run
You can now enjoy:
A guest that can run at native screen resolution
Ability to share files between host and guest
Share the clipboard (allowing you to copy and paste between host and guest).
To share folders set them up to be shared. Consider the permissions. Note that the host file permissions are transient. IOW if you can't write to file on host, the guest can't either.
After setting up the file to be shared create a destination if you don't have one:
mkdir -p ~/destination
Now mount it under the name you configured it with:
sudo mount -t vboxsf myFileName ~/destination
As an extra tip you can really exploit this feature to do things like:
- Use guest subversion client to create repository to mounted directory (you won't have a full svn client but the repo can be used in an IDE on the host).
- I personally use my guest to download and unpack binaries like Tomcat to a targeted mount. Yes you can use Linux to install things on Windows!
To unmount all shares:
sudo umount -f -a -t vboxsf
This thread has some great tips. However....
#GirishB's answer isn't correct - sorry. Jartender's is best.
Also, every post in here seems to assume you're logging in to the Linux guest as root, except for #tomoguisuru. Yuck! Don't use root, use a separate user account and "sudo" when you need root privileges. Then this user (or any other user who needs the shared folder) should have membership in the vboxsf group, and #tomoguisuru's command is perfect, even terser than what I use.
Forget running mount yourself. Set up the shared folder to auto mount and you'll find the shared folder - it's under /media in my OEL (RH and Centos probably the same). If it's not there, just run "mount" with no arguments and look for the mounted directory of type vboxsf.
For accessing a shared folder, YOU have to have "Oracle VM extension pack" installed.
Look at the bottom of this link, you can download it from there.
http://www.oracle.com/technetwork/server-storage/virtualbox/downloads/index.html
I just figured. You need to add a shared folder using VirtualBox before you access it with the guest.
Click "Device" in the menu bar--->Shared File--->add a directory and name it
then in the guest terminal, use:
sudo mount -t vboxsf myFileName ~/destination
Dont directly refer to the host directory
There's a simpler way I found when running Linux Mint.
Ensure you install the Guest Additions from the command line and that you have the folder(s) shared with "automount" and "make permanent" settings selected within "Shared Folders" tab of the Machine Settings
Launch the User management application from Application/Settings/System Setting/ menu selection (requires sudo) from within the Mint menu
In the "Privileges and Groups" tab, check the box next to the "vboxsf" group, and then apply and ok your way back out.
Any user within the vboxsf group has full access to any shared folders on each boot with no manual mounting or unmounting
I usually do the following in addition to the above just to have quick access
Open the Dolphin file manager and navigate to /media/
Right-Click on the shared folder and click "Add to Places"
You probably need to change your mount command from:
[root#localhost Desktop]# sudo mount -t vboxsf D:\share_folder_vm \share_folder
to:
[root#localhost Desktop]# sudo mount -t vboxsf share_name \share_folder
where share_name is the "Name" of the share in the VirtualBox -> Shared Folders -> Folder List list box. The argument you have ("D:\share_folder_vm") is the "Path" of the share on the host, not the "Name".
May be this can help other guys:
I had the same problem, and after looking with Google I found that can be because of the permissions of the folder... So, you need first to add permissions...
$ chmod 777 share_folder
Then run again
$ sudo mount -t vboxsf D:\share_folder_vm \share_folder
Check the answers here: Error mounting VirtualBox shared folders in an Ubuntu guest...
VirtualBox version has many uncompatibilities with Linux version, so it's hard to install by using "Guest Addition CD image". For linux distributions it's frequently have a good companion Guest Addition package(equivalent functions to the CD image) which can be installed by:
sudo apt-get install virtualbox-guest-dkms
After that, on the window menu of the Guest, go to Devices->Shared Folders Settings->Shared Folders and add a host window folder to Machine Folders(Mark Auto-mount option) then you can see the shared folder in the Files of Guest Linux.
There is a really simple tuturial here : http://my-wd-local.wikidot.com/otherapp:configure-virtualbox-shared-folders-in-a-windows-ho
telling to do:
sudo mkdir /mnt/vbox_share
sudo mount.vboxsf nameAddesAsShared /mnt/vbox_share
These are the steps to share a folder from Windows to Linux Virtual Box
Step 1 : Install Virtual Box Extension Pack from this link
Step 2: Install Oracle Guest Additions:
By pressing -> Right Ctrl and d together
Run the command
sudo /media/VBOXADDITIONS_4.*/VBoxLinuxAdditions.run
Step 3 : Create Shared Folder by Clicking Settings in Vbox
Then Shared Folders -> + and give a name to the folder (e.g. VB_Share)
Select the Shared Folder path on Windows (e.g. D:\VBox_Share)
Step 4: Create a folder in named VB_share in home\user-name (e.g. home\satish\VB_share) and share
mkdir VB_Share
chmod 777 VB_share
Step 5: Run the following command
sudo mount –t vboxsf vBox_Share VB_Share

Resources