1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Docker for Windows で postgresのコンテナが起動できない

Posted at

Docker for Windows で laradockのデータベースをpostgresにしたところ、うまくできない場合・・・

psqlで接続できない・・・

laradockを利用して、postgresにデータベースを作成する為に

docker-compose exec workspace psql -U default -h postgres

を実行したところ、以下のエラー

psql: could not translate host name "postgres" to address: No address associated with hostname

そもそもコンテナが起動してない・・・

docker ps してコンテナを確認すると、postgresは起動していない
docker-compose up -d で特にエラーが出ていなかったのだが・・・

docker ps

CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS                    NAMES
1370b45bf0b5        nginx:alpine            "/docker-entrypoint.…"   40 minutes ago      Up 10 seconds       0.0.0.0:8082->80/tcp     laravel-sns_nginx_1
e92f90d8dd0f        laravel-sns_php-fpm     "docker-php-entrypoi…"   6 days ago          Up 12 seconds       0.0.0.0:9000->9000/tcp   laravel-sns_php-fpm_1
4fc742fdaba5        laravel-sns_workspace   "docker-php-entrypoi…"   6 days ago          Up 12 seconds       9000/tcp                 laravel-sns_workspace_1

laradockディレクトリ内の.env は永続化OK

DATA_PATH_HOST=../data

.envのDATA_PATH_HOSTがデフォルトの状態だとエラーになるという記事がヒットするが、私の環境は変更済み

はて?

解決!!!

laradockディレクトリのdocker-compose.yml を変更する事で解決しました!

  postgres:
    image: postgres:${POSTGRES_VERSION}-alpine
    depends_on:
      - php-fpm
    ports:
      - ${POSTGRES_PORT}:5432
    volumes:
#      - ${DATA_PATH_HOST}/postgres:/var/lib/postgresql/data   #変更前
      - ${DATA_PATH_HOST}/postgres:/var/lib/postgresql   #変更後
    environment:

vokumesのディレクトリ指定で最後のdataを削除

これで、再度、コンテナを起動

docker-compose up -d workspace php-fpm nginx postgres
Starting laravel-sns_workspace_1  ... done                                                                           Starting laravel-sns_php-fpm_1   ... done                                                                            Starting laravel-sns_nginx_1      ... done                                                                           Recreating laravel-sns_postgres_1 ... done  

でコンテナを確認

 docker ps
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS                    NAMES
07773a4cbf64        postgres:11.6-alpine    "docker-entrypoint.s…"   6 seconds ago       Up 4 seconds        0.0.0.0:5432->5432/tcp   laravel-sns_postgres_1
1370b45bf0b5        nginx:alpine            "/docker-entrypoint.…"   44 minutes ago      Up 4 seconds        0.0.0.0:8082->80/tcp     laravel-sns_nginx_1
e92f90d8dd0f        laravel-sns_php-fpm     "docker-php-entrypoi…"   6 days ago          Up 6 seconds        0.0.0.0:9000->9000/tcp   laravel-sns_php-fpm_1
4fc742fdaba5        laravel-sns_workspace   "docker-php-entrypoi…"   6 days ago          Up 6 seconds        9000/tcp                 laravel-sns_workspace_1

無事にpostgresを起動できました!

しかし、同じ環境でmacのdockerだと問題なく動くのに、Docker for Windowsだと動かない原因までは追っていません!

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?