[Docker] How to see the contents of Volumes. Start a container with root privileges.

How to check the folders and files in the Docker volume.

Confirmation method

  1. Check the volume point (absolute path) with docker volume inspect.
  2. Start a container with root privileges from the image.
  3. Use the ls command in the terminal inside the container

Checking the mount point of volume


#Display volume list
docker volume ls

#Check mount point
docker volume inspect [Volume name]

Start a container with root privileges and check the contents of the volume


#Start container with root authority
$ docker run -it --privileged --pid=host [Image name] nsenter -t 1 -m -u -n -i sh

#Show the contents of the volume
/ # ls [Absolute path of mountpoint]

#End interactive mode
/ # exit

With the above operation, the contents of volume can be confirmed.


## Confirmation procedure by example

Check the image


$ docker images
REPOSITORY                                      TAG                 IMAGE ID            CREATED             SIZE
tomcat                                          latest              35064a4fcc93        2 weeks ago         648MB
django_web                                      latest              7f0eff7ebc94        2 weeks ago         937MB
debian                                          latest              1510e8501783        5 weeks ago         114MB
python                                          3                   dfc47c6cee13        6 weeks ago         886MB
postgres                                        latest              817f2d3d51ec        7 weeks ago         314MB
vuecli                                          3                   4040959eab16        2 months ago        338MB

Display volume list


$ docker volume ls
DRIVER              VOLUME NAME
local               0adf7a2b08b8e09f74ffb7799716e48263f012612dc2047da1d7137a75f12b5d
local               vuecli3_vue-cli-node-volume

Check mount point


$ docker volume inspect vuecli3_vue-cli-node-volume
[
    {
        "CreatedAt": "2020-09-08T05:35:36Z",
        "Driver": "local",
        "Labels": {
            "com.docker.compose.project": "vuecli3",
            "com.docker.compose.version": "1.26.2",
            "com.docker.compose.volume": "vue-cli-node-volume"
        },
        "Mountpoint": "/var/lib/docker/volumes/vuecli3_vue-cli-node-volume/_data",
        "Name": "vuecli3_vue-cli-node-volume",
        "Options": null,
        "Scope": "local"
    }
]

Enter docker interactive mode


$ docker run -it --privileged --pid=host [Image name] nsenter -t 1 -m -u -n -i sh

docker interactive mode


/ # ls
EFI         boot        dev         home        lib         mnt         proc        run         srv         tmp         var
bin         containers  etc         init        media       opt         root        sbin        sys         usr

Check volume


/ # ls /var/lib/docker/volumes/micres_micres-node_modules2/_data
@babel                                       mime-db
@csstools                                    mime-types
@mdi                                         mimic-response
@nicolo-ribaudo                              mini-css-extract-plugin
@npmcli                                      minimalistic-assert
@rails                                       minimalistic-crypto-utils

Details of starting a container with root privileges

What is the most important command to start a container with root privileges?

Command $ docker run -it --privileged --pid = host [image name] nsenter -t 1 -m -u -n -i sh`

-It -t pseudo terminal (--tty) -i Standard output always ON (--interactive)

--Privileged Privileged mode. Launch a special container with root privileges on the host.

--Pid = host --pit = Specify the PID namespace for the container. Use the host-side PID namespace inside the host container.

Nsenter A command line tool for entering namespaces created with Docker. A combination of acronyms for "ENTER into Name Spaces".


▼ nsenter options ・ `-T` Specify the "--target pid" process. Specify 1 here.

-M "--Mount" Enter the mount name space. If no namespace is specified, the process specified by PID will be used.

・ ` ` Enter the "-uts" UTS namespace. If no namespace is specified, the process specified by PID will be used.

uts stands for Unix Time Sharing.

・ ` ` Enter the "--net" network namespace. If no namespace is specified, the process specified by PID will be used.

-I Enter the "--ipc" IPC namespace. If no namespace is specified, the process specified by PID will be used.

In short, it seems that various namespaces will be launched by processing PID = 1.

List of Linux nsenter options

Recommended Posts

[Docker] How to see the contents of Volumes. Start a container with root privileges.
How to start a Docker container with a volume mounted in a batch file
Wait for the container service to start with docker healthcheck
[Ruby] How to retrieve the contents of a double hash
How to start Camunda with Docker
How to build a Jenkins server with a Docker container on CentOS 7 of VirtualBox and access the Jenkins server from a local PC
The story of pushing a Docker container to GitHub Package Registry and Docker Hub with GitHub Actions
How to check for the contents of a java fixed-length string
How to build an environment with Docker, which is the minimum required to start a Rails application
After all I wanted to preview the contents of mysql with Docker ...
How to check the logs in the Docker container
Customize how to divide the contents of Recyclerview
How to get a heapdump from a Docker container
How to mount the batch file location via WSL2 and start the Docker container
How to get the ID of a user authenticated with Firebase in Swift
How to display the amount of disk used by Docker container for each container
Up to the point of launching a Docker container built using RedHat Quarkus
How to start with Hyper-V instead of WSL2 on Docker Desktop for Windows
How to install the root certificate of Centos7 (Cybertrust)
[Rails] How to get the contents of strong parameters
[Java] How to start a new line with StringBuilder
If you use SQLite with VSCode, use the extension (how to see the binary file of sqlite3)
[Docker] How to update using a container on Heroku and how to deal with Migrate Error
How to solve when you cannot connect to DB with a new container because the port is assigned to the existing docker container
How to take a screenshot with the Android Studio emulator
[Docker] Delete only the volume associated with a specific container
How to change the contents of the jar file without decompressing
[jsoup] How to get the full amount of a document
[Docker] How to access the host from inside the container. http://host.docker.internal:
Try to imitate the idea of a two-dimensional array with a one-dimensional array
How to make a Java container
I tried to build the environment of PlantUML Server with Docker
Check the contents by docker pull from ECR and start the container
How to get the contents of Map using for statement Memorandum
Let's create a Docker container that can connect to CentOS 8 with the minimum configuration by SSH
I examined the concept of the process to understand how Docker works
[Note] How to restart the Windows container set up with docker-compose
[chown] How to change the owner of a file or directory
[Linux] Start Apache container with Docker
Make a daily build of the TOPPERS kernel with Gitlab and Docker
How to quickly create a reverse proxy that supports HTTPS with Docker
Wait for PostgreSQL to start with Docker and then start the WEB service
How to check before sending a message to the server with Spring Integration
How to execute with commands of normal development language in Docker development environment
How to access Socket directly with the TCP function of Spring Integration
How to convert an array of Strings to an array of objects with the Stream API
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
[Docker] How to build when the source code is bind-mounted on the container
How to find out the Java version of a compiled class file
[Java] How to get to the front of a specific string using the String class
How to change the value of a variable at a breakpoint in intelliJ
How to get the absolute path of a directory running in Java
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
[Ruby On Rails] How to search the contents of params using include?
[swift5] How to change the color of TabBar or the color of item of TabBar with code
How to share files with Docker Toolbox
[Rails] How to use rails console with docker
The story of updating SonarQube's Docker Container
How to determine the number of parallels
How to sort the List of SelectItem
[Docker] Start the container as soon as possible