Rasa x server keep restarting in Centos 8.2 - docker

I want to deploy rasa-x on my linux machine. I have used docker-compose to deploy:
Here is my docker-compose file:
version: "3.4"
x-database-credentials: &database-credentials
DB_HOST: "db"
DB_PORT: "5432"
DB_USER: "${DB_USER:-admin}"
DB_PASSWORD: "${DB_PASSWORD}"
DB_LOGIN_DB: "${DB_LOGIN_DB:-rasa}"
x-rabbitmq-credentials: &rabbitmq-credentials
RABBITMQ_HOST: "rabbit"
RABBITMQ_USERNAME: "user"
RABBITMQ_PASSWORD: ${RABBITMQ_PASSWORD}
x-redis-credentials: &redis-credentials
REDIS_HOST: "redis"
REDIS_PORT: "6379"
REDIS_PASSWORD: ${REDIS_PASSWORD}
REDIS_DB: "1"
x-duckling-credentials: &duckling-credentials
RASA_DUCKLING_HTTP_URL: "http://duckling:8000"
x-rasax-credentials: &rasax-credentials
RASA_X_HOST: "http://rasa-x:5006"
RASA_X_USERNAME: ${RASA_X_USERNAME:-admin}
RASA_X_PASSWORD: ${RASA_X_PASSWORD:-}
RASA_X_TOKEN: ${RASA_X_TOKEN}
JWT_SECRET: ${JWT_SECRET}
RASA_USER_APP: "http://app:5056"
RASA_PRODUCTION_HOST: "http://rasa-production:5006"
RASA_WORKER_HOST: "http://rasa-worker:5006"
RASA_TOKEN: ${RASA_TOKEN}
x-rasa-credentials: &rasa-credentials
<<: *rabbitmq-credentials
<<: *rasax-credentials
<<: *database-credentials
<<: *redis-credentials
<<: *duckling-credentials
RASA_TOKEN: ${RASA_TOKEN}
RASA_MODEL_PULL_INTERVAL: 10
RABBITMQ_QUEUE: "rasa_production_events"
x-rasa-services: &default-rasa-service
restart: always
image: "rasa/rasa:${RASA_VERSION}-full"
expose:
- "5006"
command: >
x
--no-prompt
--production
--config-endpoint http://rasa-x:5006/api/config?token=${RASA_X_TOKEN}
--port 5006
--jwt-method HS256
--jwt-secret ${JWT_SECRET}
--auth-token '${RASA_TOKEN}'
--cors "*"
depends_on:
- rasa-x
- rabbit
- redis
services:
rasa-x:
restart: on-failure
image: "rasa/rasa-x:${RASA_X_VERSION}"
ports:
- "5006:5006"
volumes:
- ./models:/app/models
- ./environments.yml:/app/environments.yml
- ./credentials.yml:/app/credentials.yml
- ./endpoints.yml:/app/endpoints.yml
- ./logs:/logs
- ./auth:/app/auth
environment:
<<: *database-credentials
<<: *rasa-credentials
SELF_PORT: "5006"
DB_DATABASE: "${DB_DATABASE:-rasa}"
RASA_MODEL_DIR: "/app/models"
PASSWORD_SALT: ${PASSWORD_SALT}
RABBITMQ_QUEUE: "rasa_production_events"
RASA_X_USER_ANALYTICS: "0"
SANIC_RESPONSE_TIMEOUT: "3600"
depends_on:
- db
rasa-production:
<<: *default-rasa-service
environment:
<<: *rasa-credentials
RASA_ENVIRONMENT: "production"
DB_DATABASE: "tracker"
RASA_MODEL_SERVER: "http://rasa-x:5006/api/projects/default/models/tags/production"
rasa-worker:
<<: *default-rasa-service
environment:
<<: *rasa-credentials
RASA_ENVIRONMENT: "worker"
DB_DATABASE: "worker_tracker"
RASA_MODEL_SERVER: "http://rasa-x:5006/api/projects/default/models/tags/production"
app:
restart: always
image: "rasa/rasa-x-demo:${RASA_X_DEMO_VERSION}"
expose:
- "5056"
depends_on:
- rasa-production
db:
restart: on-failure
image: "bitnami/postgresql:11.7.0"
user: '1005'
expose:
- "5432"
environment:
POSTGRESQL_USERNAME: "${DB_USER:-admin}"
POSTGRESQL_PASSWORD: "${DB_PASSWORD}"
POSTGRESQL_DATABASE: "${DB_DATABASE:-rasa}"
volumes:
- ./db:/bitnami/postgresql
rabbit:
restart: always
image: "bitnami/rabbitmq:3.8.3"
environment:
RABBITMQ_HOST: "rabbit"
RABBITMQ_USERNAME: "user"
RABBITMQ_PASSWORD: ${RABBITMQ_PASSWORD}
RABBITMQ_DISK_FREE_LIMIT: "{mem_relative, 0.1}"
expose:
- "5672"
duckling:
restart: always
image: "rasa/duckling:0.1.6.3"
expose:
- "8000"
command: ["duckling-example-exe", "--no-access-log", "--no-error-log"]
nginx:
restart: always
image: "rasa/nginx:${RASA_X_VERSION}"
ports:
- "8080:8080"
- "443:8443"
volumes:
- ./certs:/opt/bitnami/certs
- ./terms:/opt/bitnami/nginx/conf/bitnami/terms
depends_on:
- rasa-x
- rasa-production
- app
redis:
restart: always
image: "bitnami/redis:5.0.8"
environment:
REDIS_PASSWORD: ${REDIS_PASSWORD}
expose:
- "6379"
This is the logs of db:
| postgresql 12:36:50.30 Welcome to the Bitnami postgresql container
db_1 | postgresql 12:36:50.30 Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-postgresql
db_1 | postgresql 12:36:50.31 Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-postgresql/issues
db_1 | postgresql 12:36:50.31
db_1 | postgresql 12:36:50.85 INFO ==> ** Starting PostgreSQL setup **
db_1 | postgresql 12:36:51.75 INFO ==> Validating settings in POSTGRESQL_* env vars..
db_1 | postgresql 12:36:51.76 INFO ==> Loading custom pre-init scripts...
db_1 | postgresql 12:36:51.99 INFO ==> Initializing PostgreSQL database...
db_1 | postgresql 12:36:52.37 INFO ==> postgresql.conf file not detected. Generating it...
db_1 | postgresql 12:36:52.55 INFO ==> pg_hba.conf file not detected. Generating it...
db_1 | postgresql 12:36:52.60 INFO ==> Generating local authentication configuration
db_1 | postgresql 12:37:13.50 INFO ==> Starting PostgreSQL in background...
db_1 | postgresql 12:37:17.77 INFO ==> Creating user admin
db_1 | postgresql 12:37:17.87 INFO ==> Granting access to "admin" to the database "rasa"
db_1 | postgresql 12:37:18.25 INFO ==> Configuring replication parameters
db_1 | postgresql 12:37:18.43 INFO ==> Configuring fsync
db_1 | postgresql 12:37:18.49 INFO ==> Loading custom scripts...
db_1 | postgresql 12:37:18.53 INFO ==> Enabling remote connections
db_1 | postgresql 12:37:18.62 INFO ==> Stopping PostgreSQL...
db_1 | postgresql 12:37:19.87 INFO ==> ** PostgreSQL setup finished! **
db_1 |
db_1 | postgresql 12:37:22.12 INFO ==> ** Starting PostgreSQL **
db_1 | 2020-09-03 12:37:22.716 GMT [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2020-09-03 12:37:22.717 GMT [1] LOG: listening on IPv6 address "::", port 5432
db_1 | 2020-09-03 12:37:22.733 GMT [1] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
db_1 | 2020-09-03 12:37:22.805 GMT [211] LOG: database system was shut down at 2020-09-03 12:37:18 GMT
db_1 | 2020-09-03 12:37:22.828 GMT [1] LOG: database system is ready to accept connections
The db is connected
This is the logs of rasa-x:
asa-x_1 | Traceback (most recent call last):
rasa-x_1 | File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 2339, in _wrap_pool_connect
rasa-x_1 | return fn()
rasa-x_1 | File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 304, in unique_connection
rasa-x_1 | return _ConnectionFairy._checkout(self)
rasa-x_1 | File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 778, in _checkout
rasa-x_1 | fairy = _ConnectionRecord.checkout(pool)
rasa-x_1 | File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 495, in checkout
rasa-x_1 | rec = pool._do_get()
rasa-x_1 | File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 140, in _do_get
rasa-x_1 | self._dec_overflow()
rasa-x_1 | File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 69, in __exit__
rasa-x_1 | exc_value, with_traceback=exc_tb,
rasa-x_1 | File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
rasa-x_1 | raise exception
rasa-x_1 | File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/impl.py", line 137, in _do_get
rasa-x_1 | return self._create_connection()
rasa-x_1 | File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 309, in _create_connection
rasa-x_1 | return _ConnectionRecord(self)
rasa-x_1 | File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 440, in __init__
rasa-x_1 | self.__connect(first_connect_check=True)
rasa-x_1 | File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 661, in __connect
rasa-x_1 | pool.logger.debug("Error on connect(): %s", e)
rasa-x_1 | File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 69, in __exit__
rasa-x_1 | exc_value, with_traceback=exc_tb,
rasa-x_1 | File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
rasa-x_1 | raise exception
rasa-x_1 | File "/usr/local/lib/python3.7/site-packages/sqlalchemy/pool/base.py", line 656, in __connect
rasa-x_1 | connection = pool._invoke_creator(self)
rasa-x_1 | File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/strategies.py", line 114, in connect
rasa-x_1 | return dialect.connect(*cargs, **cparams)
rasa-x_1 | File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 493, in connect
rasa-x_1 | return self.dbapi.connect(*cargs, **cparams)
rasa-x_1 | File "/usr/local/lib/python3.7/site-packages/psycopg2/__init__.py", line 127, in connect
rasa-x_1 | conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
rasa-x_1 | psycopg2.OperationalError: could not connect to server: No route to host
rasa-x_1 | Is the server running on host "db" (172.18.0.5) and accepting
rasa-x_1 | TCP/IP connections on port 5432?
rasa-x_1 |
Any help would be very very appreciated.
Rasa x server keep restarting, I dont know the exact issues.
I am using CentOS 8 as If i run this docker-compose on windows it run fine.

Related

Elastic Search connection refused with Docker Compose (connect ECONNREFUSED )

There are multiple services that I had been trying to run (redis, front-end, back-end and elastic-search) and I was not able to connect to the elastic search service. I even tried giving a static ip for the service. (The networking part is currently commented out in the docker file attached). I tried changing the images and it still was not working.
When I tested ES locally using curl localhost:9200/_cat/health as I have mapped the container port locally it gives me that the cluster is green. I could connect to the other services like redis without issues. As with redis, I am using the service name, elasticsearch to connect it to the back-end service. Following is my docker-compose.yml file.
version: '3'
services:
arc-external:
image: arc-external
build:
context: ./arc-development-branch/arc-external
ports:
- '4201:4201'
# networks:
# - vpcbr
redis:
image: redis:3.2.11-alpine
ports:
- '6379:6379'
# networks:
# - vpcbr
elasticsearch:
image: elasticsearch:2
ports:
- '9200:9200'
- '9300:9300'
environment:
- node.name=elasticsearch
- cluster.name=datasearch
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- cluster.initial_master_nodes=elasticsearch
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./data/elastic:/usr/share/elasticsearch/data
# networks:
# vpcbr:
# ipv4_address: 10.5.0.4
api-external:
image: api-external
build: .
ports:
- '3001:3001'
depends_on:
- redis
- elasticsearch
# networks:
# - vpcbr
# networks:
# vpcbr:
# driver: bridge
# ipam:
# config:
# - subnet: 10.5.0.0/16
# gateway: 10.5.0.1
This is the exact error that I am getting when running docker compose-up
api-external_1 | 2021-03-09 20:41:46.3253 - info: Finished setting up log directories
api-external_1 | 2021-03-09 20:41:46.3514 - info: Connection successful to mongodb # mongodb://10.0.0.44:27017/arc
api-external_1 | 2021-03-09 20:41:46.3764 - info: Connection successful to redis at: host: redis port: 6379
api-external_1 | Elasticsearch ERROR: 2021-03-09T20:41:46Z
api-external_1 | Error: Request error, retrying
api-external_1 | HEAD http://elasticsearch:9200/ => connect ECONNREFUSED 172.24.0.4:9200
api-external_1 | at Log.error (/usr/src/app/api-external/node_modules/elasticsearch/src/lib/log.js:226:56)
api-external_1 | at checkRespForFailure (/usr/src/app/api-external/node_modules/elasticsearch/src/lib/transport.js:259:18)
api-external_1 | at HttpConnector.<anonymous> (/usr/src/app/api-external/node_modules/elasticsearch/src/lib/connectors/http.js:164:7)
api-external_1 | at ClientRequest.wrapper (/usr/src/app/api-external/node_modules/lodash/lodash.js:4935:19)
api-external_1 | at ClientRequest.emit (events.js:198:13)
api-external_1 | at ClientRequest.EventEmitter.emit (domain.js:448:20)
api-external_1 | at Socket.socketErrorListener (_http_client.js:401:9)
api-external_1 | at Socket.emit (events.js:198:13)
api-external_1 | at Socket.EventEmitter.emit (domain.js:448:20)
api-external_1 | at emitErrorNT (internal/streams/destroy.js:91:8)
api-external_1 | at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
api-external_1 | at process._tickCallback (internal/process/next_tick.js:63:19)
api-external_1 |
api-external_1 | Elasticsearch WARNING: 2021-03-09T20:41:46Z
api-external_1 | Unable to revive connection: http://elasticsearch:9200/
api-external_1 |
api-external_1 | Elasticsearch WARNING: 2021-03-09T20:41:46Z
api-external_1 | No living connections
api-external_1 |
api-external_1 | 2021-03-09 20:41:46.3844 - error: Error: Failed to connect to elasticsearch # elasticsearch:9200
api-external_1 | at exports.esClient.ping (/usr/src/app/api-external/dist/setup/elastic-search.js:33:46)
api-external_1 | at respond (/usr/src/app/api-external/node_modules/elasticsearch/src/lib/transport.js:327:9)
api-external_1 | at sendReqWithConnection (/usr/src/app/api-external/node_modules/elasticsearch/src/lib/transport.js:226:7)
api-external_1 | at next (/usr/src/app/api-external/node_modules/elasticsearch/src/lib/connection_pool.js:214:7)
api-external_1 | at process._tickCallback (internal/process/next_tick.js:61:11)
api-external_1 | 2021-03-09 20:41:46.3854 - error: Error: No Living connections
api-external_1 | at sendReqWithConnection (/usr/src/app/api-external/node_modules/elasticsearch/src/lib/transport.js:226:15)
api-external_1 | at next (/usr/src/app/api-external/node_modules/elasticsearch/src/lib/connection_pool.js:214:7)
api-external_1 | at process._tickCallback (internal/process/next_tick.js:61:11)
api-external_1 | npm ERR! code ELIFEC
Frankly, I searched a lot and were not able to debug it. Any help would be appreciated.
I was able to figure out the answer. The thing stating as depends_on does not wait the services to completely up. Here, api-external does get start up as soon as the redis and elasticsearch starts. However, elasticsearch need a bit time to configure everything so restarting the service will do the trick.
More permanent solution is to write a script that would wait until the elasticsearch is up completely before starting the api-external service

Docker - Celery cannot connect to redis

Project structure:
client
nginx
web/
celery_worker.py
project
config.py
api/
I have the following services in my docker-compose:
version: '3.6'
services:
web:
build:
context: ./services/web
dockerfile: Dockerfile-dev
volumes:
- './services/web:/usr/src/app'
ports:
- 5001:5000
environment:
- FLASK_ENV=development
- APP_SETTINGS=project.config.DevelopmentConfig
- DATABASE_URL=postgres://postgres:postgres#web-db:5432/web_dev
- DATABASE_TEST_URL=postgres://postgres:postgres#web-db:5432/web_test
- SECRET_KEY=my_precious
depends_on:
- web-db
- redis
celery:
image: dev3_web
restart: always
volumes:
- ./services/web:/usr/src/app
- ./services/web/logs:/usr/src/app
command: celery worker -A celery_worker.celery --loglevel=INFO -Q cache
environment:
- CELERY_BROKER=redis://redis:6379/0
- CELERY_RESULT_BACKEND=redis://redis:6379/0
depends_on:
- web
- redis
links:
- redis:redis
redis:
image: redis:5.0.3-alpine
restart: always
expose:
- '6379'
ports:
- '6379:6379'
monitor:
image: dev3_web
ports:
- 5555:5555
command: flower -A celery_worker.celery --port=5555 --broker=redis://redis:6379/0
depends_on:
- web
- redis
web-db:
build:
context: ./services/web/project/db
dockerfile: Dockerfile
ports:
- 5435:5432
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
nginx:
build:
context: ./services/nginx
dockerfile: Dockerfile-dev
restart: always
ports:
- 80:80
- 8888:8888
depends_on:
- web
- client
- redis
client:
build:
context: ./services/client
dockerfile: Dockerfile-dev
volumes:
- './services/client:/usr/src/app'
- '/usr/src/app/node_modules'
ports:
- 3007:3000
environment:
- NODE_ENV=development
- REACT_APP_WEB_SERVICE_URL=${REACT_APP_WEB_SERVICE_URL}
depends_on:
- web
- redis
CELERY LOG
However, celery is not being able to connect, from this log:
celery_1 | [2019-03-29 03:09:32,111: ERROR/MainProcess] consumer: Cannot connect to redis://localhost:6379/0: Error 99 connecting to localhost:6379. Address not available..
celery_1 | Trying again in 2.00 seconds...
WEB LOG
and so is not web service (running the backend), by the same log:
web_1 | Waiting for postgres...
web_1 | PostgreSQL started
web_1 | * Environment: development
web_1 | * Debug mode: on
web_1 | * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
web_1 | * Restarting with stat
web_1 | * Debugger is active!
web_1 | * Debugger PIN: 316-641-271
web_1 | 172.21.0.9 - - [29/Mar/2019 03:03:17] "GET /users HTTP/1.0" 200 -
web_1 | 172.21.0.9 - - [29/Mar/2019 03:03:26] "POST /auth/register HTTP/1.0" 500 -
web_1 | Traceback (most recent call last):
web_1 | File "/usr/lib/python3.6/site-packages/redis/connection.py", line 492, in connect
web_1 | sock = self._connect()
web_1 | File "/usr/lib/python3.6/site-packages/redis/connection.py", line 550, in _connect
web_1 | raise err
web_1 | File "/usr/lib/python3.6/site-packages/redis/connection.py", line 538, in _connect
web_1 | sock.connect(socket_address)
web_1 | OSError: [Errno 99] Address not available
web_1 |
web_1 | During handling of the above exception, another exception occurred:
web_1 |
web_1 | Traceback (most recent call last):
web_1 | File "/usr/lib/python3.6/site-packages/kombu/connection.py", line 431, in _reraise_as_library_errors
web_1 | yield
web_1 | File "/usr/lib/python3.6/site-packages/celery/app/base.py", line 744, in send_task
web_1 | self.backend.on_task_call(P, task_id)
web_1 | File "/usr/lib/python3.6/site-packages/celery/backends/redis.py", line 265, in on_task_call
web_1 | self.result_consumer.consume_from(task_id)
web_1 | File "/usr/lib/python3.6/site-packages/celery/backends/redis.py", line 125, in consume_from
web_1 | return self.start(task_id)
web_1 | File "/usr/lib/python3.6/site-packages/celery/backends/redis.py", line 107, in start
web_1 | self._consume_from(initial_task_id)
web_1 | File "/usr/lib/python3.6/site-packages/celery/backends/redis.py", line 132, in _consume_from
web_1 | self._pubsub.subscribe(key)
web_1 | File "/usr/lib/python3.6/site-packages/redis/client.py", line 3096, in subscribe
web_1 | ret_val = self.execute_command('SUBSCRIBE', *iterkeys(new_channels))
web_1 | File "/usr/lib/python3.6/site-packages/redis/client.py", line 3003, in execute_command
web_1 | self.shard_hint
web_1 | File "/usr/lib/python3.6/site-packages/redis/connection.py", line 994, in get_connection
web_1 | connection.connect()
web_1 | File "/usr/lib/python3.6/site-packages/redis/connection.py", line 497, in connect
web_1 | raise ConnectionError(self._error_message(e))
web_1 | redis.exceptions.ConnectionError: Error 99 connecting to localhost:6379. Address not available.
web_1 |
web_1 | During handling of the above exception, another exception occurred:
web_1 |
web_1 | Traceback (most recent call last):
web_1 | File "/usr/lib/python3.6/site-packages/flask/app.py", line 2309, in __call__
web_1 | return self.wsgi_app(environ, start_response)
web_1 | File "/usr/lib/python3.6/site-packages/flask/app.py", line 2295, in wsgi_app
web_1 | response = self.handle_exception(e)
web_1 | File "/usr/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function
web_1 | return cors_after_request(app.make_response(f(*args, **kwargs)))
web_1 | File "/usr/lib/python3.6/site-packages/flask/app.py", line 1741, in handle_exception
web_1 | reraise(exc_type, exc_value, tb)
web_1 | File "/usr/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
web_1 | raise value
web_1 | File "/usr/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
web_1 | response = self.full_dispatch_request()
web_1 | File "/usr/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
web_1 | rv = self.handle_user_exception(e)
web_1 | File "/usr/lib/python3.6/site-packages/flask_cors/extension.py", line 161, in wrapped_function
web_1 | return cors_after_request(app.make_response(f(*args, **kwargs)))
web_1 | File "/usr/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
REDIS LOG
Redis, however, seems to be working:
redis_1 | 1:C 29 Mar 2019 02:33:32.722 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1 | 1:C 29 Mar 2019 02:33:32.722 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1 | 1:C 29 Mar 2019 02:33:32.722 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1 | 1:M 29 Mar 2019 02:33:32.724 * Running mode=standalone, port=6379.
redis_1 | 1:M 29 Mar 2019 02:33:32.724 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1 | 1:M 29 Mar 2019 02:33:32.724 # Server initialized
redis_1 | 1:M 29 Mar 2019 02:33:32.724 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redis_1 | 1:M 29 Mar 2019 02:33:32.725 * DB loaded from disk: 0.000 seconds
redis_1 | 1:M 29 Mar 2019 02:33:32.725 * Ready to accept connections
config.py
class DevelopmentConfig(BaseConfig):
"""Development configuration"""
DEBUG_TB_ENABLED = True
DEBUG = True
BCRYPT_LOG_ROUNDS = 4
#set key
#sqlalchemy
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL')
#SQLALCHEMY_DATABASE_URI= "sqlite:///models/data/database.db"
# mail
MAIL_SERVER='smtp.gmail.com'
MAIL_PORT = 587
MAIL_USE_TLS = True
MAIL_DEBUG = True
MAIL_USERNAME = 'me#gmail.com'
MAIL_PASSWORD = 'MEfAc6w74WGx'
SEVER_NAME = 'http://127.0.0.1:8080'
# celery broker
REDIS_HOST = "0.0.0.0"
REDIS_PORT = 6379
BROKER_URL = os.environ.get('REDIS_URL', "redis://{host}:{port}/0".format(
host=REDIS_HOST,
port=str(REDIS_PORT)))
INSTALLED_APPS = ['routes']
# celery config
CELERYD_CONCURRENCY = 10
CELERY_BROKER_URL = BROKER_URL
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
CELERY_IMPORTS = ('project.api.routes.background',)
what am I missing here?
TL;DR change redis://localhost:6379/0 to redis://redis:6379/0
When you run docker-compose, it creates a new network under which all your containers are running. Docker engine also creates an internal routing which allows all the containers to reference each other using their names.
In your case, your web and celery containers were trying to access redis over localhost. But inside the container, localhost means their own localhost. You need to change the configuration to point the hostname to the name of the container.
If you were not using docker, but had different machines for each of your container, localhost would have meant their own server. In order to connect to redis server, you would have passed the IP address of the machine on which redis was running. In docker, instead of IP address, you can just pass the name of the container because of the engine's routing discussed above.
Note that you can still assign static IP addresses to each of your container, and use those IP addresses instead of container_names. For more details, read the networking section of docker documents.

Python application cannot connect to PostgreSQL Docker

Can anyone help me on this?
Dockerfile for my image:
FROM python:3.6.1
ENV PYTHONUNBUFFERED 1
RUN mkdir /hlcup
WORKDIR /hlcup
ADD requirements.txt /hlcup/
RUN pip install --upgrade pip
RUN pip3 install -r requirements.txt
ADD . /hlcup/
EXPOSE 80
EXPOSE 5432
My docker-compose.yml:
version: '3'
services:
db:
image: postgres
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
ports:
- "5432:5432"
web:
build: .
command: python3 main.py
volumes:
- .:/hlcup
- ./data:/tmp/data/
ports:
- "80:80"
depends_on:
- db
I run my build: docker-compose up --build
As a result, the application should connect to the database, but I get a connection error:
web_1 | conn = await asyncpg.connect(**DB_PARAMS)
web_1 | File "/usr/local/lib/python3.6/site-packages/asyncpg/connection.py", line 1688, in connect
web_1 | max_cacheable_statement_size=max_cacheable_statement_size)
web_1 | File "/usr/local/lib/python3.6/site-packages/asyncpg/connect_utils.py", line 551, in _connect
web_1 | raise last_error
web_1 | File "/usr/local/lib/python3.6/site-packages/asyncpg/connect_utils.py", line 543, in _connect
web_1 | connection_class=connection_class)
web_1 | File "/usr/local/lib/python3.6/site-packages/asyncpg/connect_utils.py", line 513, in _connect_addr
web_1 | connector, timeout=timeout, loop=loop)
web_1 | File "/usr/local/lib/python3.6/asyncio/tasks.py", line 352, in wait_for
web_1 | return fut.result()
web_1 | File "/usr/local/lib/python3.6/asyncio/base_events.py", line 776, in create_connection
web_1 | raise exceptions[0]
web_1 | File "/usr/local/lib/python3.6/asyncio/base_events.py", line 763, in create_connection
web_1 | yield from self.sock_connect(sock, address)
web_1 | File "/usr/local/lib/python3.6/asyncio/selector_events.py", line 451, in sock_connect
web_1 | return (yield from fut)
web_1 | File "/usr/local/lib/python3.6/asyncio/selector_events.py", line 481, in _sock_connect_cb
web_1 | raise OSError(err, 'Connect call failed %s' % (address,))
web_1 | ConnectionRefusedError: [Errno 111] Connect call failed ('0.0.0.0', 5432)
You container web is tries to connecting to database with local ip 0.0.0.0:5432 and the database is on other container with another ip.
docker-compose support DNS between container, so I would try change in the python app from an ip number to a DNS.
In your docker-compose file, the postgres database DNS is db

Can't connect to postgres when using docker-compose

I am new to docker and still learning how to use it,
I am trying to use docker-compose to run Django and Postgres together
and they run perfectly and the migrate done and everything, but i have a problem i cant connect into the database using pgAdmin4 to look at the database
that's my setting.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'slack',
'USER': 'username',
'PASSWORD': 'password',
'HOST': 'db',
'PORT': 5432,
}
}
and that's my docker-compose.yml
version: '3'
services:
db:
image: postgres
environment:
POSTGRES_DB: slack
POSTGRES_USER: username
POSTGRES_PASSWORD: password
web:
build: .
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- .:/slack_code
ports:
- "8000:8000"
depends_on:
- db
everything works seems to be fine :
sudo docker-compose up
slackwebapp_db_1 is up-to-date
Creating slackwebapp_web_1 ... done
Attaching to slackwebapp_db_1, slackwebapp_web_1
db_1 | The files belonging to this database system will be owned by user "postgres".
db_1 | This user must also own the server process.
db_1 |
db_1 | The database cluster will be initialized with locale "en_US.utf8".
db_1 | The default database encoding has accordingly been set to "UTF8".
db_1 | The default text search configuration will be set to "english".
db_1 |
db_1 | Data page checksums are disabled.
db_1 |
db_1 | fixing permissions on existing directory /var/lib/postgresql/data ... ok
db_1 | creating subdirectories ... ok
db_1 | selecting default max_connections ... 100
db_1 | selecting default shared_buffers ... 128MB
db_1 | selecting dynamic shared memory implementation ... posix
db_1 | creating configuration files ... ok
db_1 | running bootstrap script ... ok
db_1 | performing post-bootstrap initialization ... ok
db_1 | syncing data to disk ... ok
db_1 |
db_1 | Success. You can now start the database server using:
db_1 |
db_1 | pg_ctl -D /var/lib/postgresql/data -l logfile start
db_1 |
db_1 |
db_1 | WARNING: enabling "trust" authentication for local connections
db_1 | You can change this by editing pg_hba.conf or using the option -A, or
db_1 | --auth-local and --auth-host, the next time you run initdb.
db_1 | waiting for server to start....2018-01-18 19:46:43.851 UTC [38] LOG: listening on IPv4 address "127.0.0.1", port 5432
db_1 | 2018-01-18 19:46:43.851 UTC [38] LOG: could not bind IPv6 address "::1": Cannot assign requested address
db_1 | 2018-01-18 19:46:43.851 UTC [38] HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
db_1 | 2018-01-18 19:46:43.853 UTC [38] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2018-01-18 19:46:43.864 UTC [39] LOG: database system was shut down at 2018-01-18 19:46:43 UTC
db_1 | 2018-01-18 19:46:43.867 UTC [38] LOG: database system is ready to accept connections
db_1 | done
db_1 | server started
db_1 | CREATE DATABASE
db_1 |
db_1 | CREATE ROLE
db_1 |
db_1 |
db_1 | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
db_1 |
db_1 | 2018-01-18 19:46:44.388 UTC [38] LOG: received fast shutdown request
db_1 | waiting for server to shut down....2018-01-18 19:46:44.389 UTC [38] LOG: aborting any active transactions
db_1 | 2018-01-18 19:46:44.390 UTC [38] LOG: worker process: logical replication launcher (PID 45) exited with exit code 1
db_1 | 2018-01-18 19:46:44.391 UTC [40] LOG: shutting down
db_1 | 2018-01-18 19:46:44.402 UTC [38] LOG: database system is shut down
db_1 | done
db_1 | server stopped
db_1 |
db_1 | PostgreSQL init process complete; ready for start up.
db_1 |
db_1 | 2018-01-18 19:46:44.501 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2018-01-18 19:46:44.501 UTC [1] LOG: listening on IPv6 address "::", port 5432
db_1 | 2018-01-18 19:46:44.502 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2018-01-18 19:46:44.514 UTC [65] LOG: database system was shut down at 2018-01-18 19:46:44 UTC
db_1 | 2018-01-18 19:46:44.518 UTC [1] LOG: database system is ready to accept connections
web_1 | Performing system checks...
web_1 |
web_1 | System check identified no issues (0 silenced).
web_1 |
web_1 | You have 14 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
web_1 | Run 'python manage.py migrate' to apply them.
web_1 | January 18, 2018 - 19:48:49
web_1 | Django version 2.0.1, using settings 'slack_webapp.settings'
web_1 | Starting development server at http://0.0.0.0:8000/
web_1 | Quit the server with CONTROL-C.
web_1 | [18/Jan/2018 19:56:03] "GET / HTTP/1.1" 200 16559
web_1 | [18/Jan/2018 19:56:03] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
web_1 | [18/Jan/2018 19:56:04] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 82564
web_1 | [18/Jan/2018 19:56:04] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 80304
web_1 | [18/Jan/2018 19:56:04] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 81348
web_1 | [18/Jan/2018 19:56:08] "GET /admin/ HTTP/1.1" 302 0
web_1 | [18/Jan/2018 19:56:09] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 1855
web_1 | [18/Jan/2018 19:56:09] "GET /static/admin/css/base.css HTTP/1.1" 200 16106
web_1 | [18/Jan/2018 19:56:09] "GET /static/admin/css/responsive.css HTTP/1.1" 200 17894
web_1 | [18/Jan/2018 19:56:09] "GET /static/admin/css/login.css HTTP/1.1" 200 1203
web_1 | [18/Jan/2018 19:58:58] "POST /admin/login/?next=/admin/ HTTP/1.1" 302 0
web_1 | [18/Jan/2018 19:58:58] "GET /admin/ HTTP/1.1" 200 2988
web_1 | [18/Jan/2018 19:58:58] "GET /static/admin/css/base.css HTTP/1.1" 304 0
web_1 | [18/Jan/2018 19:58:58] "GET /static/admin/css/dashboard.css HTTP/1.1" 200 412
web_1 | [18/Jan/2018 19:58:58] "GET /static/admin/css/responsive.css HTTP/1.1" 304 0
web_1 | [18/Jan/2018 19:58:58] "GET /static/admin/css/fonts.css HTTP/1.1" 304 0
web_1 | [18/Jan/2018 19:58:58] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 304 0
web_1 | [18/Jan/2018 19:58:58] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 304 0
web_1 | [18/Jan/2018 19:58:58] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 304 0
web_1 | [18/Jan/2018 19:58:58] "GET /static/admin/img/icon-addlink.svg HTTP/1.1" 200 331
web_1 | [18/Jan/2018 19:58:58] "GET /static/admin/img/icon-changelink.svg HTTP/1.1" 200 380
web_1 | [18/Jan/2018 19:59:05] "GET /admin/ HTTP/1.1" 200 2988
web_1 | [18/Jan/2018 19:59:07] "GET /admin/ HTTP/1.1" 200 2988
web_1 | [18/Jan/2018 19:59:11] "GET /admin/ HTTP/1.1" 200 2988
^CGracefully stopping... (press Ctrl+C again to force)
Stopping slackwebapp_web_1 ... done
Stopping slackwebapp_db_1 ... done
but still i cant connect and i don't know how to set up a password for the Postgres default user like we do in
sudo docker run --name test -e POSTGRES_PASSWORD=password -d postgres
cuz i cant do the same with docker-compose i guess, Thanks in advance.
Hostname should be name of service defined in your docker-compose.yml
This is because you're in the docker network
You cannot use localhost or 127.0.0.1 here, because pgadmin is in container, and localhost here means 'pgadmin container'.
Let's consider your case:
version: '3'
services:
db:
image: postgres
ports:
- 5432:5432
environment:
POSTGRES_DB: slack
POSTGRES_USER: snowflake
POSTGRES_PASSWORD: 1Stepclose
pgadmin:
image: chorss/docker-pgadmin4
ports:
- 5050:5050
In this case,
Hostname: db
port : 5432
user: snowflake
pass: 1Stepclose
Hope this helps :)
In order to access the postgres database from an external program you will need to mount port 5432 which is exposed by the postgres service to a port on your host.
With the following changes to your docker-compose.yml file you should be able to connect to the database using pgadmin (on localhost:5432) as well as have postgres create your user for you.
db:
image: postgres
ports:
- "5432:5432"
environment:
- POSTGRES_DB=slack
- POSTGRES_USER=snowflake
- POSTGRES_PASSWORD=1Stepclose
Edit:
I did not realize that you were trying to connect with pgadmin4 running in another docker container. The easiest way to set that up to allow pgadmin4 container to communicate with the postgres container is to add pgadmin as a service in your docker-compose.yml file. Update your docker-compose.yml file to contain the following configuration:
version: '3'
services:
db:
image: postgres
ports:
- 5432:5432
environment:
POSTGRES_DB: slack
POSTGRES_USER: snowflake
POSTGRES_PASSWORD: 1Stepclose
pgadmin:
image: chorss/docker-pgadmin4
ports:
- 5050:5050
web:
build: .
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- .:/slack_code
ports:
- "8000:8000"
depends_on:
- db
Browse to localhost:5050 > Click add new server > Enter any name > Click on connection tab > Enter db for Hostname/Address > Enter snowflake for username > Enter 1Stepclose for password > Click save
In your setting.py file you are calling the db host 'db' but in your compose output it appears to be called 'slackwebapp_db_1'. Try changing setting.py to the full name.
I have used Pycharm to control my project, and the built-in database management system in Pycharm has connected successfully, maybe it was something wrong with pgadmin4 then, i was using chorss/docker-pgadmin4 image for pgAdmin4 as i am linux so maybe it was something wrong with the image or something. thanks guys for your effort.
I looked at postgres, from which I found the git repository (according to your docker-compose, you use the latest tag). Looks like the default user name and password 'postgres' are hard-coded. You might want to try 'postgres' in settings.py for user name and password, and see if that works.

Docker Compose LAMP Database connection error

So after running docker-compose up I get the message Error establishing a database connection when visiting http://localhost:8000/
Output of docker ps -a:
➜ ~ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5a3c015efeec dockercompose_wordpress "docker-php-entryp..." 17 minutes ago Up 16 minutes 0.0.0.0:8000->80/tcp dockercompose_wordpress_1
4e46c85345d5 dockercompose_db "docker-entrypoint..." 17 minutes ago Up 16 minutes 0.0.0.0:3306->3306/tcp dockercompose_db_1
Is this right? Or should it only show one container since wordpress depends_on db?
So I am expecting to see my Wordpress site at localhost:8000.
Had imported the database making sure I sed to change all url to point to http://localhost.
Had also mounted ./html which contains my source files to container's /var/www/html.
Did I miss anything?
Folder Structure:
Folder
|
|-db
| |-Dockerfile
| |-db.sql
|
|-html
| |- (Wordpress files)
|
|-php
| |-Dockerfile
|
|-docker-composer.yml
docker-composer.yml:
version: '3'
services:
db:
build:
context: ./db
args:
MYSQL_DATABASE: coown
MYSQL_ROOT_PASSWORD: root
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: coown
MYSQL_ROOT_PASSWORD: root
wordpress:
build:
context: ./php
depends_on:
- db
ports:
- "8000:80"
volumes:
- ./html:/var/www/html
db/Dockerfile:
FROM mysql:5.7
RUN chown -R mysql:root /var/lib/mysql/
ARG MYSQL_DATABASE
ARG MYSQL_ROOT_PASSWORD
ENV MYSQL_DATABASE=$MYSQL_DATABASE
ENV MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD
ADD db.sql /etc/mysql/db.sql
RUN cp /etc/mysql/db.sql /docker-entrypoint-initdb.d
EXPOSE 3306
php/Dockerfile:
FROM php:7.0-apache
RUN docker-php-ext-install mysqli
Some output of docker-compose up:
db_1 | 2017-06-12T19:21:33.873957Z 0 [Warning] CA certificate ca.pem is self signed.
db_1 | 2017-06-12T19:21:33.875841Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
db_1 | 2017-06-12T19:21:33.876030Z 0 [Note] IPv6 is available.
db_1 | 2017-06-12T19:21:33.876088Z 0 [Note] - '::' resolves to '::';
db_1 | 2017-06-12T19:21:33.876195Z 0 [Note] Server socket created on IP: '::'.
db_1 | 2017-06-12T19:21:33.885002Z 0 [Note] InnoDB: Buffer pool(s) load completed at 170612 19:21:33
db_1 | 2017-06-12T19:21:33.902676Z 0 [Warning] 'user' entry 'root#localhost' ignored in --skip-name-resolve mode.
db_1 | 2017-06-12T19:21:33.902862Z 0 [Warning] 'user' entry 'mysql.sys#localhost' ignored in --skip-name-resolve mode.
db_1 | 2017-06-12T19:21:33.902964Z 0 [Warning] 'db' entry 'sys mysql.sys#localhost' ignored in --skip-name-resolve mode.
db_1 | 2017-06-12T19:21:33.903006Z 0 [Warning] 'proxies_priv' entry '# root#localhost' ignored in --skip-name-resolve mode.
db_1 | 2017-06-12T19:21:33.905557Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys#localhost' ignored in --skip-name-resolve mode.
db_1 | 2017-06-12T19:21:33.910940Z 0 [Note] Event Scheduler: Loaded 0 events
db_1 | 2017-06-12T19:21:33.911310Z 0 [Note] mysqld: ready for connections.
db_1 | Version: '5.7.18' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
db_1 | 2017-06-12T19:21:33.911365Z 0 [Note] Executing 'SELECT * FROM INFORMATION_SCHEMA.TABLES;' to get a list of tables using the deprecated partition engine. You may use the startup option '--disable-partition-engine-check' to skip this check.
db_1 | 2017-06-12T19:21:33.911387Z 0 [Note] Beginning of list of non-natively partitioned tables
db_1 | 2017-06-12T19:21:33.926384Z 0 [Note] End of list of non-natively partitioned tables
wordpress_1 | 172.18.0.1 - - [12/Jun/2017:19:28:39 +0000] "GET / HTTP/1.1" 500 557 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
are you using "db" host to connect PHP (Wordpress? wp-config.php?) to your database instead of the usual "localhost"?.

Resources