Docker Compose LAMP Database connection error - docker

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"?.

Related

pymysql.err.OperationalError: (1130, '172.18.0.3' is not allowed to connect to this MariaDB server)

I have a dockerized app and use the following docker-compose.yml file:
version: '3.7'
services:
app:
restart: always
build: ./app
ports:
- "8501:8501"
env_file:
- .env
command: streamlit run Main.py
networks:
- streamlit_network
mariadb:
image: mariadb:10.5.17
ports:
- "3306:3306"
volumes:
- db_data:/var/lib/mysql
- db_conf:/etc/mysql/conf.d
environment:
MYSQL_ROOT_PASSWORD: "root"
MYSQL_DATABASE: "db"
MYSQL_USER: "user"
MYSQL_PASSWORD: "password"
networks:
- streamlit_network
nginx:
restart: always
build: ./nginx
ports:
- "80:80"
depends_on:
- app
- mariadb
networks:
- streamlit_network
volumes:
db_data:
db_conf:
networks:
streamlit_network:
driver: bridge
I am able to access mysql using the following commands:
mysql -h <ip-address where database is hosted> -p -u username database
inside of my ubuntu machine which has a host IP of
How do I achieve the same within docker container
I believe '172.18.0.3' is a randomly generated ip address by docker as the IP address did change to '172.18.0.2' on another occasion.
The .env file is:
host="mariadb"
user="user"
password="password"
database="db"
port="3306"
This is the trace for mariadb when I am running docker-compose up:
mariadb_1 | 2022-10-27 12:20:24+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.9.3+maria~ubu2204 started.
mariadb_1 | 2022-10-27 12:20:25+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mariadb_1 | 2022-10-27 12:20:25+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.9.3+maria~ubu2204 started.
mariadb_1 | 2022-10-27 12:20:26+00:00 [Note] [Entrypoint]: MariaDB upgrade information missing, assuming required
mariadb_1 | 2022-10-27 12:20:26+00:00 [Note] [Entrypoint]: MariaDB upgrade (mariadb-upgrade) required, but skipped due to $MARIADB_AUTO_UPGRADE setting
mariadb_1 | 2022-10-27 12:20:26 0 [Note] mariadbd (server 10.9.3-MariaDB-1:10.9.3+maria~ubu2204) starting as process 1 ...
mariadb_1 | 2022-10-27 12:20:26 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
mariadb_1 | 2022-10-27 12:20:26 0 [Note] InnoDB: Number of transaction pools: 1
mariadb_1 | 2022-10-27 12:20:26 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
mariadb_1 | 2022-10-27 12:20:26 0 [Note] mariadbd: O_TMPFILE is not supported on /tmp (disabling future attempts)
mariadb_1 | 2022-10-27 12:20:26 0 [Note] InnoDB: Initializing buffer pool, total size = 128.000MiB, chunk size = 2.000MiB
mariadb_1 | 2022-10-27 12:20:26 0 [Note] InnoDB: Completed initialization of buffer pool
mariadb_1 | 2022-10-27 12:20:26 0 [Note] InnoDB: File system buffers for log disabled (block size=512 bytes)
mariadb_1 | 2022-10-27 12:20:27 0 [Note] InnoDB: 128 rollback segments are active.
mariadb_1 | 2022-10-27 12:20:27 0 [Note] InnoDB: Setting file './ibtmp1' size to 12.000MiB. Physically writing the file full; Please wait ...
mariadb_1 | 2022-10-27 12:20:27 0 [Note] InnoDB: File './ibtmp1' size is now 12.000MiB.
mariadb_1 | 2022-10-27 12:20:27 0 [Note] InnoDB: log sequence number 35204; transaction id 8
mariadb_1 | 2022-10-27 12:20:27 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
mariadb_1 | 2022-10-27 12:20:27 0 [Note] Plugin 'FEEDBACK' is disabled.
mariadb_1 | 2022-10-27 12:20:27 0 [Note] InnoDB: Buffer pool(s) load completed at 221027 12:20:27
mariadb_1 | 2022-10-27 12:20:27 0 [ERROR] Could not open mysql.plugin table: "Table 'mysql.plugin' doesn't exist". Some plugins may be not loaded
mariadb_1 | 2022-10-27 12:20:28 0 [Warning] You need to use --log-bin to make --expire-logs-days or --binlog-expire-logs-seconds work.
mariadb_1 | 2022-10-27 12:20:28 0 [ERROR] Can't open and lock privilege tables: Table 'mysql.servers' doesn't exist
mariadb_1 | 2022-10-27 12:20:28 0 [Note] Server socket created on IP: '0.0.0.0'.
mariadb_1 | 2022-10-27 12:20:28 0 [Note] Server socket created on IP: '::'.
mariadb_1 | 2022-10-27 12:20:28 0 [ERROR] Missing system table mysql.proxies_priv; please run mysql_upgrade to create it
mariadb_1 | 2022-10-27 12:20:28 0 [ERROR] Missing system table mysql.roles_mapping; please run mysql_upgrade to create it
mariadb_1 | 2022-10-27 12:20:28 0 [Warning] Can't open and lock time zone table: Table 'mysql.time_zone_leap_second' doesn't exist trying to live without them
mariadb_1 | 2022-10-27 12:20:28 0 [ERROR] Can't open the mysql.func table. Please run mysql_upgrade to create it.
mariadb_1 | 2022-10-27 12:20:28 0 [ERROR] Cannot open mysql.event
mariadb_1 | 2022-10-27 12:20:28 0 [ERROR] mariadbd: Event Scheduler: An error occurred when initializing system tables. Disabling the Event Scheduler.
mariadb_1 | 2022-10-27 12:20:28 1 [Warning] Failed to load slave replication state from table mysql.gtid_slave_pos: 1146: Table 'mysql.gtid_slave_pos' doesn't exist
mariadb_1 | 2022-10-27 12:20:28 0 [Note] mariadbd: ready for connections.
mariadb_1 | Version: '10.9.3-MariaDB-1:10.9.3+maria~ubu2204' socket: '/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution
mariadb_1 | 2022-10-27 12:27:27 3 [Warning] Aborted connection 3 to db: 'unconnected' user: 'unauthenticated' host: '172.18.0.2' (This connection closed normally without authentication)
mariadb_1 | 2022-10-27 12:35:05 4 [Warning] Aborted connection 4 to db: 'unconnected' user: 'unauthenticated' host: '172.18.0.2' (This connection closed normally without authentication)

Invoice Ninja with docker compose - Error 500

I have setup Invoice ninja with docker-compose behind a nginx reverse proxy, which also manages the TLS certificate.
As far as I can see from the logs, everything initializes correct, but when I navigate to the site, I can only see a 500 Server error.
I provided my docker-compose and the logs until the first 500 error below.
Thanks in advance!
docker-compose.yml
version: '3.7'
services:
server:
image: caddy:alpine
restart: always
environment:
- APP_URL=http://ninja.example.de
volumes:
# Vhost configuration
- ./config/caddy/Caddyfile:/etc/caddy/Caddyfile
- ./public:/var/www/app/public
- ./storage:/var/www/app/storage
depends_on:
- app
# Run webserver nginx on port 80
# Feel free to modify depending what port is already occupied
ports:
- "127.0.0.1:4301:80"
# - "443:443"
networks:
- invoiceninja
app:
image: invoiceninja/invoiceninja:5
restart: always
environment:
- APP_URL=ninja.example.de
- APP_KEY=base64:mykeyxzy
- MULTI_DB_ENABLED=false
- DB_HOST1=db
volumes:
- ./public:/var/www/app/public
- ./storage:/var/www/app/storage
depends_on:
- db
networks:
- invoiceninja
db:
image: mysql:5
restart: always
environment:
- MYSQL_ROOT_PASSWORD=mypassword
- MYSQL_USER=ninja
- MYSQL_PASSWORD=ninja
- MYSQL_DATABASE=db-ninja-01
volumes:
- ./mysql/data:/var/lib/mysql
networks:
- invoiceninja
# cron:
# cron is commented out by me
volumes:
mysql-data:
public:
storage:
networks:
invoiceninja:
docker log
server_1 | {"level":"info","ts":1590774949.786359,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
server_1 | {"level":"info","ts":1590774949.7946017,"logger":"admin","msg":"admin endpoint started","address":"tcp/localhost:2019","enforce_origin":false,"origins":["localhost:2019","[::1]:2019","127.0.0.1:2019"]}
server_1 | {"level":"info","ts":1590774949.7968726,"logger":"http","msg":"server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server","server_name":"srv0","http_port":80}
server_1 | 2020/05/29 17:55:49 [INFO][cache:0xc00075e0a0] Started certificate maintenance routine
server_1 | {"level":"info","ts":1590774949.7995124,"logger":"tls","msg":"cleaned up storage units"}
server_1 | {"level":"info","ts":1590774949.799886,"msg":"autosaved config","file":"/config/caddy/autosave.json"}
server_1 | {"level":"info","ts":1590774949.799923,"msg":"serving initial configuration"}
app_1 | Configuration cache cleared!
app_1 | Configuration cached successfully!
app_1 | Route cache cleared!
app_1 | Routes cached successfully!
app_1 | Files cached successfully!
app_1 | [29-May-2020 17:55:49] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
app_1 | [29-May-2020 17:55:49] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
app_1 | [29-May-2020 17:55:49] NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root
app_1 | [29-May-2020 17:55:49] NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root
app_1 | [29-May-2020 17:55:49] NOTICE: fpm is running, pid 1
app_1 | [29-May-2020 17:55:49] NOTICE: ready to handle connections
db_1 | 2020-05-29 17:55:48+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.30-1debian10 started.
db_1 | 2020-05-29 17:55:48+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db_1 | 2020-05-29 17:55:48+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.30-1debian10 started.
db_1 | 2020-05-29T17:55:48.703457Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1 | 2020-05-29T17:55:48.708189Z 0 [Note] mysqld (mysqld 5.7.30) starting as process 1 ...
db_1 | 2020-05-29T17:55:48.714931Z 0 [Note] InnoDB: PUNCH HOLE support available
db_1 | 2020-05-29T17:55:48.714988Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1 | 2020-05-29T17:55:48.714995Z 0 [Note] InnoDB: Uses event mutexes
db_1 | 2020-05-29T17:55:48.714999Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
db_1 | 2020-05-29T17:55:48.715002Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
db_1 | 2020-05-29T17:55:48.715011Z 0 [Note] InnoDB: Using Linux native AIO
db_1 | 2020-05-29T17:55:48.715701Z 0 [Note] InnoDB: Number of pools: 1
db_1 | 2020-05-29T17:55:48.716017Z 0 [Note] InnoDB: Using CPU crc32 instructions
db_1 | 2020-05-29T17:55:48.722484Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
db_1 | 2020-05-29T17:55:48.741778Z 0 [Note] InnoDB: Completed initialization of buffer pool
db_1 | 2020-05-29T17:55:48.747111Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
db_1 | 2020-05-29T17:55:48.763090Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
db_1 | 2020-05-29T17:55:48.798980Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db_1 | 2020-05-29T17:55:48.799233Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db_1 | 2020-05-29T17:55:48.832312Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db_1 | 2020-05-29T17:55:48.834307Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
db_1 | 2020-05-29T17:55:48.834434Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
db_1 | 2020-05-29T17:55:48.835099Z 0 [Note] InnoDB: Waiting for purge to start
db_1 | 2020-05-29T17:55:48.885461Z 0 [Note] InnoDB: 5.7.30 started; log sequence number 12488420
db_1 | 2020-05-29T17:55:48.886497Z 0 [Note] Plugin 'FEDERATED' is disabled.
db_1 | 2020-05-29T17:55:48.897039Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db_1 | 2020-05-29T17:55:48.906339Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
db_1 | 2020-05-29T17:55:48.906387Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
db_1 | 2020-05-29T17:55:48.907291Z 0 [Warning] CA certificate ca.pem is self signed.
db_1 | 2020-05-29T17:55:48.907356Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
db_1 | 2020-05-29T17:55:48.908141Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200529 17:55:48
db_1 | 2020-05-29T17:55:48.909168Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
db_1 | 2020-05-29T17:55:48.909863Z 0 [Note] IPv6 is available.
db_1 | 2020-05-29T17:55:48.909911Z 0 [Note] - '::' resolves to '::';
db_1 | 2020-05-29T17:55:48.909952Z 0 [Note] Server socket created on IP: '::'.
db_1 | 2020-05-29T17:55:48.914971Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1 | 2020-05-29T17:55:48.932266Z 0 [Note] Event Scheduler: Loaded 0 events
db_1 | 2020-05-29T17:55:48.932616Z 0 [Note] mysqld: ready for connections.
db_1 | Version: '5.7.30' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
app_1 | 192.168.48.5 - 29/May/2020:17:59:07 +0000 "GET /index.php" 500
This errors occurs dues to the facts that the application cannot correctly determine the passed application key APP_KEY. It seems the application cache is a bit reluctant to be refreshed - this is only a problem in the docker containers and not for the self-host option w/o docker.
I pushed an update to the for the latest and 5 tags. So first, please update your images. This fixes some permission to get proper write permissions to some cache folders.
Then after your docker-compose setup started please run
docker-compose exec app php artisan config:cache
a couple of times and refresh your page. It takes some time and a couple of calls till the cache is refreshed. The error message then changes to SQLSTATE[42S02]: Base table or view not found: this is a know problem but can be fixed (for now) by navigation to /setup which then will run the proper migrations.

phpMyAdmin does not connect to MariaDB and MariaDB does not set default MYSQL_ROOT_PASSWORD variable on the docker compose

I'm trying to create a docker-compose with MariaDB and phpMyAdmin Docker images, however I'm having the following problems: neither MariaDB nor phpMyAdmin use the environment variables inside their files, in other words, MariaDB does not set default password described on MYSQL_ROOT_PASSWORD variable and phpMyAdmin is not able to connect to MariaDB even if I set a new password to MariaDB manually.
On the terminal, MariaDB shows the following output when I run the docker compose for once:
dgi_catalog_db | PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
dgi_catalog_db | To do so, start the server, then issue the following commands:
dgi_catalog_db |
dgi_catalog_db | '/usr/bin/mysqladmin' -u root password 'new-password'
dgi_catalog_db | '/usr/bin/mysqladmin' -u root -h password 'new-password'
dgi_catalog_db |
dgi_catalog_db | Alternatively you can run:
dgi_catalog_db | '/usr/bin/mysql_secure_installation'
[...]
dgi_catalog_db | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
When I try to connect to MariaDB through phpMyAdmin without setting a default password, the following message shows:
mysqli_real_connect(): (HY000/2002): Connection refused
Then, I get into the container and I set a new password manually:
$ docker exec -it dgi_catalog_db /bin/bash
# mysqladmin -u root password 'password'
If I try to connect through phpMyAdmin again, I get the same error again:
mysqli_real_connect(): (HY000/2002): Connection refused
Then, I tried to restart my containers and to connect through phpMyAdmin again and they show the following messages:
phpMyAdmin on the web interface:
Packets out of order. Expected 0 received 1. Packet size=69
mysqli_real_connect(): Error while reading greeting packet. PID=35
mysqli_real_connect(): (HY000/2006): MySQL server has gone away
MariaDB on the terminal:
dgi_catalog_db | 2020-01-15 12:36:36 8 [Warning] Aborted connection 8 to db: 'unconnected' user: 'unauthenticated' host: '172.29.0.3' (This connection closed normally without authentication)
I've already tried some solutions on the internet (for example, this one), but I was not able to fix the problem.
I'm using Ubuntu 16.04.6 LTS and I send my files below.
Could anyone help me, please? Thank you in advance.
project's structure
I have a folder called catalog with the following structure:
.
├── docker-compose.yml
└── env_files
   ├── db.env
   └── phpmyadmin.env
The files are described afterwards.
docker-compose.yml:
version: '3'
services:
dgi_catalog_db:
container_name: dgi_catalog_db
image: mariadb:10.4.11
restart: always
volumes:
- ../data/mysqldata:/var/lib/mysql
env_file:
- ./env_files/db.env
networks:
- dgi_catalog
ports:
- 3311:3306
dgi_catalog_admin:
container_name: dgi_catalog_admin
image: phpmyadmin/phpmyadmin:4.9
restart: always
env_file:
- ./env_files/phpmyadmin.env
networks:
- dgi_catalog
ports:
- 8099:80
networks:
dgi_catalog:
driver: bridge
../data/mysqldata volume can be another folder.
./env_files/db.env
MYSQL_ROOT_PASSWORD=password
./env_files/phpmyadmin.env
PMA_HOST=dgi_catalog_db
PMA_ARBITRARY=1
EDIT 1:
I've not found a solution, but I believe I've discovered the main problem: MariaDB takes a very long time to initialize. 20 minutes after docker-compose be initialized, MariaDB has printed mysqld: ready for connections. and I was able to connect to my database through phpMyAdmin.
dgi_catalog_db | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
dgi_catalog_db | 2020-01-15 14:06:41 10 [Warning] 'proxies_priv' entry '#% root#fbbf075da453' ignored in --skip-name-resolve mode.
dgi_catalog_db | 2020-01-15 14:06:41+00:00 [Note] [Entrypoint]: Stopping temporary server
[...]
dgi_catalog_db | 2020-01-15 14:06:49 0 [Warning] 'proxies_priv' entry '#% root#fbbf075da453' ignored in --skip-name-resolve mode.
dgi_catalog_db | 2020-01-15 14:06:49 0 [Note] Reading of all Master_info entries succeeded
dgi_catalog_db | 2020-01-15 14:06:49 0 [Note] Added new Master_info '' to hash table
dgi_catalog_db | 2020-01-15 14:06:49 0 [Note] mysqld: ready for connections.
dgi_catalog_db | Version: '10.4.11-MariaDB-1:10.4.11+maria~bionic' socket: '/var/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution
dgi_catalog_db | 2020-01-15 14:06:49 0 [Note] InnoDB: Buffer pool(s) load completed at 200115 14:06:49
There is an opened issue on Github about it. Apparently, if I use the -e MYSQL_INITDB_SKIP_TZINFO=1 variable, MariaDB will initialize faster, but I will not have time zone information.

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.

Unable to run mariadb when mount volume

Using the following docker-compose.yml file
version: '2'
services:
wordpress:
image: wordpress
ports:
- 8080:80
environment:
WORDPRESS_DB_NAME: my_db
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: password
volumes:
- ./src:/var/www/html
mysql:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: password
volumes:
- ./data_dir:/var/lib/mysql
when running docker-compose up commande,its giving me following error
Starting wp_mysql_1
Starting wp_wordpress_1
Attaching to wp_mysql_1, wp_wordpress_1
wordpress_1 |
wordpress_1 | Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 19
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) Connection refused
mysql_1 | 2016-11-28 15:47:02 139858949081024 [Note] mysqld (mysqld 10.1.19-MariaDB-1~jessie) starting as process 1
...
mysql_1 | 2016-11-28 15:47:03 139858949081024 [Note] InnoDB: Using mutexes to ref count buffer pool pages
mysql_1 | 2016-11-28 15:47:03 139858949081024 [Note] InnoDB: The InnoDB memory heap is disabled
mysql_1 | 2016-11-28 15:47:03 139858949081024 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
mysql_1 | 2016-11-28 15:47:03 139858949081024 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory
barrier
mysql_1 | 2016-11-28 15:47:03 139858949081024 [Note] InnoDB: Compressed tables use zlib 1.2.8
mysql_1 | 2016-11-28 15:47:03 139858949081024 [Note] InnoDB: Using Linux native AIO
mysql_1 | 2016-11-28 15:47:03 139858949081024 [Note] InnoDB: Using SSE crc32 instructions
mysql_1 | 2016-11-28 15:47:03 139858949081024 [Note] InnoDB: Initializing buffer pool, size = 256.0M
mysql_1 | 2016-11-28 15:47:03 139858949081024 [Note] InnoDB: Completed initialization of buffer pool
mysql_1 | 2016-11-28 15:47:03 139858949081024 [ERROR] InnoDB: auto-extending data file ./ibdata1 is of a different
size 0 pages (rounded down to MB) than specified in the .cnf file: initial 768 pages, max 0 (relevant if non-zero) pages
!
mysql_1 | 2016-11-28 15:47:03 139858949081024 [ERROR] InnoDB: Could not open or create the system tablespace. If yo
u tried to add new data files to the system tablespace, and it failed here, you should now edit innodb_data_file_path in
my.cnf back to what it was, and remove the new ibdata files InnoDB created in this failed attempt. InnoDB only wrote th
ose files full of zeros, but did not yet use them in any way. But be careful: do not remove old data files which contain
your precious data!
mysql_1 | 2016-11-28 15:47:03 139858949081024 [ERROR] Plugin 'InnoDB' init function returned error.
mysql_1 | 2016-11-28 15:47:03 139858949081024 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
mysql_1 | 2016-11-28 15:47:03 139858949081024 [Note] Plugin 'FEEDBACK' is disabled.
mysql_1 | 2016-11-28 15:47:03 139858949081024 [ERROR] Could not open mysql.plugin table. Some plugins may be not lo
aded
mysql_1 | 2016-11-28 15:47:03 139858949081024 [ERROR] Unknown/unsupported storage engine: InnoDB
mysql_1 | 2016-11-28 15:47:03 139858949081024 [ERROR] Aborting
mysql_1 |
wp_mysql_1 exited with code 1
wordpress_1 |
wordpress_1 | Warning: mysqli::mysqli(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - o
n line 19
wordpress_1 |
wordpress_1 | Warning: mysqli::mysqli(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service no
t known in - on line 19
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
but if I removed the volumes from mysql image, then it works fine! How can I mount the volume as I need data to be persisted.
It's actually a problem with MariaDB. You cannot mount the folder for MariaDB to the host using Docker because it presents the shared files/folders permissions to the database container as root owned with writable only by root. The solution is to use docker-compose named volumes. As stated in docker documentation:
Docker has two options for containers to store files in the host machine, so that the files are persisted even after the container stops: volumes, and bind mounts. If you’re running Docker on Linux you can also use a tmpfs mount.
What you are trying to use is the bind-mount which does not works with MariaDB. So we can use docker volume for that.
When you create a volume, it is stored within a directory on the Docker host. When you mount the volume into a container, this directory is what is mounted into the container. This is similar to the way that bind mounts work, except that volumes are managed by Docker and are isolated from the core functionality of the host machine. Volumes are stored in a part of the host filesystem which is managed by Docker(/var/lib/docker/volumes/ on Linux). So change your docker-compose file as:-
version: '2'
services:
wordpress:
image: wordpress
ports:
- 8080:80
environment:
WORDPRESS_DB_NAME: my_db
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: password
volumes:
- ./src:/var/www/html
mysql:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: password
volumes:
- db_data:/var/lib/mysql
volumes:
db_data:
i.e. use a named volume under mysql service and declare it in top level volumes key. This will tell docker-compose to create a Docker mananged volume and your MariaDB data is backed up/persisted at /var/lib/docker/volumes/_db_data/_data directory on host machine.
Also after running docker-compose up command if you do
docker volume ls
then you can see docker-compose created volume.

Resources