简体   繁体   English

Docker PostgreSQL - /docker-entrypoint-initdb.d中的脚本无法运行

[英]Docker PostgreSQL - Scripts in /docker-entrypoint-initdb.d doesn't run

So, I have a docker-compose project with this structure: 所以,我有一个具有这种结构的docker-compose项目:

DockerDev
- docker-compose.yaml
- d-php
  - Dockerfile
  - scripts-apache
- d-postgresql
  - Dockerfile
  - scripts
    - dev_data_setup.sql
- logs
- pgdata
- www

PHP, Redis, ElasticSearch is OK. PHP,Redis,ElasticSearch都行。 But Postgresql doesn't run dev_data_setup.sql, with any diferent solutions to /dockes-entrypoint-initdb.d that I found (volume, ADD, COPY, etc). 但Postgresql没有运行dev_data_setup.sql,我找到了/dockes-entrypoint-initdb.d的任何不同解决方案(volume,ADD,COPY等)。 I tried to run and sh script and nothing. 我试图运行和sh脚本,没有。

Could you see this docker-compose and Dockerfile and help me? 你能看到这个docker-compose和Dockerfile并帮助我吗? Thanks 谢谢

Dockerfile: Dockerfile:

FROM postgres:latest
ADD ./scripts/dev_data_setup.sql /docker-entrypoint-initdb.d

docker-compose.yaml: 泊坞窗,compose.yaml:

version: '2'
services:
  php:
    build: ./d-php/
    hostname: www.domain.com
    ports:
      - "80:80"
    volumes:
      - ./www:/var/www/html
      - ./d-php/scripts-apache2/apache2.conf:/etc/apache2/apache2.conf
      - ./d-php/scripts-apache2/web.conf:/etc/apache2/sites-enabled/web.conf
      - ./d-php/scripts-apache2/webservice.conf:/etc/apache2/sites-enabled/webservice.conf
      - ./logs:/var/log/apache2
    links:
      - db
      - redis
      - elasticsearch
  db:
    build: ./d-postgresql/
    volumes:
      - ./pgdata:/pgdata
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - PGDATA=/pgdata
  redis:
    image: redis:latest
  elasticsearch:
    image: elasticsearch:2.4.1

So I found the problem. 所以我发现了问题。

  • First: my sql script was trying to recreate postgres user. 第一:我的sql脚本试图重新创建postgres用户。 then, the dockedev_db exited. 然后,dockedev_db退出。
  • Second: I needed to remove all images related to db to docker-compose run the script again. 第二:我需要删除与db相关的所有图像到docker-compose再次运行脚本。

Thanks for your help. 谢谢你的帮助。

Your problem is caused by the way you use ADD in your Dockerfile: 您的问题是由您在Dockerfile中使用ADD的方式引起的:

FROM postgres:latest
ADD ./scripts/dev_data_setup.sql /docker-entrypoint-initdb.d

This creates a file called /docker-entrypoint-initdb.d with the content of the dev_data_setup.sql file. 这将创建一个名为/docker-entrypoint-initdb.d的文件,其中dev_data_setup.sql文件的内容。 What you want is to treat /docker-entrypoint-initdb.d as a directory. 你想要的是将/docker-entrypoint-initdb.d视为一个目录。

You should change your ADD command to one of the following: 您应该将ADD命令更改为以下之一:

ADD ./scripts/dev_data_setup.sql /docker-entrypoint-initdb.d/

The trailing slash will treat the dest parameter as a directory. 尾部斜杠将dest参数视为目录。 Or use 或者使用

ADD ./scripts/dev_data_setup.sql /docker-entrypoint-initdb.d/dev_data_setup.sql

Which will specifically spell out the file name. 其中将具体说明文件名。

Reference: https://docs.docker.com/engine/reference/builder/#/add 参考: https//docs.docker.com/engine/reference/builder/#/add

If <dest> does not end with a trailing slash, it will be considered a regular file and the contents of <src> will be written at <dest> . 如果<dest>不以尾部斜杠结束,则将其视为常规文件, <src>的内容将写入<dest>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 docker-entrypoint-initdb.d 脚本初始化 PostgreSQL 容器 - Initialize PostgreSQL Container with docker-entrypoint-initdb.d script docker alpine postgres在撰写中不执行docker-entrypoint-initdb.d脚本 - docker alpine postgres in compose not executing docker-entrypoint-initdb.d scripts docker-compose postgres 在 docker-entrypoint-initdb.d 中运行脚本后重新启动 - docker-compose postgres restart after running scripts in docker-entrypoint-initdb.d docker-entrypoint-initdb.d 中的 Docker PostgreSQL 初始化脚本无法导入文件 - Docker PostgreSQL initialisation script laced in docker-entrypoint-initdb.d’ fails to import file 如何解决空docker-entrypoint-initdb.d的问题? (PostgresQL + Docker) - How to solve problem with empty docker-entrypoint-initdb.d? (PostgresQL + Docker) 无法启动 PostgreSQL Docker 容器 – “'/docker-entrypoint-initdb.d/': 不允许操作” - Cannot start PostgreSQL Docker container – "'/docker-entrypoint-initdb.d/': Operation not permitted" docker-entrypoint-initdb.d/* 文件在 docker-compose 首次运行时被忽略 - docker-entrypoint-initdb.d/* files ignored on docker-compose first run Docker postgres 不在 docker-entrypoint-initdb.d 中运行 init 文件 - Docker postgres does not run init file in docker-entrypoint-initdb.d 初始化postgres数据库(不使用/docker-entrypoint-initdb.d) - Initialize postgres database (without using /docker-entrypoint-initdb.d) docker-entrypoint-initdb.d 错误解释器:权限被拒绝 - docker-entrypoint-initdb.d bad interpreter: Permission denied
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM