Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
400 views
in Technique[技术] by (71.8m points)

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

I am super new to Docker and my first task as an intern is to fix some problems related to docker in a Laravel + Postgres + pgadmin + redis containerized project. I'm running everything on WSL2 Ubuntu 20.04 (since I only have Windows 10 Home)

My questions are simple I believe.

  1. Why postgres and pgadmin volumes names are set with a '.' in the beggining?? And can someone spot a problem with the pgadmin service? It's not working after docker-compose up -d, do I have to do anything else to set it up?
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: "[email protected]"
            PGADMIN_DEFAULT_PASSWORD: "123456"
        ports:
            - "16543:80"
        depends_on:
            - postgres-app
        volumes:
            - .pgadmin:/var/lib/pgadmin
        networks:
            - app-network
networks: 
    app-network:
        driver: bridge

My Dockerfile

# 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. Ok, as recommended I executed sudo docker-compose up and got the following errors (the last part of postgres is repetead forever):
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

I searched for this error and apparently I need to run chown -R 5050:5050 /var/lib in the host in order for pgadmin to run on localhost:16543, but what I want is to fix this automatically (maybe with the Dockerfile?)

question from:https://stackoverflow.com/questions/65944521/why-are-docker-pgadmin-and-postgres-services-named-with

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I have a similar docker-compose.yml file, but I use named volumes for my db service. Only for my pgadmin service I use bind mount ./pgadmin:/var/lib/pgadmin, to bind the directory ./pgadmin in my windows host machine to the directory /var/lib/pgadmin in container. I find it useful for pgadmin service, because when we generate a backupfile of a database/server, we can take it directly from ./pgadmin in host machine.

Following is a compose file that works perfectly fine for me.

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: [email protected]
      PGADMIN_DEFAULT_PASSWORD: pgadmin
volumes:
  db_data:

permission of directory /var/lib/pgadmin in pgadmin container:

/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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...