简体   繁体   English

docker-compose 似乎忽略了 mariadb 上的.env-variables

[英]docker-compose seems to ignore .env-variables on mariadb

I'm having problems with docker-compose for a while now and can't figure out what's going on there.我在一段时间内遇到了docker-compose的问题,无法弄清楚那里发生了什么。 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):这是缩短的docker-compose.yml-file (缩短,因为它只影响数据库...... nginx 和 php 容器工作正常):

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:和 .env 文件:

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:现在我的问题 - 每当我尝试设置场景中给出的环境并运行docker-compose builddocker-compose up之后,我都会得到以下 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.在我看来,好像.env-parameters不再提供给数据库容器。 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.所有使用docker-compose build重新创建数据库容器,或通过docker image prunedocker-compose pull删除所有图像的尝试都是徒劳的。 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).两天前我已将我的操作系统从 21.04 更新到 21.10,但我认为这不会导致问题(如果确实如此,请在此处说明)。 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 docker-compose.yml中设置MYSQL_ROOT_PASSWORD也没有帮助。 The permission on database_persist are set via sudo chown -R $USER:$USER database_persist/ so that should not be an issue as well. database_persist 的权限是通过sudo chown -R $USER:$USER database_persist/设置的,因此这也不应该成为问题。

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.编辑:我尝试重新安装 docker 并将 docker-compose 更新到版本 2.2.2(相应编辑),但没有效果。 One of the commentors asked if I can connect to the container.其中一位评论者问我是否可以连接到容器。 Yes, I can, but not as root.是的,我可以,但不能以 root 身份。

The .env file can be parsed as a part of the docker-compose.yaml . .env文件可以被解析为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使用env_file

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.显然,您还需要更改 .env 文件中的变量名称。 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.好的-由于某些奇怪的原因,output 保持不变,但是当我尝试登录 dbroot 时,dbuser 实际上使用了在 env 文件中指定的密码。 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.如果我有任何新的见解,我会更新这个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM