简体   繁体   中英

Docker chown on my machine, but not on the server

I have docker-compose.yml file

version: '3'
services:

  #PHP Service
  app:
    build:
      context: .
      dockerfile: Dockerfile
    image: pamo/php
    container_name: app
    restart: unless-stopped
    tty: true
    working_dir: /var/www
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      - ./:/var/www
    networks:
      - app-network

  #Nginx Service
  webserver:
    image: nginx:alpine
    container_name: webserver
    restart: unless-stopped
    tty: true
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./:/var/www
      - .docker/nginx-conf.d/:/etc/nginx/conf.d/
      - .docker/logs/:/var/log/nginx/
    networks:
      - app-network

#Docker Networks
networks:
  app-network:
    driver: bridge

and this is Dockerfile :

FROM php:7.4-fpm

# Set working directory
WORKDIR /var/www

# Install dependencies
RUN apt-get update && apt-get install -y \
    libonig-dev \
    build-essential \
    libpng-dev \
    libzip-dev \
    libjpeg62-turbo-dev \
    libfreetype6-dev \
    locales \
    zip \
    jpegoptim optipng pngquant gifsicle \
    vim \
    unzip \
    git \
    curl

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl gd

# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www


# Copy existing application directory permissions
COPY --chown=www:www . /var/www

# Change current user to www
USER www

# Expose port 9000 and start php-fpm server
EXPOSE 9000


CMD ["php-fpm"]

On my local machine (ARCH, Linux os 5.10.52-1-lts), when i run docker-compose run app ls -l , output is:

drwxr-xr-x 39 www 1003   4096 Jul 22 06:08 Modules
-rw-r--r--  1 www 1003    515 Jul 22 18:40 README.md
drwxr-xr-x  3 www 1003   4096 Jul 22 06:08 Themes
drwxr-xr-x  9 www 1003   4096 Jul 22 06:08 app
-rw-r--r--  1 www 1003   1690 Jul 22 06:08 artisan
drwxr-xr-x  3 www 1003   4096 Jul 22 06:08 bootstrap
-rw-r--r--  1 www 1003   2291 Jul 22 07:05 composer.json
-rw-r--r--  1 www 1003 391487 Jul 23 05:56 composer.lock

So, my app work right, user own app is www . But when on my server (Centos), output like this:

drwxr-xr-x 39 root root   4096 Jul 23 05:41 Modules
-rw-r--r--  1 root root    515 Jul 23 05:43 README.md
drwxr-xr-x  3 root root   4096 Jul 23 05:41 Themes
drwxr-xr-x  9 root root   4096 Jul 23 05:41 app
-rw-r--r--  1 root root   1690 Jul 23 05:41 artisan
drwxr-xr-x  3 root root   4096 Jul 23 05:41 bootstrap
-rw-r--r--  1 root root   2291 Jul 23 05:43 composer.json
-rw-r--r--  1 root root 395282 Jul 23 05:41 composer.lock

My folder app now own by root , and root is current user of my server, and chown command in Dockerfile not work. Can you tell me why ?

Make sure you are not root with the whoami command. If you are not root, try giving root permissions to your account by editing the file along this path /etc/passwd

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