Docker volume with www-data user

docker

#1

Part of my docker compose file

version: "3.1"
services:
  codecontainer:
    container_name: codecontainer
    build: .
    user: www-data
    volumes:
      - codecontainerdata:/var/www/html
  php:
    container_name: php
    restart: always
    build:
      context: ./build/php
      args:
        ENVIRONMENT: ${ENVIRONMENT}
    volumes:
      - codecontainerdata:/var/www/html
      - ./logs/php/:/var/log
    depends_on:
      - codecontainer
    user: www-data
volumes:
  pgdata:
  codecontainerdata:
  • :white_check_mark: Both Dockerfiles creating same www-data user and group
  • :white_check_mark: Dockerfile in Codecontainer copy files into /var/www/html
  • :white_check_mark: all files in dir /var/www/html inside codecontainer are getting chown www-data:www-data
  • :white_check_mark: docker-compose up

Problem:

  • :x: docker exec -ti -u www-data php ls -la /var/www/html => all files are owned root:root
  • :x: docker exec -ti php chown -R www-data:www-data /var/www
    • … chown: /var/www/html/README.md: Operation not permitted …

Additional Information:
Working on my mac and on linux

the job from .config.yml

  integration_tests:
    docker:
      - image: docker:17.09.0-ce
    working_directory: ~/repo/Api/
    steps:
      - checkout
      - setup_remote_docker:
          version: 17.09.0-ce
          docker_layer_caching: true
      - run:
          name: install python3
          command: apk update && apk add --no-cache python3
      - run:
          name: Install Docker Compose
          command: |
            set -x
            VER="1.16.1"
            pip3 install docker-compose==$VER
      - run:
          name: Start container with docker compose
          command: |
            set -x
            docker-compose up --build -d
          environment:
            ENVIRONMENT: test
            APPLICATION_CACHE: false
            APPLICATION_DEBUG: false
            LOCALE: en
      - run:
          name: install dependencies
          command: |
            set -x
            docker exec -ti -u www-data php ./composer.phar install

      - run:
          name: test db schema
          command: |
            set -x
            docker exec -ti -u www-data php ./bin/console doctrine:schema:validate --skip-sync
            
      - run:
          name: run integration tests
          command: |
            set -x
            docker exec -ti -u www-data php ./composer.phar integ

#2

If you need to mount volumes, we would recommend using the machine executor. This is documented here: https://circleci.com/docs/2.0/executor-types/#docker-benefits-and-limitations and https://circleci.com/docs/2.0/executor-types/#using-machine


#3