admin管理员组

文章数量:1302294

So i have been trying to figure out for a week now on how to set locale inside my docker container postgres using dockerfile and so far with 0 success. The playbook itself does not fail but it also dosent do anything to resolve what the dockerfile tells it to do. Ive tried 3 different dockerfiles so far with various different ways to get it to work still all end up with same result of 0.

First dockerfile:

RUN apt-get update && apt-get install -y locales

RUN dpkg-reconfigure locales && \
  locale-gen C.UTF-8 && \
  /usr/sbin/update-locale LANG=C.UTF-8

RUN echo 'et_EE.UTF-8 UTF-8' >> /etc/locale.gen && \
  locale-gen

ENV LC_ALL C.UTF-8
ENV LANG et_EE.UTF-8
ENV LANGUAGE et_EE.UTF-8

Second dockerfile :

FROM postgres:15.3

# Install the locales package
RUN apt-get update && \
    apt-get install -y locales && \
    locale-gen et_EE.UTF-8 && \
    update-locale LANG=et_EE.UTF-8 && \
    apt-get clean && \ 
    rm -rf /var/lib/apt/lists/*

# Set the environment variable for the locale
ENV LANG et_EE.UTF-8

Third dockerfile:

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

And the compose itself:

---
- hosts: all
  become: yes
  tasks:
    - name: test docker-compose
      docker_compose:
        project_name: database
        remove_orphans: true
        definition:
          version: "3.7"
          services:
            db_test:
              image: postgres:15.3
              build:
                context: .
                dockerfile: Dockerfile
              shm_size: 1gb
              #container_name: local_pgdb
              restart: always
              ports:
                - "5432:5432"
              environment:
                POSTGRES_USER: 
                POSTGRES_PASSWORD:
                POSTGRES_MAX_CONNECTIONS: '400'
              volumes:
                - local_tst_pgdata:/var/lib/postgresql/data
            db_prelive:
              build:
                context: .
                dockerfile: Dockerfile
              image: postgres:15.3
              shm_size: 1gb
              #container_name: local_pgdb
              restart: always
              ports:
                - "5433:5432"
              environment:
                POSTGRES_USER:
                POSTGRES_PASSWORD: 
              volumes:
                - local_prelive_pgdata:/var/lib/postgresql/data

Anyone has ideas on where the mistake is, cuz after running the playbook, when i go into the container, using ssh to server hosting the docker and then docker exec to log into the container and do "locale -a" it only displays the en_US and not et_EE which i need?

To be clear, ansible output contains no info about the dockerfile, it contains the 3 lines in the dockerfile :

build:
  context: .
  dockerfile: Dockerfile

And that is all the informantion, even in verbose mode that it displays. Which is why i suspect it skips this step. Therefor i didnt paste that pile here. Other then rest of the compose ofc, compose itself works, the containers are created and the postgres in it is working flawlessly, its just the locale part that is defined in Dockerfile that it gives no info about, almost like it didnt see it.

So i have been trying to figure out for a week now on how to set locale inside my docker container postgres using dockerfile and so far with 0 success. The playbook itself does not fail but it also dosent do anything to resolve what the dockerfile tells it to do. Ive tried 3 different dockerfiles so far with various different ways to get it to work still all end up with same result of 0.

First dockerfile:

RUN apt-get update && apt-get install -y locales

RUN dpkg-reconfigure locales && \
  locale-gen C.UTF-8 && \
  /usr/sbin/update-locale LANG=C.UTF-8

RUN echo 'et_EE.UTF-8 UTF-8' >> /etc/locale.gen && \
  locale-gen

ENV LC_ALL C.UTF-8
ENV LANG et_EE.UTF-8
ENV LANGUAGE et_EE.UTF-8

Second dockerfile :

FROM postgres:15.3

# Install the locales package
RUN apt-get update && \
    apt-get install -y locales && \
    locale-gen et_EE.UTF-8 && \
    update-locale LANG=et_EE.UTF-8 && \
    apt-get clean && \ 
    rm -rf /var/lib/apt/lists/*

# Set the environment variable for the locale
ENV LANG et_EE.UTF-8

Third dockerfile:

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

And the compose itself:

---
- hosts: all
  become: yes
  tasks:
    - name: test docker-compose
      docker_compose:
        project_name: database
        remove_orphans: true
        definition:
          version: "3.7"
          services:
            db_test:
              image: postgres:15.3
              build:
                context: .
                dockerfile: Dockerfile
              shm_size: 1gb
              #container_name: local_pgdb
              restart: always
              ports:
                - "5432:5432"
              environment:
                POSTGRES_USER: 
                POSTGRES_PASSWORD:
                POSTGRES_MAX_CONNECTIONS: '400'
              volumes:
                - local_tst_pgdata:/var/lib/postgresql/data
            db_prelive:
              build:
                context: .
                dockerfile: Dockerfile
              image: postgres:15.3
              shm_size: 1gb
              #container_name: local_pgdb
              restart: always
              ports:
                - "5433:5432"
              environment:
                POSTGRES_USER:
                POSTGRES_PASSWORD: 
              volumes:
                - local_prelive_pgdata:/var/lib/postgresql/data

Anyone has ideas on where the mistake is, cuz after running the playbook, when i go into the container, using ssh to server hosting the docker and then docker exec to log into the container and do "locale -a" it only displays the en_US and not et_EE which i need?

To be clear, ansible output contains no info about the dockerfile, it contains the 3 lines in the dockerfile :

build:
  context: .
  dockerfile: Dockerfile

And that is all the informantion, even in verbose mode that it displays. Which is why i suspect it skips this step. Therefor i didnt paste that pile here. Other then rest of the compose ofc, compose itself works, the containers are created and the postgres in it is working flawlessly, its just the locale part that is defined in Dockerfile that it gives no info about, almost like it didnt see it.

Share edited Feb 10 at 14:03 Mairold Kunimägi asked Feb 10 at 13:26 Mairold KunimägiMairold Kunimägi 2131 gold badge5 silver badges12 bronze badges 4
  • 1 "...into the container" -- which one precisely and how? Please make sure you provide a minimal reproducible example, which includes all instructions for how to run it. Also, preferably provide the actual output you see, not just your interpretation, though in this case it's probably less important than usual. – Ulrich Eckhardt Commented Feb 10 at 13:40
  • Well the containers are both defined in the compose, test and prelive. And the dockerfile is added to both in the compose. So i figured its already cleared via the compose itself. I access it by SSH connecting to the rocky server and from there i use docker exec to log into the container. From which i can use shell command "locale -a". And when i say the ansible output gives nothing about this, i literally mean nothing, so theres nothing to paste here other then the usual finish of a playbook. Ok 3 changed 1. failed 0. Even with the verbose mode, nothing useful. – Mairold Kunimägi Commented Feb 10 at 13:49
  • 2 When you do combine build and image in a compose file, the image instructions does take precedence, so your builds are not done. – β.εηοιτ.βε Commented Feb 10 at 17:54
  • Thank you, that explains alot. This might be the reason. – Mairold Kunimägi Commented Feb 11 at 7:45
Add a comment  | 

1 Answer 1

Reset to default 0

So thanks to β.εηοιτ.βε in the comments, it was cleared, the error is that you cant have

image: postgres:15.3
          build:
            context: .
            dockerfile: Dockerfile    

image and build in the same compose or the image supercedes the build and therefor the build is ignored. I believe this is the mistake i have made. As of rn i dont know where the image should be, so i can not test it but im convinced this is the issue.

本文标签: Set locale in ansible managed dockercomposeStack Overflow