2

I'm running my CI from within a docker container with docker installed. Inside that docker container, I'm running docker-compose with a postgres database. Even though the postgres database has fully started, I can't access it at localhost:8090, like I should be able to.

I'm using the container syntax to run my github actions in a container. (tilt is running docker-compose for me) i.e.:

  build-tilt:
    name: Build Tilt
    runs-on: [ self-hosted, docker ]
    container:
      image: devitllc/coretto-build:17

    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Tilt CI
        run: tilt ci --timeout 15m --debug

docker-compose.yml:

version: "3.9"
services:

  postgres:
    image: postgres:14
    ports:
      - "8090:5432"
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: test
      POSTGRES_DB: example
    volumes:
      - example-postgres:/var/lib/postgresql/data
    deploy:
      resources:
        limits:
          memory: 1g
    healthcheck:
      test: CMD pg_isready -U postgres
      interval: 5s
      timeout: 5s
      retries: 10

I've tried accessing it at postgres as well, and I'm unsure what I'm doing wrong. Perhaps I need to do something with networks? I don't have enough docker experience with networks to know what I should be doing.

I'm running multiple github actions runners from a single computer, so ideally nothing would be exposed outside of the container I'm using to run my container in.

EDIT: An example reproducing the failure, is here: https://github.com/ScottPierce/DockerInDockerNetworkingError

The CI logs are here: https://github.com/ScottPierce/DockerInDockerNetworkingError/actions Notice that it succeeds when it's not docker-in-docker.

spierce7
  • 14,797
  • 13
  • 65
  • 106
  • There is only one service i.e. `postgres` in your `docker-compose.yml` file, how are you accessing it in your workflow? Please include that in your workflow. Also, I believe this is the container that you're using i.e. [devitllc/coretto-build:17](https://hub.docker.com/layers/devitllc/coretto-build/17/images/sha256-925ce564d7d88244b2c54df267d4b5ad50b194857c8afdf0eb282362839c48e0?context=explore), right? – Azeem Feb 25 '23 at 05:48
  • Technically there is a MySQL service also, but I’m not trying to access that right now. I’m accessing Postgres via localhost:8090 in my corretto-build container. – spierce7 Feb 25 '23 at 13:50
  • @Azeem Yes corretto-build is just a container that has tilt , Java, docker, etc installed. – spierce7 Feb 25 '23 at 13:52
  • Right. And, the `tilt ci` command automatically fires up the `docker-compose` as there's no `docker-compose up` in your workflow? – Azeem Feb 25 '23 at 13:55
  • Right. Also the process I’m trying to access Postgres from via localhost:8090 is running in the corretto-build container – spierce7 Feb 25 '23 at 13:56
  • Right. Then, the only thing I see missing is the network configuration in your `docker-compose.yml` file i.e. `network_mode: "host"`. – Azeem Feb 25 '23 at 14:00
  • if I use `network_mode: "host"`, will I be able to run this command from multiple runners at the same time? 10 github runners on one large machine. – spierce7 Feb 25 '23 at 14:10
  • I put `network_mode: "host"` in the docker-compose file underneath the `volumes` block. Same results. `Exception in thread "main" com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Connection to localhost:8090 refused.` – spierce7 Feb 25 '23 at 14:18
  • If you could add a minimal, reproducible example in your question, I'd be able to test it on my side and suggest accordingly. – Azeem Feb 25 '23 at 14:25
  • 1
    @Azeem I created a sample showing the failure here: https://github.com/ScottPierce/CiNetworkingIssue – spierce7 Feb 25 '23 at 15:23
  • I've removed tilt from the example, so it's just docker-compose now. – spierce7 Feb 25 '23 at 16:06

0 Answers0