I have been trying to get mariadb to work with named volumes, but I keep running into the problem that it cannot write to it.
My docker host
Docker Version: 20.10.3 on Synology DSM 7
My docker-compose.yml
---
version: "3.8"
services:
bitwarden:
depends_on:
- database
env_file:
- /volume1/docker/bitwardenextvol/settings.env
image: bitwarden/self-host:beta
restart: unless-stopped
ports:
- "4088:4080"
- "4449:4443"
volumes:
- bitwarden:/etc/bitwarden
database:
environment:
MARIADB_USER: "bitwarden"
MARIADB_PASSWORD: "****************"
MARIADB_DATABASE: "bitwarden_vault"
MARIADB_RANDOM_ROOT_PASSWORD: "true"
image: mariadb:latest
user: 1026:100
restart: unless-stopped
volumes:
- data:/var/lib/mysql
volumes:
bitwarden:
external: true
data:
external: true
My named volumes
[
{
"CreatedAt": "2023-01-14T18:32:39+01:00",
"Driver": "local",
"Labels": null,
"Mountpoint": "/volume1/#docker/volumes/bitwarden/_data",
"Name": "bitwarden",
"Options": {
"device": "//diskstation.diesveld.lan/docker/bitwardenextvol/bitwarden",
"o": "addr=diskstation.diesveld.lan,username=harald,password=********,vers=3.0",
"type": "cifs"
},
"Scope": "local"
}
]
[
{
"CreatedAt": "2023-01-14T18:33:24+01:00",
"Driver": "local",
"Labels": null,
"Mountpoint": "/volume1/#docker/volumes/data/_data",
"Name": "data",
"Options": {
"device": "//diskstation.diesveld.lan/docker/bitwardenextvol/data",
"o": "addr=diskstation.diesveld.lan,username=harald,password=********,vers=3.0",
"type": "cifs"
},
"Scope": "local"
}
]
The host directory
harald#diskstation:/volume1/docker$ ls -al | grep bitwardenextvol
drwxrwxrwx+ 1 harald users 116 Jan 14 18:36 bitwardenextvol
Inside the host directory
harald#diskstation:/volume1/docker/bitwardenextvol$ ls -al
total 16
drwxrwxrwx+ 1 harald users 116 Jan 14 18:36 .
drwxrwxrwx+ 1 root root 294 Jan 14 18:41 ..
drwxrwxrwx+ 1 harald users 94 Jan 14 18:39 bitwarden
drwxrwxrwx+ 1 harald users 30 Jan 14 18:37 data
-rwxrwxrwx+ 1 harald users 698 Jan 14 22:07 docker-compose.yml
-rwxrwxrwx+ 1 harald users 6148 Jan 14 18:11 .DS_Store
drwxrwxrwx+ 1 root users 94 Jan 14 18:12 #eaDir
-rwxrwxrwx+ 1 harald users 1940 Jan 14 18:18 settings.env
My user account
harald#diskstation:/volume1/docker/bitwardenextvol$ id harald
uid=1026(harald) gid=100(users) groups=100(users),101(administrators)
The error message that I get when running sudo docker-compose up
harald#diskstation:/volume1/docker/bitwardenextvol$ sudo docker-compose up
Creating bitwardenextvol_database_1 ... done
Creating bitwardenextvol_bitwarden_1 ... done
Attaching to bitwardenextvol_database_1, bitwardenextvol_bitwarden_1
database_1 | 2023-01-14 23:24:33+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.10.2+maria~ubu2204 started.
bitwarden_1 | addgroup: gid '100' in use
database_1 | 2023-01-14 23:24:33+00:00 [Note] [Entrypoint]: Initializing database files
database_1 | 2023-01-14 23:24:33 0 [Warning] Can't create test file /var/lib/mysql/a68bd83e89af.lower-test
database_1 | 2023-01-14 23:24:33 0 [ERROR] mariadbd: Can't create/write to file './ddl_recovery.log' (Errcode: 13 "Permission denied")
database_1 | 2023-01-14 23:24:33 0 [ERROR] DDL_LOG: Failed to create ddl log file: ./ddl_recovery.log
database_1 | 2023-01-14 23:24:33 0 [ERROR] Aborting
database_1 |
database_1 | Installation of system tables failed! Examine the logs in
database_1 | /var/lib/mysql/ for more information.
database_1 |
database_1 | The problem could be conflicting information in an external
database_1 | my.cnf files. You can ignore these by doing:
database_1 |
database_1 | shell> /usr/bin/mariadb-install-db --defaults-file=~/.my.cnf
database_1 |
database_1 | You can also try to start the mysqld daemon with:
database_1 |
database_1 | shell> /usr/sbin/mariadbd --skip-grant-tables --general-log &
database_1 |
database_1 | and use the command line tool /usr/bin/mariadb
database_1 | to connect to the mysql database and look at the grant tables:
database_1 |
database_1 | shell> /usr/bin/mysql -u root mysql
database_1 | mysql> show tables;
database_1 |
database_1 | Try 'mysqld --help' if you have problems with paths. Using
database_1 | --general-log gives you a log in /var/lib/mysql/ that may be helpful.
database_1 |
database_1 | The latest information about mysql_install_db is available at
database_1 | ******/kb/en/installing-system-tables-mysql_install_db
database_1 | You can find the latest source at ******** and
database_1 | the maria-discuss email list at ********/~maria-discuss
database_1 |
database_1 | Please check all of the above before submitting a bug report
database_1 | at *******/jira
database_1 |
bitwardenextvol_database_1 exited with code 1
database_1 | 2023-01-14 23:24:35+00:00 [Note] [Entrypoint]: Initializing database files
bitwarden_1 | 2023-01-14 23:24:35,560 INFO Included extra file "/etc/supervisor.d/admin.ini" during parsing
bitwarden_1 | 2023-01-14 23:24:35,560 INFO Included extra file "/etc/supervisor.d/api.ini" during parsing
bitwarden_1 | 2023-01-14 23:24:35,560 INFO Included extra file "/etc/supervisor.d/events.ini" during parsing
bitwarden_1 | 2023-01-14 23:24:35,560 INFO Included extra file "/etc/supervisor.d/icons.ini" during parsing
bitwarden_1 | 2023-01-14 23:24:35,560 INFO Included extra file "/etc/supervisor.d/identity.ini" during parsing
bitwarden_1 | 2023-01-14 23:24:35,560 INFO Included extra file "/etc/supervisor.d/nginx.ini" during parsing
bitwarden_1 | 2023-01-14 23:24:35,560 INFO Included extra file "/etc/supervisor.d/notifications.ini" during parsing
bitwarden_1 | 2023-01-14 23:24:35,560 INFO Included extra file "/etc/supervisor.d/scim.ini" during parsing
bitwarden_1 | 2023-01-14 23:24:35,561 INFO Included extra file "/etc/supervisor.d/sso.ini" during parsing
database_1 | 2023-01-14 23:24:35 0 [Warning] Can't create test file /var/lib/mysql/a68bd83e89af.lower-test
bitwarden_1 | 2023-01-14 23:24:35,571 INFO RPC interface 'supervisor' initialized
bitwarden_1 | 2023-01-14 23:24:35,571 CRIT Server 'unix_http_server' running without any HTTP authentication checking
bitwarden_1 | 2023-01-14 23:24:35,572 INFO supervisord started with pid 48
database_1 | 2023-01-14 23:24:35 0 [ERROR] mariadbd: Can't create/write to file './ddl_recovery.log' (Errcode: 13 "Permission denied")
database_1 | 2023-01-14 23:24:35 0 [ERROR] DDL_LOG: Failed to create ddl log file: ./ddl_recovery.log
database_1 | 2023-01-14 23:24:35 0 [ERROR] Aborting
database_1 |
database_1 | Installation of system tables failed! Examine the logs in
database_1 | /var/lib/mysql/ for more information.
database_1 |
database_1 | The problem could be conflicting information in an external
database_1 | my.cnf files. You can ignore these by doing:
database_1 |
database_1 | shell> /usr/bin/mariadb-install-db --defaults-file=~/.my.cnf
database_1 |
database_1 | You can also try to start the mysqld daemon with:
database_1 |
database_1 | shell> /usr/sbin/mariadbd --skip-grant-tables --general-log &
database_1 |
database_1 | and use the command line tool /usr/bin/mariadb
database_1 | to connect to the mysql database and look at the grant tables:
database_1 |
database_1 | shell> /usr/bin/mysql -u root mysql
database_1 | mysql> show tables;
database_1 |
database_1 | Try 'mysqld --help' if you have problems with paths. Using
database_1 | --general-log gives you a log in /var/lib/mysql/ that may be helpful.
database_1 |
database_1 | The latest information about mysql_install_db is available at
database_1 | ********/kb/en/installing-system-tables-mysql_install_db
database_1 | You can find the latest source at https://downloads.mariadb.org and
database_1 | the maria-discuss email list at https://launchpad.net/~maria-discuss
database_1 |
database_1 | Please check all of the above before submitting a bug report
database_1 | at ******
database_1 |
bitwarden_1 | 2023-01-14 23:24:36,574 INFO spawned: 'identity' with pid 49
bitwarden_1 | 2023-01-14 23:24:36,576 INFO spawned: 'admin' with pid 50
bitwarden_1 | 2023-01-14 23:24:36,578 INFO spawned: 'api' with pid 51
bitwarden_1 | 2023-01-14 23:24:36,579 INFO spawned: 'icons' with pid 52
bitwarden_1 | 2023-01-14 23:24:36,583 INFO spawned: 'nginx' with pid 53
bitwarden_1 | 2023-01-14 23:24:36,586 INFO spawned: 'notifications' with pid 54
database_1 | 2023-01-14 23:24:36+00:00 [Note] [Entrypoint]: Initializing database files
database_1 | 2023-01-14 23:24:36 0 [Warning] Can't create test file /var/lib/mysql/a68bd83e89af.lower-test
database_1 | 2023-01-14 23:24:36 0 [ERROR] mariadbd: Can't create/write to file './ddl_recovery.log' (Errcode: 13 "Permission denied")
database_1 | 2023-01-14 23:24:36 0 [ERROR] DDL_LOG: Failed to create ddl log file: ./ddl_recovery.log
database_1 | 2023-01-14 23:24:36 0 [ERROR] Aborting
database_1 |
database_1 | Installation of system tables failed! Examine the logs in
database_1 | /var/lib/mysql/ for more information.
database_1 |
database_1 | The problem could be conflicting information in an external
database_1 | my.cnf files. You can ignore these by doing:
database_1 |
database_1 | shell> /usr/bin/mariadb-install-db --defaults-file=~/.my.cnf
database_1 |
database_1 | You can also try to start the mysqld daemon with:
database_1 |
database_1 | shell> /usr/sbin/mariadbd --skip-grant-tables --general-log &
database_1 |
database_1 | and use the command line tool /usr/bin/mariadb
database_1 | to connect to the mysql database and look at the grant tables:
database_1 |
database_1 | shell> /usr/bin/mysql -u root mysql
database_1 | mysql> show tables;
database_1 |
database_1 | Try 'mysqld --help' if you have problems with paths. Using
database_1 | --general-log gives you a log in /var/lib/mysql/ that may be helpful.
database_1 |
database_1 | The latest information about mysql_install_db is available at
database_1 | *******/kb/en/installing-system-tables-mysql_install_db
database_1 | You can find the latest source at ****** and
database_1 | the maria-discuss email list at *******/~maria-discuss
database_1 |
database_1 | Please check all of the above before submitting a bug report
database_1 | at ******
database_1 |
bitwardenextvol_database_1 exited with code 1
The weird thing is it works perfectly well with bind mounts to the very same location on disk. Also, the bitwarden container is working perfectly fine with the described named volume, however, the mariadb container is throwing the errors like in above log
[ERROR] mariadbd: Can't create/write to file './ddl_recovery.log' (Errcode: 13 "Permission denied")
The directory that the named volume is pointing to is not getting written in at all.
I cannot view the MariaDB logs, as the container keeps restarting so I cannot SSH into it.
What I get from the official documentation is that MariaDB should work perfectly fine with named volumes, but for some reason it is not in my case. My hunch was that it has to do with permissions. I tried adding the --user 1026:100 in the MariaDB service declaration but that doesn't change things.
I know I could simply work with bind mounts, but I really want to figure out how to do it with named volumes.
Who has some tips or knows how to further debug this? Your help or insights are much appreciated.
Updates based on answers
I noticed something peculiar though, the user mysql is not 999:999, but rather 66:66
harald#diskstation:~$ id mysql uid=66(mysql) gid=66(mysql) groups=66(mysql)
As I am a bit out of my comfort zone here, I cannot exactly estimate the impact of this.
As I can see in the below output, this user is not running any processes
harald#diskstation:~$ ps -u mysql
PID TTY TIME CMD
But when I try to delete the user (Synology does not support deluser) I cannot get it done:
harald#diskstation:~$ sudo synouser --del mysql
Lastest SynoErr=[user_db_delete.c:38] synouser.c:798 SYNOLocalAccountUserDelete failed. synoerr=[0xB800].
Otherwise I could get MariaDB recreate the mysql user with the right creds perhaps.
Results from docker run command from answer of Dan shows that the named volume can be read:
harald#diskstation:~$ sudo docker run -v data:/var/lib/mysql --rm mariadb ls -laZ /var/lib/mysql
total 8
drwxr-xr-x 2 root root ? 0 Jan 15 14:57 .
drwxr-xr-x 1 root root ? 76 Dec 9 02:27 ..
-rwxr-xr-x 1 root root ? 6148 Jan 14 16:40 .DS_Store
-rwxr-xr-x 1 root root ? 0 Jan 15 14:57 just-to-show-this-file-in-the-volume.yml
mysql user is indeed 999:999 inside container, but it is 66:66 outside for some weird reason.
harald#diskstation:~$ sudo docker run --rm mariadb id mysql
uid=999(mysql) gid=999(mysql) groups=999(mysql)
Changing the mount options of CIFS to include cache=none appears to be
one solution. The other is adding --innodb_flush_method=fsync to the
mariadb container args.
Mounting volume with cache=none option and adding
innodb_flush_method: "fsync"
to the docker-compose.yml does not change the behaviour unfortunately.
This is the latest state, with above remarks taken into account and without the --user. Still the same results.
harald#diskstation:~$ sudo docker volume inspect data
[
{
"CreatedAt": "2023-01-15T16:42:40+01:00",
"Driver": "local",
"Labels": {},
"Mountpoint": "/volume1/#docker/volumes/data/_data",
"Name": "data",
"Options": {
"device": "//diskstation.diesveld.lan/docker/bitwardenextvol/data",
"o": "addr=diskstation.diesveld.lan,username=harald,password=***,vers=3.0,cache=none",
"type": "cifs"
},
"Scope": "local"
}
]
And this is my docker-compose.yml
---
version: "3.8"
services:
bitwarden:
depends_on:
- database
env_file:
- /volume1/docker/bitwardenextvol/settings.env
image: bitwarden/self-host:beta
restart: unless-stopped
ports:
- "4088:4080"
- "4449:4443"
volumes:
- bitwarden:/etc/bitwarden
database:
environment:
MARIADB_USER: "bitwarden"
MARIADB_PASSWORD: "***"
MARIADB_DATABASE: "bitwarden_vault"
MARIADB_RANDOM_ROOT_PASSWORD: "true"
innodb_flush_method: "fsync"
image: mariadb:latest
restart: unless-stopped
volumes:
- data:/var/lib/mysql
volumes:
bitwarden:
external: true
data:
external: true
The logs from this:
harald#diskstation:/volume1/docker/bitwardenextvol$ sudo docker-compose up
Creating bitwardenextvol_database_1 ... done
Creating bitwardenextvol_bitwarden_1 ... done
Attaching to bitwardenextvol_database_1, bitwardenextvol_bitwarden_1
database_1 | 2023-01-16 06:26:00+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.10.2+maria~ubu2204 started.
bitwarden_1 | addgroup: gid '100' in use
database_1 | 2023-01-16 06:26:00+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
database_1 | 2023-01-16 06:26:00+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.10.2+maria~ubu2204 started.
database_1 | 2023-01-16 06:26:00+00:00 [Note] [Entrypoint]: Initializing database files
database_1 | 2023-01-16 6:26:00 0 [Warning] Can't create test file /var/lib/mysql/4d6c9c2f7405.lower-test
database_1 | 2023-01-16 6:26:00 0 [ERROR] mariadbd: Can't create/write to file './ddl_recovery.log' (Errcode: 13 "Permission denied")
database_1 | 2023-01-16 6:26:00 0 [ERROR] DDL_LOG: Failed to create ddl log file: ./ddl_recovery.log
database_1 | 2023-01-16 6:26:00 0 [ERROR] Aborting
database_1 |
database_1 | Installation of system tables failed! Examine the logs in
database_1 | /var/lib/mysql/ for more information.
database_1 |
database_1 | The problem could be conflicting information in an external
database_1 | my.cnf files. You can ignore these by doing:
database_1 |
database_1 | shell> /usr/bin/mariadb-install-db --defaults-file=~/.my.cnf
database_1 |
database_1 | You can also try to start the mysqld daemon with:
database_1 |
database_1 | shell> /usr/sbin/mariadbd --skip-grant-tables --general-log &
database_1 |
database_1 | and use the command line tool /usr/bin/mariadb
database_1 | to connect to the mysql database and look at the grant tables:
database_1 |
database_1 | shell> /usr/bin/mysql -u root mysql
database_1 | mysql> show tables;
database_1 |
database_1 | Try 'mysqld --help' if you have problems with paths. Using
database_1 | --general-log gives you a log in /var/lib/mysql/ that may be helpful.
database_1 |
database_1 | The latest information about mysql_install_db is available at
database_1 | https://mariadb.com/kb/en/installing-system-tables-mysql_install_db
database_1 | You can find the latest source at https://downloads.mariadb.org and
database_1 | the maria-discuss email list at https://launchpad.net/~maria-discuss
database_1 |
database_1 | Please check all of the above before submitting a bug report
database_1 | at https://mariadb.org/jira
database_1 |
bitwardenextvol_database_1 exited with code 1
bitwarden_1 | 2023-01-16 06:26:02,303 INFO Included extra file "/etc/supervisor.d/admin.ini" during parsing
bitwarden_1 | 2023-01-16 06:26:02,303 INFO Included extra file "/etc/supervisor.d/api.ini" during parsing
bitwarden_1 | 2023-01-16 06:26:02,303 INFO Included extra file "/etc/supervisor.d/events.ini" during parsing
bitwarden_1 | 2023-01-16 06:26:02,303 INFO Included extra file "/etc/supervisor.d/icons.ini" during parsing
bitwarden_1 | 2023-01-16 06:26:02,303 INFO Included extra file "/etc/supervisor.d/identity.ini" during parsing
bitwarden_1 | 2023-01-16 06:26:02,303 INFO Included extra file "/etc/supervisor.d/nginx.ini" during parsing
bitwarden_1 | 2023-01-16 06:26:02,304 INFO Included extra file "/etc/supervisor.d/notifications.ini" during parsing
bitwarden_1 | 2023-01-16 06:26:02,304 INFO Included extra file "/etc/supervisor.d/scim.ini" during parsing
bitwarden_1 | 2023-01-16 06:26:02,304 INFO Included extra file "/etc/supervisor.d/sso.ini" during parsing
bitwarden_1 | 2023-01-16 06:26:02,314 INFO RPC interface 'supervisor' initialized
bitwarden_1 | 2023-01-16 06:26:02,314 CRIT Server 'unix_http_server' running without any HTTP authentication checking
bitwarden_1 | 2023-01-16 06:26:02,315 INFO supervisord started with pid 47
database_1 | 2023-01-16 06:26:02+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
database_1 | 2023-01-16 06:26:02+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.10.2+maria~ubu2204 started.
database_1 | 2023-01-16 06:26:02+00:00 [Note] [Entrypoint]: Initializing database files
database_1 | 2023-01-16 6:26:02 0 [Warning] Can't create test file /var/lib/mysql/4d6c9c2f7405.lower-test
database_1 | 2023-01-16 6:26:03 0 [ERROR] mariadbd: Can't create/write to file './ddl_recovery.log' (Errcode: 13 "Permission denied")
database_1 | 2023-01-16 6:26:03 0 [ERROR] DDL_LOG: Failed to create ddl log file: ./ddl_recovery.log
database_1 | 2023-01-16 6:26:03 0 [ERROR] Aborting
database_1 |
database_1 | Installation of system tables failed! Examine the logs in
database_1 | /var/lib/mysql/ for more information.
database_1 |
database_1 | The problem could be conflicting information in an external
database_1 | my.cnf files. You can ignore these by doing:
database_1 |
database_1 | shell> /usr/bin/mariadb-install-db --defaults-file=~/.my.cnf
database_1 |
database_1 | You can also try to start the mysqld daemon with:
database_1 |
database_1 | shell> /usr/sbin/mariadbd --skip-grant-tables --general-log &
database_1 |
database_1 | and use the command line tool /usr/bin/mariadb
database_1 | to connect to the mysql database and look at the grant tables:
database_1 |
database_1 | shell> /usr/bin/mysql -u root mysql
database_1 | mysql> show tables;
database_1 |
database_1 | Try 'mysqld --help' if you have problems with paths. Using
database_1 | --general-log gives you a log in /var/lib/mysql/ that may be helpful.
database_1 |
database_1 | The latest information about mysql_install_db is available at
database_1 | https://mariadb.com/kb/en/installing-system-tables-mysql_install_db
database_1 | You can find the latest source at https://downloads.mariadb.org and
database_1 | the maria-discuss email list at https://launchpad.net/~maria-discuss
database_1 |
database_1 | Please check all of the above before submitting a bug report
database_1 | at https://mariadb.org/jira
database_1 |
bitwarden_1 | 2023-01-16 06:26:03,318 INFO spawned: 'identity' with pid 48
bitwarden_1 | 2023-01-16 06:26:03,320 INFO spawned: 'admin' with pid 49
bitwarden_1 | 2023-01-16 06:26:03,322 INFO spawned: 'api' with pid 50
bitwarden_1 | 2023-01-16 06:26:03,324 INFO spawned: 'icons' with pid 51
bitwarden_1 | 2023-01-16 06:26:03,326 INFO spawned: 'nginx' with pid 52
bitwarden_1 | 2023-01-16 06:26:03,328 INFO spawned: 'notifications' with pid 53
Its either the UID mapping or a selinux label, (note the + in the ls -la output). With the selinux label its probably up to an selinux boolean to allow docker to access the volume. Specific selinux labels can also be applied at the mount time.
When checking uid mapping its helpful to look inside the container as the mappings may be different:
docker run -v data:/var/lib/mysql --rm mariadb ls -laZ /var/lib/mysql
Rather than putting user in compose you can get the CIFS to map the uid to the 999:999 user the mariadb container uses by default.
docker run --rm mariadb id mysql
uid=999(mysql) gid=999(mysql) groups=999(mysql)
Based of MDEV-26970, the conditions under which MariaDB under its default --innodb_flush_method=O_DIRECT work with CIFS is limited.
Changing the mount options of CIFS to include cache=none appears to be one solution.
The other is adding --innodb_flush_method=fsync to the mariadb container command.
command: --innodb_flush_method=fsync
Related
I'm having problems with docker-compose for a while now and can't figure out what's going on there. Given is the following scenario - which worked before but stopped working on a new project and now on every new stack I build up:
$ docker --version
Docker version 20.10.12, build e91ed57
$ docker-compose --version
Docker Compose version v2.2.2
OS: Pop!_OS 21.10 (NVIDIA)
Filestructure:
/myfolder
+ app-src (containing my laravel-project)
+ database-dumps (for database-dumps - containing a .gitkeep-file)
+ database_persist (for persistent data - containing a .gitkeep-file)
- .env
- .gitignore
- buildcontrainer.sh (custom script)
- container-start.sh (custom script)
- docker-compose.yml
- migrate-database.sh (custom script)
- README.md
This is the shortened docker-compose.yml-file (shortened, because it only affects the database... nginx and the php-container are working fine):
version: '3'
services:
database:
environment:
- MYSQL_DATABASE=${DB_DATABASE}
- MYSQL_USER=${DB_USER}
- MYSQL_PASSWORD=${DB_PASSWORD}
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
image: mariadb:10.6.1
ports:
- "${DB_EXPOSE_PORT}:3306"
volumes:
- "./database_persist:/var/lib/mysqldata"
And the .env-File:
COMPOSE_PROJECT_NAME=MyProject
DB_DATABASE="myprojectdb"
DB_USER="myproject"
DB_PASSWORD="12345"
DB_ROOT_PASSWORD="12345"
DB_EXPOSE_PORT=9036
WEB_EXPOSE_PORT_HTTP=9080
WEB_EXPOSE_PORT_HTTPS=9043
Now to my problem - whenever I try to set up an environment like given in the scenario and I run docker-compose build and docker-compose up afterwards I get the following output:
Creating network "myproject_default" with the default driver
Creating myproject_database_1 ... done
Attaching to myproject_database_1
database_1 | 2021-12-25 15:30:53+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.6.1+maria~focal started.
database_1 | 2021-12-25 15:30:53+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
database_1 | 2021-12-25 15:30:53+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.6.1+maria~focal started.
database_1 | 2021-12-25 15:30:53+00:00 [Note] [Entrypoint]: Initializing database files
database_1 | 2021-12-25 15:30:53 0 [Warning] You need to use --log-bin to make --expire-logs-days or --binlog-expire-logs-seconds work.
database_1 |
database_1 |
database_1 | PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
database_1 | To do so, start the server, then issue the following commands:
database_1 |
database_1 | '/usr/bin/mysqladmin' -u root password 'new-password'
database_1 | '/usr/bin/mysqladmin' -u root -h password 'new-password'
database_1 |
database_1 | Alternatively you can run:
database_1 | '/usr/bin/mysql_secure_installation'
database_1 |
database_1 | which will also give you the option of removing the test
database_1 | databases and anonymous user created by default. This is
database_1 | strongly recommended for production servers.
database_1 |
database_1 | See the MariaDB Knowledgebase at https://mariadb.com/kb or the
database_1 | MySQL manual for more instructions.
database_1 |
database_1 | Please report any problems at https://mariadb.org/jira
database_1 |
database_1 | The latest information about MariaDB is available at https://mariadb.org/.
database_1 | You can find additional information about the MySQL part at:
database_1 | https://dev.mysql.com
database_1 | Consider joining MariaDB's strong and vibrant community:
database_1 | https://mariadb.org/get-involved/
database_1 |
database_1 | 2021-12-25 15:30:57+00:00 [Note] [Entrypoint]: Database files initialized
database_1 | 2021-12-25 15:30:57+00:00 [Note] [Entrypoint]: Starting temporary server
database_1 | 2021-12-25 15:30:57+00:00 [Note] [Entrypoint]: Waiting for server startup
database_1 | 2021-12-25 15:30:57 0 [Note] mysqld (mysqld 10.6.1-MariaDB-1:10.6.1+maria~focal) starting as process 110 ...
database_1 | 2021-12-25 15:30:57 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
database_1 | 2021-12-25 15:30:57 0 [Note] InnoDB: Number of pools: 1
database_1 | 2021-12-25 15:30:57 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
database_1 | 2021-12-25 15:30:57 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
database_1 | 2021-12-25 15:30:57 0 [Note] InnoDB: Using Linux native AIO
database_1 | 2021-12-25 15:30:57 0 [Note] InnoDB: Initializing buffer pool, total size = 134217728, chunk size = 134217728
database_1 | 2021-12-25 15:30:57 0 [Note] InnoDB: Completed initialization of buffer pool
database_1 | 2021-12-25 15:30:57 0 [Note] InnoDB: 128 rollback segments are active.
database_1 | 2021-12-25 15:30:57 0 [Note] InnoDB: Creating shared tablespace for temporary tables
database_1 | 2021-12-25 15:30:57 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
database_1 | 2021-12-25 15:30:57 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
database_1 | 2021-12-25 15:30:57 0 [Note] InnoDB: 10.6.1 started; log sequence number 42616; transaction id 18
database_1 | 2021-12-25 15:30:57 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
database_1 | 2021-12-25 15:30:57 0 [Note] Plugin 'FEEDBACK' is disabled.
database_1 | 2021-12-25 15:30:57 0 [Warning] You need to use --log-bin to make --expire-logs-days or --binlog-expire-logs-seconds work.
database_1 | 2021-12-25 15:30:57 0 [Warning] 'user' entry 'root#66d18f02ea8a' ignored in --skip-name-resolve mode.
database_1 | 2021-12-25 15:30:57 0 [Warning] 'proxies_priv' entry '#% root#66d18f02ea8a' ignored in --skip-name-resolve mode.
database_1 | 2021-12-25 15:30:57 0 [Note] InnoDB: Buffer pool(s) load completed at 211225 15:30:57
database_1 | 2021-12-25 15:30:57 0 [Note] mysqld: ready for connections.
database_1 | Version: '10.6.1-MariaDB-1:10.6.1+maria~focal' socket: '/run/mysqld/mysqld.sock' port: 0 mariadb.org binary distribution
database_1 | 2021-12-25 15:30:58+00:00 [Note] [Entrypoint]: Temporary server started.
database_1 | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
database_1 | Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
database_1 | Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
database_1 | 2021-12-25 15:31:01 5 [Warning] 'proxies_priv' entry '#% root#66d18f02ea8a' ignored in --skip-name-resolve mode.
database_1 | 2021-12-25 15:31:01+00:00 [Note] [Entrypoint]: Creating database myprojectdb
database_1 | 2021-12-25 15:31:01+00:00 [Note] [Entrypoint]: Creating user myproject
database_1 | 2021-12-25 15:31:01+00:00 [Note] [Entrypoint]: Giving user myproject access to schema myprojectdb
database_1 |
database_1 | 2021-12-25 15:31:01+00:00 [Note] [Entrypoint]: Stopping temporary server
database_1 | 2021-12-25 15:31:01 0 [Note] mysqld (initiated by: root[root] # localhost []): Normal shutdown
database_1 | 2021-12-25 15:31:01 0 [Note] InnoDB: FTS optimize thread exiting.
database_1 | 2021-12-25 15:31:01 0 [Note] InnoDB: Starting shutdown...
database_1 | 2021-12-25 15:31:01 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
database_1 | 2021-12-25 15:31:01 0 [Note] InnoDB: Buffer pool(s) dump completed at 211225 15:31:01
database_1 | 2021-12-25 15:31:01 0 [Note] InnoDB: Removed temporary tablespace data file: "./ibtmp1"
database_1 | 2021-12-25 15:31:01 0 [Note] InnoDB: Shutdown completed; log sequence number 42628; transaction id 19
database_1 | 2021-12-25 15:31:01 0 [Note] mysqld: Shutdown complete
database_1 |
database_1 | 2021-12-25 15:31:02+00:00 [Note] [Entrypoint]: Temporary server stopped
database_1 |
database_1 | 2021-12-25 15:31:02+00:00 [Note] [Entrypoint]: MariaDB init process done. Ready for start up.
database_1 |
database_1 | 2021-12-25 15:31:02 0 [Note] mysqld (mysqld 10.6.1-MariaDB-1:10.6.1+maria~focal) starting as process 1 ...
database_1 | 2021-12-25 15:31:02 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
database_1 | 2021-12-25 15:31:02 0 [Note] InnoDB: Number of pools: 1
database_1 | 2021-12-25 15:31:02 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
database_1 | 2021-12-25 15:31:02 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
database_1 | 2021-12-25 15:31:02 0 [Note] InnoDB: Using Linux native AIO
database_1 | 2021-12-25 15:31:02 0 [Note] InnoDB: Initializing buffer pool, total size = 134217728, chunk size = 134217728
database_1 | 2021-12-25 15:31:02 0 [Note] InnoDB: Completed initialization of buffer pool
database_1 | 2021-12-25 15:31:02 0 [Note] InnoDB: 128 rollback segments are active.
database_1 | 2021-12-25 15:31:02 0 [Note] InnoDB: Creating shared tablespace for temporary tables
database_1 | 2021-12-25 15:31:02 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
database_1 | 2021-12-25 15:31:02 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
database_1 | 2021-12-25 15:31:02 0 [Note] InnoDB: 10.6.1 started; log sequence number 42628; transaction id 18
database_1 | 2021-12-25 15:31:02 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
database_1 | 2021-12-25 15:31:02 0 [Note] Plugin 'FEEDBACK' is disabled.
database_1 | 2021-12-25 15:31:02 0 [Warning] You need to use --log-bin to make --expire-logs-days or --binlog-expire-logs-seconds work.
database_1 | 2021-12-25 15:31:02 0 [Note] Server socket created on IP: '0.0.0.0'.
database_1 | 2021-12-25 15:31:02 0 [Note] Server socket created on IP: '::'.
database_1 | 2021-12-25 15:31:02 0 [Warning] 'proxies_priv' entry '#% root#66d18f02ea8a' ignored in --skip-name-resolve mode.
database_1 | 2021-12-25 15:31:02 0 [Note] InnoDB: Buffer pool(s) load completed at 211225 15:31:02
database_1 | 2021-12-25 15:31:02 0 [Note] mysqld: ready for connections.
database_1 | Version: '10.6.1-MariaDB-1:10.6.1+maria~focal' socket: '/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution
It looks to me as if the .env-parameters are not given to the database-container anymore. All attempts recreating the database-container with docker-compose build, or removing all images via docker image prune and docker-compose pull have been in vain. I have updated my OS from 21.04 to 21.10 two days ago, but I don't think it causes the issue (just stated it here if it does). Does someone has an idea on how to fix this? Setting the MYSQL_ROOT_PASSWORD directly in the docker-compose.yml did not help either. The permission on database_persist are set via sudo chown -R $USER:$USER database_persist/ so that should not be an issue as well.
Thanks (and merry Christmas :) )
Edit: I tried reinstalling docker and updating docker-compose to version 2.2.2 (edited accordingly), but it had no effect. One of the commentors asked if I can connect to the container. Yes, I can, but not as root.
The .env file can be parsed as a part of the docker-compose.yaml. Though I personally never used this the way you do, as you can also pass a file directly into the container. With the env_file key
version: '3'
services:
database:
env_file: .env
image: mariadb:10.6.1
ports:
- "${DB_EXPOSE_PORT}:3306"
volumes:
- "./database_persist:/var/lib/mysqldata"
Obviously, you then also need to change the variable names in your .env file. And I personally would rename it to a more clear name.
Okay - for some weird reason the output stays the same, but when I try to login the dbroot and the dbuser actually use their passwords specified in the env-files. Plus using anything else will result in a "access denied". So I don't know if the update fixed the issue or if the logoutput just scared me and this is actually the expected behaviour. I will update this if I get any new insights.
I have spent the last few hours debugging my system and I am at a loss as to what is going on here.
I am using a simple docker-compose.yml file to start a mariadb and an adminer instance on my Ubuntu 20.04 LTS system.
docker-compose.yml:
version: '3'
services:
database:
image: mariadb
restart: always
environment:
MYSQL_DATABASE: feedback
MYSQL_USER: db_user
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: root
adminer:
image: adminer
restart: always
environment:
ADMINER_DEFAULT_SERVER: database
ports:
- "127.0.0.1:8080:8080"
A coworker tested this and it works 100% of the time on their system. However, it only worked twice out of many, many tries in the last few hours one my system.
This is the docker-compose output:
Creating knowledge-base_database_1 ... done
Creating knowledge-base_adminer_1 ... done
Attaching to knowledge-base_adminer_1, knowledge-base_database_1
database_1 | 2021-05-31 12:17:04+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.5.10+maria~focal started.
adminer_1 | [Mon May 31 12:17:04 2021] PHP 7.4.19 Development Server (http://[::]:8080) started
database_1 | 2021-05-31 12:17:04+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
database_1 | 2021-05-31 12:17:04+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.5.10+maria~focal started.
database_1 | 2021-05-31 12:17:05+00:00 [Note] [Entrypoint]: Initializing database files
database_1 |
database_1 |
database_1 | PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
database_1 | To do so, start the server, then issue the following command:
database_1 |
database_1 | '/usr/bin/mysql_secure_installation'
database_1 |
database_1 | which will also give you the option of removing the test
database_1 | databases and anonymous user created by default. This is
database_1 | strongly recommended for production servers.
database_1 |
database_1 | See the MariaDB Knowledgebase at https://mariadb.com/kb or the
database_1 | MySQL manual for more instructions.
database_1 |
database_1 | Please report any problems at https://mariadb.org/jira
database_1 |
database_1 | The latest information about MariaDB is available at https://mariadb.org/.
database_1 | You can find additional information about the MySQL part at:
database_1 | https://dev.mysql.com
database_1 | Consider joining MariaDB's strong and vibrant community:
database_1 | https://mariadb.org/get-involved/
database_1 |
database_1 | 2021-05-31 12:17:06+00:00 [Note] [Entrypoint]: Database files initialized
database_1 | 2021-05-31 12:17:06+00:00 [Note] [Entrypoint]: Starting temporary server
database_1 | 2021-05-31 12:17:06+00:00 [Note] [Entrypoint]: Waiting for server startup
database_1 | 2021-05-31 12:17:06 0 [Note] mysqld (mysqld 10.5.10-MariaDB-1:10.5.10+maria~focal) starting as process 99 ...
database_1 | 2021-05-31 12:17:06 0 [Note] InnoDB: Uses event mutexes
database_1 | 2021-05-31 12:17:06 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
database_1 | 2021-05-31 12:17:06 0 [Note] InnoDB: Number of pools: 1
database_1 | 2021-05-31 12:17:06 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
database_1 | 2021-05-31 12:17:06 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
database_1 | 2021-05-31 12:17:06 0 [Note] InnoDB: Using Linux native AIO
database_1 | 2021-05-31 12:17:06 0 [Note] InnoDB: Initializing buffer pool, total size = 134217728, chunk size = 134217728
database_1 | 2021-05-31 12:17:06 0 [Note] InnoDB: Completed initialization of buffer pool
database_1 | 2021-05-31 12:17:06 0 [Note] InnoDB: 128 rollback segments are active.
database_1 | 2021-05-31 12:17:06 0 [Note] InnoDB: Creating shared tablespace for temporary tables
database_1 | 2021-05-31 12:17:06 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
database_1 | 2021-05-31 12:17:06 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
database_1 | 2021-05-31 12:17:06 0 [Note] InnoDB: 10.5.10 started; log sequence number 45118; transaction id 20
database_1 | 2021-05-31 12:17:06 0 [Note] Plugin 'FEEDBACK' is disabled.
database_1 | 2021-05-31 12:17:06 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
database_1 | 2021-05-31 12:17:06 0 [Note] InnoDB: Buffer pool(s) load completed at 210531 12:17:06
database_1 | 2021-05-31 12:17:06 0 [Warning] 'user' entry 'root#5315aa145a33' ignored in --skip-name-resolve mode.
database_1 | 2021-05-31 12:17:06 0 [Warning] 'proxies_priv' entry '#% root#5315aa145a33' ignored in --skip-name-resolve mode.
database_1 | 2021-05-31 12:17:06 0 [Note] Reading of all Master_info entries succeeded
database_1 | 2021-05-31 12:17:06 0 [Note] Added new Master_info '' to hash table
database_1 | 2021-05-31 12:17:06 0 [Note] mysqld: ready for connections.
database_1 | Version: '10.5.10-MariaDB-1:10.5.10+maria~focal' socket: '/run/mysqld/mysqld.sock' port: 0 mariadb.org binary distribution
database_1 | 2021-05-31 12:17:07+00:00 [Note] [Entrypoint]: Temporary server started.
database_1 | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
database_1 | Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
database_1 | Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
database_1 | 2021-05-31 12:17:09 5 [Warning] 'proxies_priv' entry '#% root#5315aa145a33' ignored in --skip-name-resolve mode.
database_1 | 2021-05-31 12:17:09+00:00 [Note] [Entrypoint]: Creating database feedback
database_1 | 2021-05-31 12:17:09+00:00 [Note] [Entrypoint]: Creating user db_user
database_1 | 2021-05-31 12:17:09+00:00 [Note] [Entrypoint]: Giving user db_user access to schema feedback
database_1 |
database_1 | 2021-05-31 12:17:09+00:00 [Note] [Entrypoint]: Stopping temporary server
database_1 | 2021-05-31 12:17:09 0 [Note] mysqld (initiated by: root[root] # localhost []): Normal shutdown
database_1 | 2021-05-31 12:17:09 0 [Note] Event Scheduler: Purging the queue. 0 events
database_1 | 2021-05-31 12:17:09 0 [Note] InnoDB: FTS optimize thread exiting.
database_1 | 2021-05-31 12:17:09 0 [Note] InnoDB: Starting shutdown...
database_1 | 2021-05-31 12:17:09 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
database_1 | 2021-05-31 12:17:09 0 [Note] InnoDB: Buffer pool(s) dump completed at 210531 12:17:09
database_1 | 2021-05-31 12:17:09 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
database_1 | 2021-05-31 12:17:09 0 [Note] InnoDB: Shutdown completed; log sequence number 45130; transaction id 21
database_1 | 2021-05-31 12:17:09 0 [Note] mysqld: Shutdown complete
database_1 |
database_1 | 2021-05-31 12:17:10+00:00 [Note] [Entrypoint]: Temporary server stopped
database_1 |
database_1 | 2021-05-31 12:17:10+00:00 [Note] [Entrypoint]: MariaDB init process done. Ready for start up.
database_1 |
database_1 | 2021-05-31 12:17:10 0 [Note] mysqld (mysqld 10.5.10-MariaDB-1:10.5.10+maria~focal) starting as process 1 ...
database_1 | 2021-05-31 12:17:10 0 [Note] InnoDB: Uses event mutexes
database_1 | 2021-05-31 12:17:10 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
database_1 | 2021-05-31 12:17:10 0 [Note] InnoDB: Number of pools: 1
database_1 | 2021-05-31 12:17:10 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
database_1 | 2021-05-31 12:17:10 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
database_1 | 2021-05-31 12:17:10 0 [Note] InnoDB: Using Linux native AIO
database_1 | 2021-05-31 12:17:10 0 [Note] InnoDB: Initializing buffer pool, total size = 134217728, chunk size = 134217728
database_1 | 2021-05-31 12:17:10 0 [Note] InnoDB: Completed initialization of buffer pool
database_1 | 2021-05-31 12:17:10 0 [Note] InnoDB: 128 rollback segments are active.
database_1 | 2021-05-31 12:17:10 0 [Note] InnoDB: Creating shared tablespace for temporary tables
database_1 | 2021-05-31 12:17:10 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
database_1 | 2021-05-31 12:17:10 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
database_1 | 2021-05-31 12:17:10 0 [Note] InnoDB: 10.5.10 started; log sequence number 45130; transaction id 20
database_1 | 2021-05-31 12:17:10 0 [Note] Plugin 'FEEDBACK' is disabled.
database_1 | 2021-05-31 12:17:10 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
database_1 | 2021-05-31 12:17:10 0 [Note] InnoDB: Buffer pool(s) load completed at 210531 12:17:10
database_1 | 2021-05-31 12:17:10 0 [Note] Server socket created on IP: '::'.
database_1 | 2021-05-31 12:17:10 0 [Warning] 'proxies_priv' entry '#% root#5315aa145a33' ignored in --skip-name-resolve mode.
database_1 | 2021-05-31 12:17:10 0 [Note] Reading of all Master_info entries succeeded
database_1 | 2021-05-31 12:17:10 0 [Note] Added new Master_info '' to hash table
database_1 | 2021-05-31 12:17:10 0 [Note] mysqld: ready for connections.
database_1 | Version: '10.5.10-MariaDB-1:10.5.10+maria~focal' socket: '/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution
Trying to log into the database with adminer using root:root produces the following output:
adminer_1 | [Mon May 31 12:17:54 2021] [::ffff:172.25.0.1]:38170 Accepted
adminer_1 | [Mon May 31 12:17:54 2021] [::ffff:172.25.0.1]:38170 [302]: POST /?server=database&username=root
adminer_1 | [Mon May 31 12:17:54 2021] [::ffff:172.25.0.1]:38170 Closing
adminer_1 | [Mon May 31 12:17:54 2021] [::ffff:172.25.0.1]:38174 Accepted
adminer_1 | [Mon May 31 12:18:24 2021] [::ffff:172.25.0.1]:38174 [403]: GET /?server=database&username=root
adminer_1 | [Mon May 31 12:18:24 2021] [::ffff:172.25.0.1]:38174 Closing
adminer_1 | [Mon May 31 12:18:24 2021] [::ffff:172.25.0.1]:38208 Accepted
adminer_1 | [Mon May 31 12:18:24 2021] [::ffff:172.25.0.1]:38208 [200]: GET /?file=favicon.ico&version=4.8.0
adminer_1 | [Mon May 31 12:18:24 2021] [::ffff:172.25.0.1]:38208 Closing
I have tried disabling my firewall, reinstalling docker and docker-compose, creating a custom network with docker instead of using docker-compose's default network, etc.
I also started a known-working project on my system, which yielded the same results. Something on my system seems to be broken, but I don't know where to look anymore.
Does anyone have any ideas what I can try to get this working?
Try appending /index.php so instead of http://localhost go to http://localhost/index.php
I am pretty new to Docker and Django. I am trying to set up a Django project for a REST-ful API running in a Docker container. I am trying to import the relavent python packages from a RUN command in the dockerfile, however, not all the packages are successfully installing.
Here are the files I'm using and the error I am getting.
Dockerfile:
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt .
RUN pip install --upgrade pip
RUN pip install -r requirements.txt
COPY . .
docker-compose.yml:
version: '3'
services:
db:
image: postgres
environment:
POSTGRES_PASSWORD: password
web:
build: .
# command: bash -c "pip install -r requirements.txt && python manage.py runserver 0.0.0.0:8000"
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
requirements.txt
djangorestframework
django-filter
markdown
Django
psycopg2
When I execute docker-compose up I get this output
Starting apiTest_db_1 ... done
Recreating apiTest_web_1 ... done
Attaching to apiTest_db_1, apiTest_web_1
db_1 |
db_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization
db_1 |
db_1 | 2020-04-17 21:35:57.022 UTC [1] LOG: starting PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1 | 2020-04-17 21:35:57.023 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2020-04-17 21:35:57.023 UTC [1] LOG: listening on IPv6 address "::", port 5432
db_1 | 2020-04-17 21:35:57.028 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2020-04-17 21:35:57.075 UTC [27] LOG: database system was shut down at 2020-04-17 21:34:34 UTC
db_1 | 2020-04-17 21:35:57.100 UTC [1] LOG: database system is ready to accept connections
web_1 | Watching for file changes with StatReloader
web_1 | Exception in thread django-main-thread:
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
web_1 | self.run()
web_1 | File "/usr/local/lib/python3.8/threading.py", line 870, in run
web_1 | self._target(*self._args, **self._kwargs)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/autoreload.py", line 53, in wrapper
web_1 | fn(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
web_1 | autoreload.raise_last_exception()
web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/autoreload.py", line 76, in raise_last_exception
web_1 | raise _exception[1]
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 357, in execute
web_1 | autoreload.check_errors(django.setup)()
web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/autoreload.py", line 53, in wrapper
web_1 | fn(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
web_1 | apps.populate(settings.INSTALLED_APPS)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/apps/registry.py", line 91, in populate
web_1 | app_config = AppConfig.create(entry)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/apps/config.py", line 90, in create
web_1 | module = import_module(entry)
web_1 | File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
web_1 | return _bootstrap._gcd_import(name[level:], package, level)
web_1 | File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
web_1 | File "<frozen importlib._bootstrap>", line 991, in _find_and_load
web_1 | File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
web_1 | ModuleNotFoundError: No module named 'rest_framework'
Which indicates that djangorestframework has not been installed by pip.
Furthermore, when I switch the comented line in the docker-compose.yml file for the line below it (so that section becomes)
command: bash -c "pip install -r requirements.txt && python manage.py runserver 0.0.0.0:8000"
# command: python manage.py runserver 0.0.0.0:8000
Then when I run docker-compose up I get the following output.
Creating network "apiTest_default" with the default driver
Creating apiTest_db_1 ... done
Creating apiTest_web_1 ... done
Attaching to apiTest_db_1, apiTest_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 dynamic shared memory implementation ... posix
db_1 | selecting default max_connections ... 100
db_1 | selecting default shared_buffers ... 128MB
db_1 | selecting default time zone ... Etc/UTC
db_1 | creating configuration files ... ok
db_1 | running bootstrap script ... ok
db_1 | performing post-bootstrap initialization ... ok
web_1 | Collecting djangorestframework
db_1 | syncing data to disk ... initdb: 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 | ok
db_1 |
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 | waiting for server to start....2020-04-17 22:47:22.783 UTC [46] LOG: starting PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1 | 2020-04-17 22:47:22.789 UTC [46] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
web_1 | Downloading djangorestframework-3.11.0-py3-none-any.whl (911 kB)
db_1 | 2020-04-17 22:47:22.823 UTC [47] LOG: database system was shut down at 2020-04-17 22:47:22 UTC
db_1 | 2020-04-17 22:47:22.841 UTC [46] LOG: database system is ready to accept connections
db_1 | done
db_1 | server started
db_1 |
db_1 | /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
db_1 |
db_1 | 2020-04-17 22:47:22.885 UTC [46] LOG: received fast shutdown request
db_1 | waiting for server to shut down....2020-04-17 22:47:22.889 UTC [46] LOG: aborting any active transactions
db_1 | 2020-04-17 22:47:22.908 UTC [46] LOG: background worker "logical replication launcher" (PID 53) exited with exit code 1
db_1 | 2020-04-17 22:47:22.920 UTC [48] LOG: shutting down
db_1 | 2020-04-17 22:47:22.974 UTC [46] 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 | 2020-04-17 22:47:23.021 UTC [1] LOG: starting PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
db_1 | 2020-04-17 22:47:23.022 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2020-04-17 22:47:23.023 UTC [1] LOG: listening on IPv6 address "::", port 5432
db_1 | 2020-04-17 22:47:23.036 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2020-04-17 22:47:23.063 UTC [55] LOG: database system was shut down at 2020-04-17 22:47:22 UTC
db_1 | 2020-04-17 22:47:23.073 UTC [1] LOG: database system is ready to accept connections
web_1 | Collecting django-filter
web_1 | Downloading django_filter-2.2.0-py3-none-any.whl (69 kB)
web_1 | Collecting markdown
web_1 | Downloading Markdown-3.2.1-py2.py3-none-any.whl (88 kB)
web_1 | Requirement already satisfied: Django in /usr/local/lib/python3.8/site-packages (from -r requirements.txt (line 4)) (3.0.5)
web_1 | Requirement already satisfied: psycopg2 in /usr/local/lib/python3.8/site-packages (from -r requirements.txt (line 5)) (2.8.5)
web_1 | Requirement already satisfied: setuptools>=36 in /usr/local/lib/python3.8/site-packages (from markdown->-r requirements.txt (line 3)) (46.1.3)
web_1 | Requirement already satisfied: pytz in /usr/local/lib/python3.8/site-packages (from Django->-r requirements.txt (line 4)) (2019.3)
web_1 | Requirement already satisfied: sqlparse>=0.2.2 in /usr/local/lib/python3.8/site-packages (from Django->-r requirements.txt (line 4)) (0.3.1)
web_1 | Requirement already satisfied: asgiref~=3.2 in /usr/local/lib/python3.8/site-packages (from Django->-r requirements.txt (line 4)) (3.2.7)
web_1 | Installing collected packages: djangorestframework, django-filter, markdown
web_1 | Successfully installed django-filter-2.2.0 djangorestframework-3.11.0 markdown-3.2.1
web_1 | Watching for file changes with StatReloader
web_1 | Performing system checks...
web_1 |
web_1 | System check identified no issues (0 silenced).
web_1 |
web_1 | You have 17 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 | April 17, 2020 - 22:47:25
web_1 | Django version 3.0.5, using settings 'apiTesting.settings'
web_1 | Starting development server at http://0.0.0.0:8000/
web_1 | Quit the server with CONTROL-C.
Which shows that some packages such as Django have been successfully installed by the Dockerfile but some like djangorestframework, django-filter and markdown have not.
Why is this and what can I do in my Dockerfile to make them correctly install?
Both the main problem and the problem mentioned in the comments of itamar-turner-trauring's answer were solved by instead of running docker-compose up running
docker-compose up --build
Not 100% sure why this fixed it but I'd guess the compose file was loaing up the container from an old image which didn't include the new python packages. So forcing it to rebuild made it include the new python packages.
You are doing two things that potentially conflict:
Inside the image, as part of the build you copy everything in to /code.
In the compose file you mount current working directory into /code.
I am not sure that's the problem, but I suggest removing the volumes bit from the compose.yml and see if that help.
I am trying to create a hybrid container.
Following is my docker-compose file.
version: "2"
services:
database:
build:
context: ./registration-database
image: registration-database
# set default mysql root password, change as needed
environment:
MYSQL_ROOT_PASSWORD: password
# Expose port 3306 to host.
ports:
- "3306:3306"
restart: always
webserver:
build:
context: ./registration-webserver
image: registration-webserver
# mount point for application in tomcat
volumes:
- ./app/target/UserSignup:/usr/local/tomcat/webapps/UserSignup
links:
- database:registration-database
# open ports for tomcat and remote debugging
ports:
- "8080:8080"
- "8000:8000"
restart: always
Following is the dockerFile for mysql:
FROM mysql:5.7
# Copy the database initialize script:
# Contents of /docker-entrypoint-initdb.d are run on mysqld startup
ADD docker-entrypoint-initdb.d/ /docker-entrypoint-initdb.d/
ENV MYSQL_DATABASE=ishan
ENV MYSQL_USER=ishan
ENV MYSQL_PASSWORD=password
Following is the initialize_db.sql file
USE `ishan`;
CREATE TABLE `user` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`dateOfBirth` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ,
`emailAddress` varchar(255) NOT NULL,
`firstName` varchar(255) NOT NULL,
`lastName` varchar(255) NOT NULL,
`password` varchar(8) NOT NULL,
`userName` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=latin1;
Earlier when I was running the command docker-compose up it was creating the user ishan and it was creating the user table also. But now, suddenly something happened although the mysql is getting installed with the root user but the new user (ishan) and the table is not getting created. Any help is appreciated.
Following is the log which is getting printed on startup:
Starting app_database_1 ... done
Starting app_webserver_1 ... done
Attaching to app_database_1, app_webserver_1
database_1 | 2019-04-09T08:30:51.326732Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
database_1 | 2019-04-09T08:30:51.327850Z 0 [Note] mysqld (mysqld 5.7.25) starting as process 1 ...
database_1 | 2019-04-09T08:30:51.330081Z 0 [Note] InnoDB: PUNCH HOLE support available
database_1 | 2019-04-09T08:30:51.330114Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
database_1 | 2019-04-09T08:30:51.330118Z 0 [Note] InnoDB: Uses event mutexes
database_1 | 2019-04-09T08:30:51.330121Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
database_1 | 2019-04-09T08:30:51.330125Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
database_1 | 2019-04-09T08:30:51.330127Z 0 [Note] InnoDB: Using Linux native AIO
database_1 | 2019-04-09T08:30:51.330295Z 0 [Note] InnoDB: Number of pools: 1
database_1 | 2019-04-09T08:30:51.330382Z 0 [Note] InnoDB: Using CPU crc32 instructions
database_1 | 2019-04-09T08:30:51.331394Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
database_1 | 2019-04-09T08:30:51.336481Z 0 [Note] InnoDB: Completed initialization of buffer pool
database_1 | 2019-04-09T08:30:51.338022Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
database_1 | 2019-04-09T08:30:51.356556Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
database_1 | 2019-04-09T08:30:51.372677Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
database_1 | 2019-04-09T08:30:51.372933Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
database_1 | 2019-04-09T08:30:51.398496Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
database_1 | 2019-04-09T08:30:51.399884Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
database_1 | 2019-04-09T08:30:51.399990Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
database_1 | 2019-04-09T08:30:51.400792Z 0 [Note] InnoDB: 5.7.25 started; log sequence number 12359503
database_1 | 2019-04-09T08:30:51.401039Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
database_1 | 2019-04-09T08:30:51.401382Z 0 [Note] Plugin 'FEDERATED' is disabled.
database_1 | 2019-04-09T08:30:51.419097Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
database_1 | 2019-04-09T08:30:51.421195Z 0 [Warning] CA certificate ca.pem is self signed.
database_1 | 2019-04-09T08:30:51.423199Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
database_1 | 2019-04-09T08:30:51.423332Z 0 [Note] IPv6 is available.
database_1 | 2019-04-09T08:30:51.423468Z 0 [Note] - '::' resolves to '::';
database_1 | 2019-04-09T08:30:51.423622Z 0 [Note] Server socket created on IP: '::'.
database_1 | 2019-04-09T08:30:51.430839Z 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.
database_1 | 2019-04-09T08:30:51.434012Z 0 [Note] InnoDB: Buffer pool(s) load completed at 190409 8:30:51
database_1 | 2019-04-09T08:30:51.437767Z 0 [Warning] 'user' entry 'root#localhost' ignored in --skip-name-resolve mode.
database_1 | 2019-04-09T08:30:51.437887Z 0 [Warning] 'user' entry 'mysql.session#localhost' ignored in --skip-name-resolve mode.
database_1 | 2019-04-09T08:30:51.438037Z 0 [Warning] 'user' entry 'mysql.sys#localhost' ignored in --skip-name-resolve mode.
database_1 | 2019-04-09T08:30:51.438612Z 0 [Warning] 'db' entry 'performance_schema mysql.session#localhost' ignored in --skip-name-resolve mode.
database_1 | 2019-04-09T08:30:51.438712Z 0 [Warning] 'db' entry 'sys mysql.sys#localhost' ignored in --skip-name-resolve mode.
database_1 | 2019-04-09T08:30:51.439004Z 0 [Warning] 'proxies_priv' entry '# root#localhost' ignored in --skip-name-resolve mode.
database_1 | 2019-04-09T08:30:51.451035Z 0 [Warning] 'tables_priv' entry 'user mysql.session#localhost' ignored in --skip-name-resolve mode.
database_1 | 2019-04-09T08:30:51.451161Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys#localhost' ignored in --skip-name-resolve mode.
database_1 | 2019-04-09T08:30:51.484566Z 0 [Note] Event Scheduler: Loaded 0 events
database_1 | 2019-04-09T08:30:51.485090Z 0 [Note] mysqld: ready for connections.
database_1 | Version: '5.7.25' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
Most probably your volume is still present and for that reason MySQL ignores the entrypoint folder. You need to delete the volume between runs to get a fresh start. Be aware that this means losing data saved in mysql in the meantime.
docker-compose down
# this will clean all volumes not in use by any containers
docker volume prune
Run docker volume ls to make sure your volume is gone and then run your docker-compose again.
I have a Windows 10 Pro PC.
I have the following in my docker compose file
database:
image: mariadb:5.5.57
ports:
- "3306:3306"
volumes:
- ./sql/:/docker-entrypoint-initdb.d/
- ./data:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=rootUsr
- MYSQL_PASSWORD=rootPwd
- MYSQL_DATABASE=root_db
When I run docker-compose up - I get this error in the console
database_1 | InnoDB: 0 pages (rounded down to MB) than specified in the .cnf file:
database_1 | InnoDB: initial 640 pages, max 0 (relevant if non-zero) pages!
database_1 | 180324 17:12:47 InnoDB: Could not open or create data files.
database_1 | 180324 17:12:47 InnoDB: If you tried to add new data files, and it failed here,
database_1 | 180324 17:12:47 InnoDB: you should now edit innodb_data_file_path in my.cnf back
database_1 | 180324 17:12:47 InnoDB: to what it was, and remove the new ibdata files InnoDB created
consumer_1 | Starting the development server...
database_1 | 180324 17:12:47 InnoDB: in this failed attempt. InnoDB only wrote those files full of
database_1 | 180324 17:12:47 InnoDB: zeros, but did not yet use them in any way. But be careful: do not
database_1 | 180324 17:12:47 InnoDB: remove old data files which contain your precious data!
database_1 | 180324 17:12:47 [ERROR] Plugin 'InnoDB' init function returned error.
database_1 | 180324 17:12:47 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
database_1 | 180324 17:12:47 [Note] Plugin 'FEEDBACK' is disabled.
database_1 | 180324 17:12:47 [ERROR] Unknown/unsupported storage engine: InnoDB
database_1 | 180324 17:12:47 [ERROR] Aborting
Do I need to do anything else to get maria db running in docker?
Update
I have tried deleting all the volumes and doing a rebuild but I still get the same error as below
Deleted the volumes from the compose file and it worked fine.
Update
Tried the same docker compose file on an Amazon EC2 instance and it worked fine the first time around