为什么 docker pgadmin 和 postgres 服务以“.\”命名?

Why are docker pgadmin and postgres services named with '.\'?

我是 Docker 的超级新手,作为实习生,我的第一个任务是在 Laravel + Postgres + pgadmin + redis 容器化项目中解决与 docker 相关的一些问题。我 运行WSL2 Ubuntu 20.04 上的所有内容(因为我只有 Windows 10 Home)

我想我的问题很简单。

  1. 为什么 postgres 和 pgadmin 卷名称设置为带有“.”在开始??有人可以发现 pgadmin 服务的问题吗?在 docker-compose up -d 之后它不工作了,我还需要做任何其他设置吗?
postgres-app:
        image: postgres:12
        restart: always
        ports: 
            - "5432:5432"
        environment: 
            
            POSTGRES_PASSWORD: postgres            
            POSTGRES_DB: recadastramento
        volumes:
            - .\postgres:/var/lib/postgresql/data 
        networks: 
            - app-network
    pgadmim-app:
        image: dpage/pgadmin4
        environment:
            PGADMIN_DEFAULT_EMAIL: "noriakiakiba@gmail.com"
            PGADMIN_DEFAULT_PASSWORD: "123456"
        ports:
            - "16543:80"
        depends_on:
            - postgres-app
        volumes:
            - .\pgadmin:/var/lib/pgadmin
        networks:
            - app-network
networks: 
    app-network:
        driver: bridge

我的Docker文件

# Dockerfile
FROM php:7.4.1-apache

#se nao criar essa pasta dá erro ao instalar openjdk
RUN mkdir /usr/share/man/man1/

RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends \
  git-core \
  openssl \
  libssl-dev \
  autoconf \
  build-essential \
  apt-utils \
  zlib1g-dev \
  libzip-dev \
  unzip \
  zip \
  libmagick++-dev \
  libgraphicsmagick1-dev \
  libmagickwand-dev \
  libpq-dev \
  libfreetype6-dev \
  libjpeg62-turbo-dev \
  libpng-dev \
  libwebp-dev \ 
  libxpm-dev \
    nano \
    gcc \
    g++ \
    curl \
    imagemagick \                        
    git \                        
    zip \
    unzip \
    libcurl4-openssl-dev \
    make \
    ant \
    apt-transport-https \
    ca-certificates \
    dirmngr \
    wget \ 
    locales

RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
    locale-gen

# 2. apache configs + document root
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

# 3. mod_rewrite for URL rewrite and mod_headers for .htaccess extra headers like Access-Control-Allow-Origin-
RUN a2enmod rewrite headers

# 4. start with base php config, then add extensions
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"    

# Configure php extensions
RUN docker-php-ext-configure gd --with-freetype --with-jpeg

# Install php extensions
RUN docker-php-ext-install \
    bcmath \
    calendar \
    curl \
    exif \
    gd \
    iconv \
    intl \    
    pdo \    
    pdo_pgsql \    
    pcntl \
    tokenizer \
    xml \
    zip \
    json \
    soap

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

#RUN git clone https://github.com/nodejs/node.git \
# && cd node \
# && ./configure \
# && make \
# && sudo make install

RUN chown -R www-data:www-data /var/www/html

RUN echo 'memory_limit = -1' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini;

# Clear package lists
RUN apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*

RUN curl -sL https://deb.nodesource.com/setup_12.x | bash - &&\
    apt-get -y install nodejs

RUN pecl install xdebug \
    && docker-php-ext-enable xdebug \
    && echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
    && echo "xdebug.client_host = host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini

RUN pecl install imagick \
    && echo "extension=imagick.so" >> /usr/local/etc/php/php.ini
    
  1. 好的,按照建议我执行了 sudo docker-compose up 并得到了以下错误(postgres 的最后一部分永远重复):
postgres-app_1  | chmod: changing permissions of '/var/lib/postgresql/data': Operation not permitted
laravel-app_1   | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.3. Set the 'ServerName' directive globally to suppress this message
postgres-app_1  | The files belonging to this database system will be owned by user "postgres".
postgres-app_1  | This user must also own the server process.
postgres-app_1  | 
postgres-app_1  | The database cluster will be initialized with locale "en_US.utf8".
postgres-app_1  | The default database encoding has accordingly been set to "UTF8".
postgres-app_1  | The default text search configuration will be set to "english".
postgres-app_1  | 
postgres-app_1  | Data page checksums are disabled.
postgres-app_1  |
postgres-app_1  | fixing permissions on existing directory /var/lib/postgresql/data ... initdb: error: could not change permissions of directory "/var/lib/postgresql/data": Operation not permitted
pgadmim-app_1   | Traceback (most recent call last):
pgadmim-app_1   |   File "/pgadmin4/run_pgadmin.py", line 4, in <module>
pgadmim-app_1   |     from pgAdmin4 import app
pgadmim-app_1   |   File "/pgadmin4/pgAdmin4.py", line 94, in <module>
pgadmim-app_1   | WARNING: Failed to set ACL on the directory containing the configuration database:
pgadmim-app_1   |            [Errno 1] Operation not permitted: '/var/lib/pgadmin'
pgadmim-app_1   | HINT   : You may need to manually set the permissions on
pgadmim-app_1   |          /var/lib/pgadmin to allow pgadmin to write to it.
pgadmim-app_1   |     app = create_app()
pgadmim-app_1   |   File "/pgadmin4/pgadmin/__init__.py", line 256, in create_app
pgadmim-app_1   |     create_app_data_directory(config)
pgadmim-app_1   |   File "/pgadmin4/pgadmin/setup/data_directory.py", line 90, in create_app_data_directory
pgadmim-app_1   |     os.chmod(config.SESSION_DB_PATH, 0o700)
pgadmim-app_1   | PermissionError: [Errno 1] Operation not permitted: '/var/lib/pgadmin/sessions'
pgadmim-app_1   | [2021-01-28 22:57:21 +0000] [1] [INFO] Starting gunicorn 19.9.0
pgadmim-app_1   | [2021-01-28 22:57:21 +0000] [1] [INFO] Listening at: http://[::]:80 (1)
pgadmim-app_1   | [2021-01-28 22:57:21 +0000] [1] [INFO] Using worker: threads
pgadmim-app_1   | /usr/local/lib/python3.9/os.py:1023: RuntimeWarning: line buffering (buffering=1) isn't supported in binary mode, the default buffer size will be used
pgadmim-app_1   |   return io.open(fd, *args, **kwargs)
pgadmim-app_1   | [2021-01-28 22:57:21 +0000] [87] [INFO] Booting worker with pid: 87
pgadmim-app_1   | [2021-01-28 22:57:21 +0000] [87] [ERROR] Exception in worker process
pgadmim-app_1   | Traceback (most recent call last):
pgadmim-app_1   |   File "/usr/local/lib/python3.9/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
pgadmim-app_1   |     worker.init_process()
pgadmim-app_1   |   File "/usr/local/lib/python3.9/site-packages/gunicorn/workers/gthread.py", line 104, in init_process
pgadmim-app_1   |     super(ThreadWorker, self).init_process()
pgadmim-app_1   |   File "/usr/local/lib/python3.9/site-packages/gunicorn/workers/base.py", line 129, in init_process
pgadmim-app_1   |     self.load_wsgi()
pgadmim-app_1   |   File "/usr/local/lib/python3.9/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
pgadmim-app_1   |     self.wsgi = self.app.wsgi()
pgadmim-app_1   |   File "/usr/local/lib/python3.9/site-packages/gunicorn/app/base.py", line 67, in wsgi
pgadmim-app_1   |     self.callable = self.load()
pgadmim-app_1   |   File "/usr/local/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
pgadmim-app_1   |     return self.load_wsgiapp()
pgadmim-app_1   |   File "/usr/local/lib/python3.9/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
pgadmim-app_1   |     return util.import_app(self.app_uri)
pgadmim-app_1   |   File "/usr/local/lib/python3.9/site-packages/gunicorn/util.py", line 350, in import_app
pgadmim-app_1   |     __import__(module)
pgadmim-app_1   |   File "/pgadmin4/run_pgadmin.py", line 4, in <module>
pgadmim-app_1   |     from pgAdmin4 import app
pgadmim-app_1   |   File "/pgadmin4/pgAdmin4.py", line 94, in <module>
pgadmim-app_1   |     app = create_app()
pgadmim-app_1   |   File "/pgadmin4/pgadmin/__init__.py", line 256, in create_app
pgadmim-app_1   |     create_app_data_directory(config)
pgadmim-app_1   |   File "/pgadmin4/pgadmin/setup/data_directory.py", line 90, in create_app_data_directory
pgadmim-app_1   |     os.chmod(config.SESSION_DB_PATH, 0o700)
pgadmim-app_1   | PermissionError: [Errno 1] Operation not permitted: '/var/lib/pgadmin/sessions'
pgadmim-app_1   | [2021-01-28 22:57:21 +0000] [87] [INFO] Worker exiting (pid: 87)
pgadmim-app_1   | WARNING: Failed to set ACL on the directory containing the configuration database:
pgadmim-app_1   |            [Errno 1] Operation not permitted: '/var/lib/pgadmin'
pgadmim-app_1   | HINT   : You may need to manually set the permissions on
pgadmim-app_1   |          /var/lib/pgadmin to allow pgadmin to write to it.
docker_postgres-app_1 exited with code 1
pgadmim-app_1   | [2021-01-28 22:57:21 +0000] [1] [INFO] Shutting down: Master
pgadmim-app_1   | [2021-01-28 22:57:21 +0000] [1] [INFO] Reason: Worker failed to boot.
docker_pgadmim-app_1 exited with code 3
postgres-app_1  | chmod: changing permissions of '/var/lib/postgresql/data': Operation not permitted
postgres-app_1  | The files belonging to this database system will be owned by user "postgres".
postgres-app_1  | This user must also own the server process.
postgres-app_1  | 
postgres-app_1  | The database cluster will be initialized with locale "en_US.utf8".
postgres-app_1  | The default database encoding has accordingly been set to "UTF8".
postgres-app_1  | The default text search configuration will be set to "english".
postgres-app_1  | 
postgres-app_1  | Data page checksums are disabled.
postgres-app_1  | 
postgres-app_1  | initdb: error: could not change permissions of directory "/var/lib/postgresql/data": Operation not permitted
postgres-app_1  | fixing permissions on existing directory /var/lib/postgresql/data ... chmod: changing permissions of '/var/lib/postgresql/data': Operation not permitted

我搜索了这个错误,显然我需要在主机中 运行 chown -R 5050:5050 /var/lib 以便 pgadmin 在 [=32] 上 运行 =],但我想要的是自动修复此问题(也许使用 Docker 文件?)

我有一个类似的docker-compose.yml文件,但我使用named volumes for my db service. Only for my pgadmin service I use bind mount./pgadmin:/var/lib/pgadmin,绑定我[=31]中的目录./pgadmin =]宿主机到容器中的目录/var/lib/pgadmin。我发现它对 pgadmin 服务很有用,因为当我们生成 database/server 的备份文件时,我们可以直接从主机中的 ./pgadmin 中获取它。

以下是一个非常适合我的撰写文件。

docker-compose.yml

version: "3.7"
services:
  db:
    image: postgres:12
    container_name: db
    volumes:
      - db_data:/var/lib/postgresql/data
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=dbname
  pgadmin:
    image: dpage/pgadmin4
    container_name: pgadmin
    depends_on:
      - db
    volumes:
    - ./pgadmin:/var/lib/pgadmin
    ports:
      - "5555:80"
    environment:
      PGADMIN_DEFAULT_EMAIL: pgadmin@domain.de
      PGADMIN_DEFAULT_PASSWORD: pgadmin
volumes:
  db_data:

pgadmin 容器中目录 /var/lib/pgadmin 的权限:

/var/lib $ ls -l
total 20
drwxr-xr-x    2 root     root          4096 Dec 16 10:31 apk
drwxr-xr-x    2 root     root          4096 Dec 16 10:31 misc
drwxrwxrwx    1 pgadmin  pgadmin          0 Jan 29 03:09 pgadmin
drwx------    1 postfix  root          4096 Jan 29 03:09 postfix
drwx--x--x    3 root     root          4096 Jan 25 14:35 sudo
drwxr-xr-x    2 root     root          4096 Dec 16 10:31 udhcpd