如何使用 docker-compose 在 postgres 中设置语言环境?

问题描述 投票:0回答:1

我尝试了多种将语言环境更改为 en_GB 的方法,但似乎没有任何效果。

我现在的

docker-compose.yml

version: '3.9'

services:

  db:
    image: postgres
    restart: always
    build: 
      context: .
      dockerfile: ./Dockerfile
    ports:
      - 5432:5432
    volumes:
      - ./pg-data:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
      PGDATA: ${PGDATA}
      # LANG: 'en_GB.UTF-8'

  adminer:
    depends_on: 
      - db
    image: adminer
    restart: always
    ports:
      - 8080:8080
  
volumes:
  pg-data:

官方的 postgres 图像文档说要创建一个

Dockerfile

FROM postgres
RUN localedef -i en_GB -c -f UTF-8 -A /usr/share/locale/locale.alias en_GB.UTF-8
ENV LANG en_GB.utf8

但是这没有任何效果..尝试设置环境变量 LC_* 和 LANG 但这会引发环境变量配置错误的构建错误。

只有一个

Dockerfile
,没有设置环境变量,容器构建和数据库正在重新初始化,但在使用
knex
运行第一次迁移时,由
money
类型组成的表仍然以美元为单位。

postgresql docker-compose dockerfile locale
1个回答
0
投票

恕我直言:您只能在 compose.yml 中使用标签“image”或“build” 如果两者都存在,则图像排名较高。因此您的构建部分将被忽略。

此外,您的作文中有一些重复条目和逻辑错误 数据文件夹。

compose.yml
Dockerfile
结合在一起是一个示例:

compose.yml

services:

  postgres:
    container_name: 'test_pg_db'
    build: 
      context: .
      dockerfile: ./Dockerfile
    # image: 'postgres:latest'  # as we build the image, this line is actually obsolete
    restart: always
    ports:
      # depending on the access you can skip the port binding
      - 5432:5432

    # set shared memory limit when using docker-compose (standard is 64MB) - no clue why the docker tutorial recommends this
    shm_size: '128mb'
 
    environment:
      POSTGRES_USER: test_admin # The PostgreSQL user (useful to connect to the database)
      POSTGRES_PASSWORD: MyVerySecretPassword  # The PostgreSQL password (useful to connect to the database)
      POSTGRES_DB: test_db   # The PostgreSQL default database (automatically created at first launch)
              
    volumes:
    # Move the data from the container to a save location (otherwise deleting the container will delete all data)
    
    # Use this entry to have docker taking care of the path of the volume on the host 
    # uncomment the two lines at the volume section as well!
    # - pgdata:/var/lib/postgresql/data 
 
    # Use this entry to use a specific folder on the host
      - /docker_data/hanf_api/pg_db:/var/lib/postgresql/data

    healthcheck:
      # had to add the user and database for no FATAL errors in the logs (role root does not exist9
      test: ["CMD-SHELL", "pg_isready -U test_admin -d test_db"]
      interval: 1s
      timeout: 5s
      retries: 10

# uncomment if you want docker to handle the volume for the data
# volumes:
  # pg-data:

这是

Dockerfile
的样子(与 compose.yml 存储在同一目录中)

FROM postgres:latest
RUN localedef -i de_DE -c -f UTF-8 -A /usr/share/locale/locale.alias de_DE.UTF-8
ENV LANG=de_DE.utf8
© www.soinside.com 2019 - 2024. All rights reserved.