Mr Coder
Mr Coder

Reputation: 8186

Docker mount order out of sequence and not letting me mount my directory

My docker-compose.yml is as following

version: '3.3'

services:
   db:
     image: mysql:5.7
     container_name: mysql-wordpress
     volumes:
       - db_data:/var/lib/mysql
     ports:
       - "3300:3306"
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: root
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress

   wordpress:
     container_name: wordpress
     depends_on:
       - db
     image: wordpress:latest
     volumes:
      - ./wp-content:/var/www/html/wp-content
      - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
     ports:
       - "80:80"
       - "443:443"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress

   phpmyadmin:
      image: phpmyadmin/phpmyadmin
      container_name: phpmyadmin
      depends_on:
         - db
      restart: always
      ports:
         - "8080:80"
      environment:
        - PMA_ARBITRARY=1

volumes:
    db_data:

When I start docker-compose up -d

the wp-content directory does not have the same content of host inside the container wp-content directory.

When I do docker inspect WordPress:

"Mounts": [
        {
            "Type": "bind",
            "Source": "/rootfs/home/rancher/projects/tabletop/uploads.ini",
            "Destination": "/usr/local/etc/php/conf.d/uploads.ini",
            "Mode": "rw",
            "RW": true,
            "Propagation": "rprivate"
        },
        {
            "Type": "bind",
            "Source": "/rootfs/home/rancher/projects/tabletop/wp-content",
            "Destination": "/var/www/html/wp-content",
            "Mode": "rw",
            "RW": true,
            "Propagation": "rprivate"
        },
        {
            "Type": "volume",
            "Name": "d0a4f5ad342db0db782b41dd676aa0e58a324b5e7db1e56086bca5550a9ffdc3",
            "Source": "/var/lib/docker/volumes/d0a4f5ad342db0db782b41dd676aa0e58a324b5e7db1e56086bca5550a9ffdc3/_data",
            "Destination": "/var/www/html",
            "Driver": "local",
            "Mode": "",
            "RW": true,
            "Propagation": ""
        }

It seems the third mount might have overridden my bind mount. But I don't know where it is coming from. How can I have my wp-content mount after it?

Update: This problem occurs only on rancherOS , on coreOS and linux Mint its working fine

Upvotes: 2

Views: 4177

Answers (1)

Alejandro Galera
Alejandro Galera

Reputation: 3691

First of all, you know that you can create two kind of volumes (let's ignore for this explanation tmpfs):

  • bind-type volume
  • volume-type volume
    • named volumes.
    • unnamed volumes.

When you create a bind-type, it's done an association between two directories or files.

When you create a volume-type, internally, it's done also a bind between /var/lib/docker/volumes//_data and destination. can be a string given by you (named volume) or a string like yours: d0a4f5ad342db0db782b... (unnamed volume)

So, you've created two bind-volumes from your local directory in host ./wp-contend furthermore a bind volume for uploads.ini file. Everything is ok.

The point is that you've inherit an unnamed volume from image: wordpress:latest.

If you had Dockerfile which was used to generate wordpress:latest, you would see a line like:

VOLUME [/var/www/html]

So, it's generated an unnamed volume in /var/lib/docker/volumes/d0a4f5ad342db0db782b41dd676aa0e58a324b5e7db1e56086bca5550a9ffdc3/_data That is done to avoid lose all generated information if container exits. Is a way to keep consistency of the data. So, if originally you had a single file your_file.txt in your ./wp-content, after wordpress starts, wordpress creates in wp-content the following dirs/files if don't exist: - index.php - plugins/ - themes/ You should have the same information in your ./wp-content that you had before docker-compose -d up plus these generated-by-wordpress file and dirs, because you're mounting a bind volume in a subfolder over an already-mounted volume from wordpress image.

Upvotes: 1

Related Questions