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

Installing via docker compose #5

Closed
damianmytek opened this issue Oct 5, 2020 · 10 comments
Closed

Installing via docker compose #5

damianmytek opened this issue Oct 5, 2020 · 10 comments

Comments

@damianmytek
Copy link

damianmytek commented Oct 5, 2020

Hi! Thank you very much for this project.
I am trying to install it on my server via docker compose. However I can't get this to work.
Could you point me in the right direction?

here is my log:

> db_1   | 
db_1   | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1   | 
db_1   | 2020-10-05 15:32:12.877 UTC [1] LOG:  starting PostgreSQL 13.0 (Debian 13.0-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1   | 2020-10-05 15:32:12.878 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1   | 2020-10-05 15:32:12.878 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1   | 2020-10-05 15:32:12.939 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1   | 2020-10-05 15:32:12.975 UTC [25] LOG:  database system was shut down at 2020-10-05 15:31:51 UTC
db_1   | 2020-10-05 15:32:12.995 UTC [1] LOG:  database system is ready to accept connections
web_1  | |> MIGRATE_AND_SEED
web_1  | |> Starting dependencies...
web_1  | |> Starting repos...
web_1  | 15:32:15.212 [error] MyXQL.Connection (#PID<0.217.0>) failed to connect: ** (DBConnection.ConnectionError) connection refused
web_1  | 15:32:15.212 [error] MyXQL.Connection (#PID<0.218.0>) failed to connect: ** (DBConnection.ConnectionError) connection refused
web_1  | 15:32:16.364 [error] MyXQL.Connection (#PID<0.217.0>) failed to connect: ** (DBConnection.ConnectionError) connection refused
web_1  | 15:32:17.981 [error] MyXQL.Connection (#PID<0.218.0>) failed to connect: ** (DBConnection.ConnectionError) connection refused
web_1  | 15:32:18.182 [error] Could not create schema migrations table. This error usually happens due to the following:
web_1  | 
web_1  |   * The database does not exist
web_1  |   * The "schema_migrations" table, which Ecto uses for managing
web_1  |     migrations, was defined by another library
web_1  |   * There is a deadlock while migrating (such as using concurrent
web_1  |     indexes with a migration_lock)
web_1  | 
web_1  | To fix the first issue, run "mix ecto.create".
web_1  | 
web_1  | To address the second, you can run "mix ecto.drop" followed by
web_1  | "mix ecto.create". Alternatively you may configure Ecto to use
web_1  | another table for managing migrations:
web_1  | 
web_1  |     config :mailgun_logger, MailgunLogger.Repo,
web_1  |       migration_source: "some_other_table_for_schema_migrations"
web_1  | 
web_1  | The full error report is shown below.
web_1  | 
web_1  | ** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2970ms. This means requests are coming in and your connection pool cannot serve them fast enough. You can address this by:
web_1  | 
web_1  |   1. By tracking down slow queries and making sure they are running fast enough
web_1  |   2. Increasing the pool_size (albeit it increases resource consumption)
web_1  |   3. Allow requests to wait longer by increasing :queue_target and :queue_interval
web_1  | 
web_1  | See DBConnection.start_link/2 for more information
web_1  | 
web_1  |     (ecto_sql 3.4.5) lib/ecto/adapters/sql.ex:593: Ecto.Adapters.SQL.raise_sql_call_error/1
web_1  |     (elixir 1.10.2) lib/enum.ex:1396: Enum."-map/2-lists^map/1-0-"/2
web_1  |     (ecto_sql 3.4.5) lib/ecto/adapters/sql.ex:686: Ecto.Adapters.SQL.execute_ddl/4
web_1  |     (ecto_sql 3.4.5) lib/ecto/migrator.ex:641: Ecto.Migrator.verbose_schema_migration/3
web_1  |     (ecto_sql 3.4.5) lib/ecto/migrator.ex:484: Ecto.Migrator.lock_for_migrations/4
web_1  |     (ecto_sql 3.4.5) lib/ecto/migrator.ex:406: Ecto.Migrator.run/4
web_1  |     (ecto_sql 3.4.5) lib/ecto/migrator.ex:149: Ecto.Migrator.with_repo/3
web_1  |     (mailgun_logger 0.0.4) lib/release_tasks.ex:51: anonymous fn/2 in JackJoe.ReleaseTasks._migrate/0
web_1  | 15:32:23.943 [info] [swarm on production@4be8c176bbca] [tracker:init] started
web_1  | 15:32:24.059 [error] MyXQL.Connection (#PID<0.3414.0>) failed to connect: ** (DBConnection.ConnectionError) connection refused
web_1  | 15:32:24.059 [error] MyXQL.Connection (#PID<0.3413.0>) failed to connect: ** (DBConnection.ConnectionError) connection refused
web_1  | 15:32:24.059 [error] MyXQL.Connection (#PID<0.3408.0>) failed to connect: ** (DBConnection.ConnectionError) connection refused
web_1  | 15:32:24.060 [error] MyXQL.Connection (#PID<0.3407.0>) failed to connect: ** (DBConnection.ConnectionError) connection refused
web_1  | 15:32:24.060 [error] MyXQL.Connection (#PID<0.3412.0>) failed to connect: ** (DBConnection.ConnectionError) connection refused
web_1  | 15:32:24.060 [error] MyXQL.Connection (#PID<0.3411.0>) failed to connect: ** (DBConnection.ConnectionError) connection refused
web_1  | 15:32:24.060 [error] MyXQL.Connection (#PID<0.3418.0>) failed to connect: ** (DBConnection.ConnectionError) connection refused
web_1  | 15:32:24.060 [error] MyXQL.Connection (#PID<0.3417.0>) failed to connect: ** (DBConnection.ConnectionError) connection refused
web_1  | 15:32:24.061 [error] MyXQL.Connection (#PID<0.3416.0>) failed to connect: ** (DBConnection.ConnectionError) connection refused
web_1  | 15:32:24.061 [error] MyXQL.Connection (#PID<0.3415.0>) failed to connect: ** (DBConnection.ConnectionError) connection refused
web_1  | 15:32:24.063 [info] Running MailgunLoggerWeb.Endpoint with cowboy 2.8.0 at 0.0.0.0:5050 (http)
web_1  | 15:32:24.064 [info] Access MailgunLoggerWeb.Endpoint at http://localhost
web_1  | 15:32:24.064 [debug] [:production@4be8c176bbca][Elixir.Quantum.JobBroadcaster] Loading Initial Jobs from Config
web_1  | 15:32:24.064 [debug] [:production@4be8c176bbca][Elixir.Quantum.ExecutionBroadcaster] Unknown last execution time, using now
web_1  | 15:32:24.064 [debug] [:production@4be8c176bbca][Elixir.Quantum.ExecutionBroadcaster] Adding job #Reference<0.912682946.2221932548.182105>
web_1  | 15:32:24.065 [debug] [:production@4be8c176bbca][Elixir.Quantum.ExecutionBroadcaster] Adding job #Reference<0.912682946.2221932548.182114>
web_1  | 15:32:24.065 [debug] [:production@4be8c176bbca][Elixir.Quantum.ExecutionBroadcaster] Continuing Execution Broadcasting at -576405090210 (2020-10-06T07:00:00)
web_1  | 15:32:25.429 [error] MyXQL.Connection (#PID<0.3413.0>) failed to connect: ** (DBConnection.ConnectionError) connection refused
web_1  | 15:32:25.495 [debug] Processing with MailgunLoggerWeb.PingController.ping/2
web_1  |   Parameters: %{}
web_1  |   Pipelines: [:ping]
web_1  | 15:32:25.953 [error] MyXQL.Connection (#PID<0.3408.0>) failed to connect: ** (DBConnection.ConnectionError) connection refused
web_1  | 15:32:25.994 [error] MyXQL.Connection (#PID<0.3417.0>) failed to connect: ** (DBConnection.ConnectionError) connection refused

Thank you!

EDIT: @damianmytek I just wrapped your log output into the backtick thing, I did not redact anything else.

@jeroenbourgois
Copy link
Member

jeroenbourgois commented Oct 5, 2020

@damianmytek I think there are some leftover bugs from our (very recent) migration from Postgres to MySQL. I will look into it asap and get back to you.

PS: I also updated our announcement article, have you tried following that?

@damianmytek
Copy link
Author

damianmytek commented Oct 5, 2020

Hi @jeroenbourgois thanks for getting back to me.
I updated docker-compose.yml:

version: "3"

services:
  db:
    image: mysql
    networks:
      - webnet
    environment:
      - MYSQL_PASSWORD=logger
      - MYSQL_USER=logger
      - MYSQL_DATABASE=mailgun_logger
      - MYSQL_RANDOM_ROOT_PASSWORD=yes
    volumes:
      - db_data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
      timeout: 5s
      retries: 10

  web:
    image: jackjoe/mailgun_logger
    depends_on:
      db:
        condition: service_healthy
    ports:
      - "5050:5050"
    networks:
      - webnet
    environment:
      ML_DB_USER: logger
      ML_DB_PASSWORD: logger
      ML_DB_NAME: mailgun_logger
      ML_DB_HOST: db

networks:
  webnet:
    external: false

volumes:
  db_data: {}

which is what i found in the announcement article.

Now i am getting this error:

ERROR: The Compose file './docker-compose.yml' is invalid because:
services.web.depends_on contains an invalid type, it should be an array

I am still learning on how to use docker so chances are that this is something on my end.
But i never run on the problem like this before.

I also tried deploying your package on a different server(synology with docker) but i am also getting errors.

Your project looks very interesting to me and i would love to test it.

Thanks,
Damian

@jeroenbourgois
Copy link
Member

@damianmytek ok, let's take this step by step. First, we need to address you docker-compose issue. I noticed that our readme was slightly different than the file we actually used, the 'ML_' env vars should be preceded with a dash. Here is the complete file again:

version: "3"

services:
  db:
    image: mysql
    networks:
      - webnet
    environment:
      - MYSQL_PASSWORD=logger
      - MYSQL_USER=logger
      - MYSQL_DATABASE=mailgun_logger
      - MYSQL_RANDOM_ROOT_PASSWORD=yes
    volumes:
      - db_data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
      timeout: 5s
      retries: 10

  web:
    image: jackjoe/mailgun_logger
    depends_on:
      db:
        condition: service_healthy
    ports:
      - "5050:5050"
    networks:
      - webnet
    environment:
      - ML_DB_USER: logger
      - ML_DB_PASSWORD: logger
      - ML_DB_NAME: mailgun_logger
      - ML_DB_HOST: db

networks:
  webnet:
    external: false

volumes:
  db_data: {}

Next, can you check the syntax by running docker-compose config? This should just output the yml file or show an error.

If that works we can continue from there.

@bmercernccer
Copy link

I'm also a docker newbie, and I'm having the same problem.
When I run docker-compose config with the yaml file provided above, I get this error:

localadmin@docker:~$ docker-compose config
ERROR: The Compose file './docker-compose.yml' is invalid because:
services.web.environment contains {"ML_DB_USER": "logger"}, which is an invalid type, it should be a string
services.web.depends_on contains an invalid type, it should be an array

I noticed that the syntax of the web environment was different from that of the db environment, so I tried changing

    environment:
      - ML_DB_USER: logger
      - ML_DB_PASSWORD: logger
      - ML_DB_NAME: mailgun_logger
      - ML_DB_HOST: db

to

    environment:
      - ML_DB_USER=logger
      - ML_DB_PASSWORD=logger
      - ML_DB_NAME=mailgun_logger
      - ML_DB_HOST=db

and that fixed the first part of the error. But I'm still getting

services.web.depends_on contains an invalid type, it should be an array

I noticed this in the documentation for depends_on...

There are several things to be aware of when using depends_on:

  • depends_on does not wait for db and redis to be “ready” before starting web - only until they have been started. If you need to wait for a service to be ready, see Controlling startup order for more on this problem and strategies for solving it.
  • Version 3 no longer supports the condition form of depends_on.
  • The depends_on option is ignored when deploying a stack in swarm mode with a version 3 Compose file.

https://docs.docker.com/compose/compose-file/

I assume this is probably the cause, but I have no idea how to correct it.

@bmercernccer
Copy link

I tried simply removing the condition clause from depends_on and that resolved the error, but I'm now having a variety of other errors. It seems the provided config has issues.

@jeroenbourgois
Copy link
Member

@bmercernccer I will get back to you asap, I will first get the suggested docker file myself. Can you tell me which version of docker you are using?

@bmercernccer
Copy link

I'm using 19.03.13.

I was finally able to get the logger running, but had to make several changes.
Here's what I had to do.

  1. change the syntax of the web environment as mentioned previously.
  2. I completely removed the condition clause from web: depends-on. It works, but it doesn't fail gracefully if there's a DB issue, which caused some other problems for me.
  3. The container kept failing to start. Eventually I identified it as due to database errors, which I think were due to not waiting for the DB to fully start. Eventually I was able to get past this by repeatedly restarting the container until I got lucky.
  4. Once the service was running, I got timeout errors while actually retrieving the logs. I couldn't find a way to change this in the YAML config, so after a lot of googling and reading, I figured that I needed to change the timeout in the image.

I edited /opt/app/releases/0.0.4/runtime.exs. and added longer timeouts. I had no idea which one was correct so I just put all three of them in there.

Here's the final runtime.exs...

config :mailgun_logger, MailgunLogger.Repo,
  username: System.get_env("ML_DB_USER"),
  password: System.get_env("ML_DB_PASSWORD"),
  database: System.get_env("ML_DB_NAME"),
  hostname: System.get_env("ML_DB_HOST"),
  ownership_timeout: 120_000,
  timeout: 120_000,
  pool_timeout: 120_000

I then exited the shell and committed the change to a new image I called updated-mailgun_logger.
Then I updated the config and started the container, and it worked.

Here's the final docker-compose.yaml file...

version: "3"

services:
  db:
    image: mysql
    networks:
      - webnet
    environment:
      - MYSQL_PASSWORD=logger
      - MYSQL_USER=logger
      - MYSQL_DATABASE=mailgun_logger
      - MYSQL_RANDOM_ROOT_PASSWORD=yes
    volumes:
      - db_data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
      timeout: 5s
      retries: 10

  web:
    image: updated-mailgun_logger
    depends_on:
      - db
    ports:
      - "5050:5050"
    networks:
      - webnet
    environment:
      - ML_DB_USER=logger
      - ML_DB_PASSWORD=logger
      - ML_DB_NAME=mailgun_logger
      - ML_DB_HOST=db

networks:
  webnet:
    external: false

volumes:
  db_data: {}

Hopefully this helps.

@jeroenbourgois
Copy link
Member

jeroenbourgois commented Oct 20, 2020

@bmercernccer thanks so much for your input. I updated the Docker image to have a wait-for program, in order for the web container to successfully wait for the db container. Your input regarding the docker-compose version was very helpful.

I tested it on my local machine with the updated docker-compose file, and it ran smoothly. Could you check again. For reference, here is the updated syntax, which also can be found in the readme file:

version: "3"

services:
  db:
    image: mysql
    networks:
      - webnet
    environment:
      - MYSQL_PASSWORD=logger
      - MYSQL_USER=logger
      - MYSQL_DATABASE=mailgun_logger
      - MYSQL_RANDOM_ROOT_PASSWORD=yes
    volumes:
      - db_data:/var/lib/mysql

  web:
    image: jackjoe/mailgun_logger
    depends_on:
      - db
    entrypoint: ["./wait-for", "db:3306", "--", "./start.sh"]
    ports:
      - "5050:5050"
    networks:
      - webnet
    environment:
      - ML_DB_USER=logger
      - ML_DB_PASSWORD=logger
      - ML_DB_NAME=mailgun_logger
      - ML_DB_HOST=db

networks:
  webnet:
    external: false

volumes:
  db_data: {}

Main difference is the entrypoint line for the web container. Love to hear your input.

PS

[REDACTED AFTER INPUT FROM @bmercernccer FOR FUTURE REFERENCE]

Be sure to update the jackjoe/mailgun-logger image before running docker-compose again. I just ran this first:

Be sure to update the jackjoe/mailgun_logger image before running docker-compose again. I just ran this first:

docker pull jackjoe/mailgun_logger

@bmercernccer
Copy link

Thanks for the update. I was finally able to get back to this today. At first I had some issues updating the image, but then I realized there's a typo in the instructions. The update command should have an underscore.
docker pull jackjoe/mailgun_logger

Once I figured that out I was able to update the image and everything fired up without issue.

My logger is now up and running. I'm having some other problems, but they're unrelated to this issue, so I think it can be considered resolved.

@jeroenbourgois
Copy link
Member

@bmercernccer thank you for bearing with us! I updated the instructions in the readme. Since you posted your issue, we started 'dogfooding' the same public docker image for a client of ours, so most bugs should be polished out now.

Happy logging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants