Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev container does not support custom DB ports #60

Open
4 tasks done
yamcodes opened this issue Oct 16, 2023 · 1 comment · May be fixed by #71
Open
4 tasks done

Dev container does not support custom DB ports #60

yamcodes opened this issue Oct 16, 2023 · 1 comment · May be fixed by #71
Assignees
Labels
bug Something isn't working devcontainers Relates to dev containers.

Comments

@yamcodes
Copy link
Contributor

Version

latest

Describe the bug

The devcontainer does not support changing the DB port to something other than 5432.

Reproduction

  1. Occupy port 5432 with something.
  2. Change the DB port to 5431 in .env.
  3. Rebuild the devcontainer.
  4. You will get an ECONREFUSED error in the console.

System Info

Macbook Air M2

Validations

@yamcodes yamcodes added bug Something isn't working devcontainers Relates to dev containers. labels Oct 16, 2023
@Hajbo
Copy link
Collaborator

Hajbo commented Oct 18, 2023

Wait, isn't this because of how we do the port mapping in docker compose? It looks like this:

    ports:
      - ${POSTGRES_PORT}:5432

which means if you update the .env file, then the 5432 port inside the container will be mapped to a different port in your host machine. But the problem is that the app will try to connect to POSTGRES_PORT inside the container, because it's using that env var.

I think something like this would solve it:

    ports:
      - ${POSTGRES_PORT}:${POSTGRES_PORT}

& we need to add the POSGRES_PORT env var to the environment key too:

db:
    image: postgres:16
    restart: unless-stopped
    volumes:
      - postgres-data:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=${POSTGRES_DB}
      - POSTGRES_PORT=${POSTGRES_PORT}
    healthcheck:
      test:
        [
          "CMD",
          "pg_isready",
          "-U",
          "${POSTGRES_USER}",
        ]
      interval: 5s
      timeout: 30s
      retries: 10
    # This allows accessing externally from "localhost" in addition to "127.0.0.1"
    ports:
      - ${POSTGRES_PORT}:${POSTGRES_PORT}

@Hajbo Hajbo linked a pull request Oct 18, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working devcontainers Relates to dev containers.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants