Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to mount a docker image and then access it (RO) as a normal directory or mounted device?

Tags:

docker

I would like to take a Docker image (let's say ubuntu:latest) and make something like:

> docker-image-mount ubuntu:latest my_little_ubuntu  
> cd my_little_ubuntu
> ls
/usr /var /bin etc.

Is it possible somehow?

like image 210
fbrusch Avatar asked Oct 26 '14 16:10

fbrusch


People also ask

What is the syntax to mount a directory from the Docker host into a directory in the container?

The -v flag is used to mount a host folder, and it consists of two fields separated by a colon. The first part is the path in the host machine. The second part is the path in the container. The --name flag (optional) is used to give the container a specific name.

What are the two types of mounts in Docker?

Basically, there are 3 types of mounts which you can use in your Docker container viz. Volumes, Bind mount and tmpfs mounts.

What does it mean to mount Docker?

With Bind mounts Docker mounts the given source directory into a location inside the container. (The original directory / file in the read-only layer inside the union file system will simply be overridden).


1 Answers

You could use Podman and Buildah to mount a container image (RW).

prompt:~ # podman pull ubuntu

prompt:~ # container=`buildah from ubuntu`

prompt:~ # echo $container
ubuntu-working-container

prompt:~ # mnt=`buildah mount $container`

prompt:~ # echo $mnt
/var/lib/containers/storage/overlay/2b1...09b/merged

prompt:~ # ls $mnt
bin  boot  dev  etc  home  lib  ...  usr  var

prompt:~ # buildah umount $container

If you actually want to mount a running or stopped container, you could mount it using the podman mount command.

like image 98
aventurin Avatar answered Nov 16 '22 02:11

aventurin