简体   繁体   中英

Docker is changing files ownership and permission, why?

I have the following docker-compose.yml file:

version: '2'
services:
  php-fpm:
    container_name: "php71-fpm-nginx"
    build: php-fpm
    ports:
        - 8080:80
        - 9002:9002
    environment:
        PHP_ERROR_REPORTING: 'E_ALL & ~E_DEPRECATED & ~E_NOTICE'
        STATUS_PAGE_ALLOWED_IP: '127.0.0.1'
    volumes:
        - ~/dev:/data/www
    links:
        - db
  db:
    container_name: "db_mysql"
    image: mysql
    environment:
        MYSQL_ROOT_PASSWORD: '1qazxsw2'
        MYSQL_DATABASE: 'nortwind'
        MYSQL_USER: 'db_user'
        MYSQL_PASSWORD: '1qazxsw2'
    volumes:
        - ./dev/northwindSQL:/docker-entrypoint-initdb.d
        - ~/data/db:/var/lib/mysql
  elk:
    container_name: "elk"
    image: willdurand/elk
    ports:
        - 81:80
    volumes:
        - ./elk/logstash:/etc/logstash
        - ./elk/logstash/patterns:/opt/logstash/patterns
    volumes_from:
        - php-fpm

Everything is working fine but as soon as I run the command docker-compose up -d --build and the containers start up the ownership and permissions in the host at ~/dev get updated as follows:

$ ls -la ~/dev/
total 96
drwxrwxr-x  11     80     80 4096 Dec 15 14:36 .
drwx------. 40 rperez rperez 4096 Dec 15 14:26 ..
drwxr-xr-x   5     80     80 4096 Mar 13  2015 css
-rw-r--r--   1     80     80  189 Mar 10  2016 DEMO_NOTES.TXT

Is this an expected behavior? It's something coming from the Dockerfile ? Any ideas?

volumes take the ownership of whatever is already at the path in the container. If the location in the container is owned by root, then the volume will get root. If the location in the container is owned by something else, the volume will get that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM