如何解决为什么 docker pgadmin 和 postgres 服务以“.\”命名?
我是 Docker 的超级新手,我作为实习生的第一项任务是在 Laravel + Postgres + pgadmin + redis 容器化项目中解决与 docker 相关的一些问题。我在 WSL2 Ubuntu 20.04 上运行所有东西(因为我只有 Windows 10 Home)
我相信我的问题很简单。
- 为什么 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
我的 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
- 好的,按照建议,我执行了 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",in <module>
pgadmim-app_1 | app = create_app()
pgadmim-app_1 | File "/pgadmin4/pgadmin/__init__.py",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 在 localhost:16543 上运行,但我想要的是自动修复这个问题(也许用Dockerfile?)
解决方法
我有一个类似的 docker-compose.yml 文件,但我的数据库服务使用 named volumes。仅对于我的 pgadmin 服务,我使用 bind mount StandardError
,将 Windows 主机中的目录 ./pgadmin:/var/lib/pgadmin
绑定到容器中的目录 ./pgadmin
。我发现它对 pgadmin 服务很有用,因为当我们生成数据库/服务器的备份文件时,我们可以直接从主机的 /var/lib/pgadmin
获取它。
以下是一个非常适合我的撰写文件。
docker-compose.yml
./pgadmin
pgadmin 容器中目录 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:
的权限:
/var/lib/pgadmin
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。