docker-compose removing shared volume

I have this LEMP stack:

cadvisor:
  image: google/cadvisor:latest
  container_name: lemp_cadvisor
  ports:
    - "8080:8080"
  volumes:
    - "/:/rootfs:ro"
    - "/var/run:/var/run:rw"
    - "/sys:/sys:ro"
    - "/var/lib/docker/:/var/lib/docker:ro"    
base:
  build: ./base
  container_name: lemp_base
  volumes:
    - /home/core/server-lemp/www:/var/www:rw
phpmyadmin:
  build: ./phpmyadmin
  container_name: lemp_phpmyadmin
  volumes_from:
    - base
  volumes:
    - /var/www/phpmyadmin
    - ./phpmyadmin/var/www/phpmyadmin/config.inc.php:/var/www/phpmyadmin/config.inc.php:rw
ffmpeg:
  build: ./ffmpeg
  container_name: lemp_ffmpeg
  volumes_from:
    - phpmyadmin
  volumes:
    - /usr/ffmpeg
mariadb:
  build: ./mariadb
  container_name: lemp_mariadb
  environment:
    - MYSQL_ROOT_PASSWORD=your-pwd
  volumes_from:
    - ffmpeg
  volumes:
    - /var/run/mysqld
    - /home/core/server-lemp/mariadb:/var/lib/mysql:rw
    - ./mariadb/etc/mysql/my.cnf:/etc/mysql/my.cnf:ro
php:
  build: ./php
  container_name: lemp_php
  volumes_from:
    - mariadb
  volumes:
    - /var/run/php-fpm
    - ./php/usr/local/php7/etc/php-fpm.conf:/usr/local/php7/etc/php-fpm.conf:ro
    - ./php/usr/local/php7/etc/php.ini:/usr/local/php7/etc/php.ini:ro
    - ./php/usr/local/php7/etc/php-fpm.d/www.conf:/usr/local/php7/etc/php-fpm.d/www.conf:ro
    - ./php/etc/supervisor/conf.d/supervisord.conf:/etc/supervisor/conf.d/supervisord.conf:ro
    - ./php/etc/cron.d:/etc/cron.d:ro
nginx:
  build: ./nginx
  container_name: lemp_nginx
  net: "host"
  ports:
    - "80:80"
    - "443:443"
  volumes_from:
    - php
  volumes:
    - /var/cache/nginx
    - ./nginx/etc/nginx/nginx.conf:/etc/nginx/nginx.conf:ro

When I start this stack, every file will be deleted at /home/core/server-lemp/www on my host which is shared to /var/www.

  • Docker - Nodejs to Mongodb connection works but collection is null
  • Can Windows Containers be hosted on linux?
  • connecting error mysql db from host to docker container
  • Can I use logspout for global syslog logging on Docker swarm?
  • How to get a docker container to the state: dead for debugging?
  • Error response from daemon: chtimes /var/lib/docker/tmp/docker-export-$: invalid argument
  • In the past this didn’t happened, the new command is only net: "host" under nginx.

    This is what my docker-compose log looks like:

    Jan 18 22:10:14 core-1 docker-compose[11563]: Going to remove lemp_nginx, lemp_php, lemp_mariadb, lemp_ffmpeg, lemp_phpmyadmin, lemp_base, lemp_cadvisor
    Jan 18 22:10:14 core-1 docker-compose[11563]: Removing lemp_nginx ...
    Jan 18 22:10:14 core-1 docker-compose[11563]: Removing lemp_php ...
    Jan 18 22:10:14 core-1 docker-compose[11563]: Removing lemp_mariadb ...
    Jan 18 22:10:14 core-1 docker-compose[11563]: Removing lemp_ffmpeg ...
    Jan 18 22:10:14 core-1 docker-compose[11563]: Removing lemp_phpmyadmin ...
    Jan 18 22:10:14 core-1 docker-compose[11563]: Removing lemp_base ...
    Jan 18 22:10:14 core-1 docker-compose[11563]: Removing lemp_cadvisor ...
    --> The deletion happening somewhere here
    Jan 18 22:10:16 core-1 docker-compose[11563]: [303B blob data]
    Jan 18 22:10:16 core-1 docker-compose[11563]: ERROR: for lemp_mariadb  Driver overlay failed to remove root filesystem 3f35133e0814235cc4b9814606798f50d22e472d415ca814beb3443df8b89e3c: remove /var/lib/docker/overlay/3f35133e0814235cc4b9814606798f50d22e472d415ca814beb3443df8b89e3c/merged/var/www/phpmyadmin: device or resource busy
    Jan 18 22:10:17 core-1 docker-compose[11579]: Creating lemp_cadvisor
    

    UPDATE:

    Here is my base Dockerfile:

    # Lanti/lempBase
    #
    # VERSION               1.0.0
    
    FROM debian:latest
    MAINTAINER Istvan Lantos <info@lantosistvan.com>
    LABEL Description="This image is the base of the other app images in this project" Vendor="Istvan Lantos" Version="1.0"
    
    ENV TERM linux
    ENV DEBIAN_FRONTEND noninteractive
    RUN ln -sf /bin/bash /bin/sh && ln -sf /bin/bash /bin/sh.distrib
    
    RUN echo -e "\
    deb http://httpredir.debian.org/debian stable main contrib non-free\n\
    deb-src http://httpredir.debian.org/debian stable main contrib non-free\n\
    deb http://security.debian.org stable/updates main contrib non-free\n\
    deb-src http://security.debian.org stable/updates main contrib non-free\n\
    deb http://httpredir.debian.org/debian stable-updates main contrib non-free\n\
    deb-src http://httpredir.debian.org/debian stable-updates main contrib non-free" > /etc/apt/sources.list
    RUN apt-get -y update && apt-get -y dist-upgrade
    
    ### Start of optimizations
    # https://easyengine.io/tutorials/linux/increase-open-files-limit/
    RUN echo -e "\n\
    *               hard    nofile            500000\n\
    *               soft    nofile            500000\n\
    root            hard    nofile            500000\n\
    root            soft    nofile            500000" >> /etc/security/limits.conf \
        && echo -e "session required pam_limits.so" >> /etc/pam.d/common-session \
        && echo -e "fs.file-max = 2097152" >> /etc/sysctl.conf
    ### End of optimizations
    
    ### Start of Nginx WEBSERVER setup
    RUN mkdir -p /var/www
    # Modify www-data user and set UID, GID to 500
    # https://muffinresearch.co.uk/linux-changing-uids-and-gids-for-user/
    RUN groupmod -g 500 www-data \
        && usermod -u 500 www-data \
        #&& `find / -user 33 -exec chown -h 500 {} \;` \
        #&& `find / -group 33 -exec chgrp -h 500 {} \;` \
        && usermod -g 500 www-data \
        && chown -R www-data:www-data /var/www \
        && chmod g+s /var/www
    ### End of Nginx WEBSERVER setup
    
    RUN mkdir -p /root/lemp_base_volume
    
    RUN rm -rf /var/lib/apt/lists/*
    
    CMD ["tail", "-f", "/dev/null"]
    

    UPDATE 2:

    Seems like you cannot daisy chain your containers to create a build order, because something happening at mariadb which is causing the removal of all of your static webserver files.

    This is now my docker-compose file, I went back for the old solution of mine where I used to link everything to base, than share their volumes into php, NOT DAISY CHAINING THEM:

    cadvisor:
      image: google/cadvisor:latest
      container_name: lemp_cadvisor
      ports:
        - "8080:8080"
      volumes:
        - "/:/rootfs:ro"
        - "/var/run:/var/run:rw"
        - "/sys:/sys:ro"
        - "/var/lib/docker/:/var/lib/docker:ro"
    base:
      build: ./base
      container_name: lemp_base
      volumes:
        - /root/lemp_base_volume
    www:
      image: lemp_base
      container_name: lemp_www
      volumes_from:
        - base
      volumes:
        - /home/core/server-lemp/www:/var/www:rw
    phpmyadmin:
      build: ./phpmyadmin
      container_name: lemp_phpmyadmin
      volumes_from:
        - base
      volumes:
        - /var/www/phpmyadmin
        - ./phpmyadmin/var/www/phpmyadmin/config.inc.php:/var/www/phpmyadmin/config.inc.php:rw
    ffmpeg:
      build: ./ffmpeg
      container_name: lemp_ffmpeg
      volumes_from:
        - base
      volumes:
        - /usr/ffmpeg
    mariadb:
      build: ./mariadb
      container_name: lemp_mariadb
      environment:
        - MYSQL_ROOT_PASSWORD=your-db-pwd
      volumes_from:
        - base
      volumes:
        - /var/run/mysqld
        - /home/core/server-lemp/mariadb:/var/lib/mysql:rw
        - ./mariadb/etc/mysql/my.cnf:/etc/mysql/my.cnf:ro
    php:
      build: ./php
      container_name: lemp_php
      volumes_from:
        - www
        - phpmyadmin
        - ffmpeg
        - mariadb
      volumes:
        - /var/run/php-fpm
        - ./php/usr/local/php7/etc/php-fpm.conf:/usr/local/php7/etc/php-fpm.conf:ro
        - ./php/usr/local/php7/etc/php.ini:/usr/local/php7/etc/php.ini:ro
        - ./php/usr/local/php7/etc/php-fpm.d/www.conf:/usr/local/php7/etc/php-fpm.d/www.conf:ro
        - ./php/etc/cron.d:/etc/cron.d:ro
    nginx:
      build: ./nginx
      container_name: lemp_nginx
      ports:
        - "80:80"
        - "443:443"
      volumes_from:
        - php
      volumes:
        - /var/cache/nginx
        - ./nginx/etc/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
    

    I created a new container called www which is the base image with the static webserver files shared into from the host. base now only need because every other image will be built from this image.

    Just like in my old solution, where I used link to create the network, every shared volume will meet in php and php‘s volume shared to nginx, which is on top of everything.

    So:

    links:
      - base
    

    Became:

    volumes_from:
      - base
    

    To maintain the build order and make sure that base will be built first.

    I created a bridged network for this stack with docker-compose --x-networking --x-network-driver=bridge up.

    But looks like the cron jobs are not working, again.

    UPDATE3:

    This is what I got with rsyslog:

    root@0687540163a3:/var/log# cat syslog
    Jan 22 14:45:04 0687540163a3 rsyslogd: [origin software="rsyslogd" swVersion="8.4.2" x-pid="13" x-info="http://www.rsyslog.com"] start
    Jan 22 14:45:04 0687540163a3 rsyslogd: imklog: cannot open kernel log(/proc/kmsg): Operation not permitted.
    Jan 22 14:45:04 0687540163a3 rsyslogd-2145: activation of module imklog failed [try http://www.rsyslog.com/e/2145 ]
    Jan 22 14:45:04 0687540163a3 cron[22]: (CRON) INFO (pidfile fd = 3)
    Jan 22 14:45:04 0687540163a3 cron[23]: (CRON) STARTUP (fork ok)
    Jan 22 14:45:04 0687540163a3 cron[23]: (*system*) NUMBER OF HARD LINKS > 1 (/etc/crontab)
    Jan 22 14:45:04 0687540163a3 cron[23]: (*system*wpcron) NUMBER OF HARD LINKS > 1 (/etc/cron.d/wpcron)
    Jan 22 14:45:04 0687540163a3 cron[23]: (*) ORPHAN (no passwd entry)
    Jan 22 14:45:04 0687540163a3 cron[23]: (CRON) INFO (Running @reboot jobs)
    Jan 22 14:46:01 0687540163a3 cron[23]: (*system*) NUMBER OF HARD LINKS > 1 (/etc/crontab)
    Jan 22 14:46:01 0687540163a3 cron[23]: (*system*wpcron) NUMBER OF HARD LINKS > 1 (/etc/cron.d/wpcron)
    Jan 22 14:46:01 0687540163a3 cron[23]: (*) ORPHAN (no passwd entry)
    

    This is what my wpcron file looks like:

    */1 *   * * *   www-data    php /var/www/domain.com/wp-cron.php >> /var/log/wp-cron.log 2>&1
    

    After the first 5 minute, /var/log/wp-cron.log still not created.

  • Fail when start a new container with elasticsearch 5.0
  • Building Docker Images with Drone.io
  • how do I start a simple container?
  • How to connect jenkins to docker?
  • Is it possible to use a mounted file in a docker file
  • Communicate to Docker host from Docker container
  • One Solution collect form web for “docker-compose removing shared volume”

    I met the same issue with you.I think that there are some problems with lemp_mariadb container.

    To solve this issue. You should try the steps below:
    Get lemp_mariadb container id:

    docker ps -a
    

    If you see lemp_mariadb status is Dead. You should go to /var/lib/docker/containers. You find the directory that has same name with lemp_mariadb container id and delete it

    rm -rf /var/lib/docker/containers/lemp_mariadb_container_id
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.