I am trying to create a docker machine that will run 3 containers:
Wordpress, mysql and phpMyAdmin. This is my docker compose file:
version: '3.1'
services:
wordpress:
volumes:
- E:\Demo Sites\testSite\public_html:/var/www/html
depends_on:
- db
image: wordpress:latest
restart: unless-stopped
ports:
- 8080:80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: user2
WORDPRESS_DB_PASSWORD: pass2
WORDPRESS_DB_NAME: db2
db:
image: mysql:5.7
restart: always
ports:
- 3306:3306
environment:
MYSQL_DATABASE: db2
MYSQL_USER: user2
MYSQL_PASSWORD: pass2
MYSQL_ROOT_PASSWORD: test_pass2
volumes:
- db_data:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
links:
- db:db
restart: always
depends_on:
- db
ports:
- 9191:80
environment:
MYSQL_USERNAME: root
MYSQL_ROOT_PASSWORD: test_pass2
MYSQL_PASSWORD: test_pass2
volumes:
db_data:
I ran docker system prune in order to start fresh. Then, I ran the file using docker-compose up. phpMyAdmin works as expected, but I can't reach the wordpress site at 192.168.99.100:8080. These are the logs:
Creating demosites_db_1 ... done
Creating demosites_phpmyadmin_1 ... done
Creating demosites_wordpress_1 ... done
Attaching to demosites_db_1, demosites_phpmyadmin_1, demosites_wordpress_1
db_1 | 2018-12-25T14:30:06.003349Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1 | 2018-12-25T14:30:06.014038Z 0 [Note] mysqld (mysqld 5.7.24) starting as process 1 ...
db_1 | 2018-12-25T14:30:06.030769Z 0 [Note] InnoDB: PUNCH HOLE support available
db_1 | 2018-12-25T14:30:06.030841Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1 | 2018-12-25T14:30:06.030868Z 0 [Note] InnoDB: Uses event mutexes
db_1 | 2018-12-25T14:30:06.030890Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
db_1 | 2018-12-25T14:30:06.030911Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
db_1 | 2018-12-25T14:30:06.030932Z 0 [Note] InnoDB: Using Linux native AIO
db_1 | 2018-12-25T14:30:06.043746Z 0 [Note] InnoDB: Number of pools: 1
db_1 | 2018-12-25T14:30:06.075840Z 0 [Note] InnoDB: Using CPU crc32 instructions
db_1 | 2018-12-25T14:30:06.084608Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
db_1 | 2018-12-25T14:30:06.147100Z 0 [Note] InnoDB: Completed initialization of buffer pool
db_1 | 2018-12-25T14:30:06.196456Z 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 | 2018-12-25T14:30:06.245622Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
db_1 | 2018-12-25T14:30:06.503315Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db_1 | 2018-12-25T14:30:06.504395Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db_1 | 2018-12-25T14:30:06.739272Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db_1 | 2018-12-25T14:30:06.742497Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
db_1 | 2018-12-25T14:30:06.743304Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
db_1 | 2018-12-25T14:30:06.744156Z 0 [Note] InnoDB: Waiting for purge to start
db_1 | 2018-12-25T14:30:06.796032Z 0 [Note] InnoDB: 5.7.24 started; log sequence number 12372193
db_1 | 2018-12-25T14:30:06.796536Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db_1 | 2018-12-25T14:30:06.797064Z 0 [Note] Plugin 'FEDERATED' is disabled.
db_1 | 2018-12-25T14:30:06.886235Z 0 [Note] InnoDB: Buffer pool(s) load completed at 181225 14:30:06
db_1 | 2018-12-25T14:30:06.912383Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
db_1 | 2018-12-25T14:30:06.916997Z 0 [Warning] CA certificate ca.pem is self signed.
db_1 | 2018-12-25T14:30:06.934450Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
db_1 | 2018-12-25T14:30:06.936498Z 0 [Note] IPv6 is available.
db_1 | 2018-12-25T14:30:06.937204Z 0 [Note] - '::' resolves to '::';
db_1 | 2018-12-25T14:30:06.937558Z 0 [Note] Server socket created on IP: '::'.
db_1 | 2018-12-25T14:30:06.959182Z 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 | 2018-12-25T14:30:06.967176Z 0 [Warning] 'user' entry 'root#localhost' ignored in --skip-name-resolve mode.
db_1 | 2018-12-25T14:30:06.967504Z 0 [Warning] 'user' entry 'mysql.session#localhost' ignored in --skip-name-resolve mode.
db_1 | 2018-12-25T14:30:06.967822Z 0 [Warning] 'user' entry 'mysql.sys#localhost' ignored in --skip-name-resolve mode.
db_1 | 2018-12-25T14:30:06.968512Z 0 [Warning] 'db' entry 'performance_schema mysql.session#localhost' ignored in --skip-name-resolve mode.
db_1 | 2018-12-25T14:30:06.968914Z 0 [Warning] 'db' entry 'sys mysql.sys#localhost' ignored in --skip-name-resolve mode.
db_1 | 2018-12-25T14:30:06.969441Z 0 [Warning] 'proxies_priv' entry '# root#localhost' ignored in --skip-name-resolve mode.
db_1 | 2018-12-25T14:30:06.997582Z 0 [Warning] 'tables_priv' entry 'user mysql.session#localhost' ignored in --skip-name-resolve mode.
db_1 | 2018-12-25T14:30:06.997923Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys#localhost' ignored in --skip-name-resolve mode.
db_1 | 2018-12-25T14:30:07.085365Z 0 [Note] Event Scheduler: Loaded 0 events
phpmyadmin_1 | phpMyAdmin not found in /var/www/html - copying now...
wordpress_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.20.0.4. Set the 'ServerName' directive globally to suppress this message
wordpress_1 | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.20.0.4. Set the 'ServerName' directive globally to suppress this message
wordpress_1 | [Tue Dec 25 14:30:09.921193 2018] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.25 (Debian) PHP/7.2.13 configured -- resuming normal operations
phpmyadmin_1 | Complete! phpMyAdmin has been successfully copied to /var/www/html
phpmyadmin_1 | /usr/lib/python2.7/site-packages/supervisor/options.py:461: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
phpmyadmin_1 | 'Supervisord is running as root and it is searching '
phpmyadmin_1 | 2018-12-25 14:30:10,239 CRIT Supervisor is running as root. Privileges were not dropped because no user is specified in the config file. If you intend to run as root, you can set user=root in the config file to avoid this message.
phpmyadmin_1 | 2018-12-25 14:30:10,240 INFO Included extra file "/etc/supervisor.d/nginx.ini" during parsing
phpmyadmin_1 | 2018-12-25 14:30:10,241 INFO Included extra file "/etc/supervisor.d/php.ini" during parsing
phpmyadmin_1 | 2018-12-25 14:30:10,276 INFO RPC interface 'supervisor' initialized
phpmyadmin_1 | 2018-12-25 14:30:10,277 CRIT Server 'unix_http_server' running without any HTTP authentication checking
phpmyadmin_1 | 2018-12-25 14:30:10,278 INFO supervisord started with pid 1
phpmyadmin_1 | 2018-12-25 14:30:11,283 INFO spawned: 'php-fpm' with pid 21
phpmyadmin_1 | 2018-12-25 14:30:11,291 INFO spawned: 'nginx' with pid 22
phpmyadmin_1 | [25-Dec-2018 14:30:11] NOTICE: fpm is running, pid 21
phpmyadmin_1 | [25-Dec-2018 14:30:11] NOTICE: ready to handle connections
phpmyadmin_1 | 2018-12-25 14:30:12,466 INFO success: php-fpm entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
In addition, I can see that no folder is created under E:/Demo Sites. It used to work perfectly and therefor I am pretty lost on this one. Thanks in advance.
EDIT: I found it that if I write any path inside the site (i.e. 192.168.99.100:8080/aaa) it works and takes me to the wordpress installation page. I have absolutely no idea why, but it does work.
I think you need to specify that WordPress depends on PHP too
Related
I'm trying to access a docker container i have created.
Here are the files.
DockerFile
FROM mysql:5.7.24
LABEL MAINTAINER Myself <example#example.com>
LABEL description="Immagine DBMS MySql"
ADD dump.sql /docker-entrypoint-initdb.d
EXPOSE 3390
The dump.sql creates multiple databases with al the tables for each database.
(Is it possible to do this?)
docker-compose.yml
version: '3.3'
networks:
ntalphash:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.20.0.0/24
services:
mysql:
build:
context: .
image: mysql:5.7.24
restart: unless-stopped
container_name: mysqlsrv
volumes:
- data-volume:/var/lib/mysql
networks:
ntalphash:
ipv4_address: 172.20.0.2
ports:
- target: 3306
published: 3390
protocol: tcp
mode: host
environment:
- MYSQL_ROOT_PASSWORD=admin
volumes:
data-volume:
Here the commands i'm running on terminal:
Starting the container:
PS C:\Sql Server\MySql> docker-compose up Starting mysqlsrv ... done Attaching to mysqlsrv
mysqlsrv | 2020-06-14T11:07:57.454914Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
mysqlsrv | 2020-06-14T11:07:57.455943Z 0 [Note] mysqld (mysqld 5.7.24) starting as process 1 ...
mysqlsrv | 2020-06-14T11:07:57.458112Z 0 [Note] InnoDB: PUNCH HOLE support available
mysqlsrv | 2020-06-14T11:07:57.458143Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
mysqlsrv | 2020-06-14T11:07:57.458148Z 0 [Note] InnoDB: Uses event mutexes
mysqlsrv | 2020-06-14T11:07:57.458151Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
mysqlsrv | 2020-06-14T11:07:57.458153Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
mysqlsrv | 2020-06-14T11:07:57.458155Z 0 [Note] InnoDB: Using Linux native AIO
mysqlsrv | 2020-06-14T11:07:57.458319Z 0 [Note] InnoDB: Number of pools: 1
mysqlsrv | 2020-06-14T11:07:57.458429Z 0 [Note] InnoDB: Using CPU crc32 instructions
mysqlsrv | 2020-06-14T11:07:57.459511Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
mysqlsrv | 2020-06-14T11:07:57.465707Z 0 [Note] InnoDB: Completed initialization of buffer pool
mysqlsrv | 2020-06-14T11:07:57.467263Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
mysqlsrv | 2020-06-14T11:07:57.478653Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
mysqlsrv | 2020-06-14T11:07:57.490450Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
mysqlsrv | 2020-06-14T11:07:57.490629Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
mysqlsrv | 2020-06-14T11:07:57.505991Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
mysqlsrv | 2020-06-14T11:07:57.506650Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
mysqlsrv | 2020-06-14T11:07:57.506677Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
mysqlsrv | 2020-06-14T11:07:57.507334Z 0 [Note] InnoDB: 5.7.24 started; log sequence number 101589607
mysqlsrv | 2020-06-14T11:07:57.507516Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
mysqlsrv | 2020-06-14T11:07:57.507702Z 0 [Note] Plugin 'FEDERATED' is disabled.
mysqlsrv | 2020-06-14T11:07:57.509875Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200614 11:07:57
mysqlsrv | 2020-06-14T11:07:57.511163Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
mysqlsrv | 2020-06-14T11:07:57.511449Z 0 [Warning] CA certificate ca.pem is self signed.
mysqlsrv | 2020-06-14T11:07:57.513138Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
mysqlsrv | 2020-06-14T11:07:57.513304Z 0 [Note] IPv6 is available.
mysqlsrv | 2020-06-14T11:07:57.513313Z 0 [Note] - '::' resolves to '::';
mysqlsrv | 2020-06-14T11:07:57.513327Z 0 [Note] Server socket created on IP: '::'.
mysqlsrv | 2020-06-14T11:07:57.515152Z 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.
mysqlsrv | 2020-06-14T11:07:57.515869Z 0 [Warning] 'user' entry 'root#localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.515907Z 0 [Warning] 'user' entry 'mysql.session#localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.515915Z 0 [Warning] 'user' entry 'mysql.sys#localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.515920Z 0 [Warning] 'user' entry 'debian-sys-maint#localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.515937Z 0 [Warning] 'db' entry 'performance_schema mysql.session#localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.515939Z 0 [Warning] 'db' entry 'sys mysql.sys#localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.515946Z 0 [Warning] 'proxies_priv' entry '# root#localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.516857Z 0 [Warning] 'tables_priv' entry 'user mysql.session#localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.516888Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys#localhost' ignored in --skip-name-resolve mode.
mysqlsrv | 2020-06-14T11:07:57.521147Z 0 [Note] Event Scheduler: Loaded 0 events
mysqlsrv | 2020-06-14T11:07:57.521307Z 0 [Note] mysqld: ready for connections.
mysqlsrv | Version: '5.7.24' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
Checking for active containers:
C:\Users\Myself>docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ec9f9070939e mysql:5.7.24 "docker-entrypoint.s…" 27 minutes ago Up About a minute 3390/tcp, 33060/tcp, 0.0.0.0:3390->3306/tcp mysqlsrv
64540c9d4bd1 portainer/portainer "/portainer" 7 days ago Up 46 minutes 0.0.0.0:9000->9000/tcp portainer
0345722e5fc3 mcr.microsoft.com/mssql/server:2017-latest-ubuntu "/opt/mssql/bin/nonr…" 6 months ago Up 46 minutes 0.0.0.0:1433->1433/tcp sqlserver
Then accessing the container and trying login mysql:
C:\Users\Myself>docker exec -ti mysqlsrv bash
root#ec9f9070939e:/# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
root#ec9f9070939e:/#
The password i'm typing is 'admin' as this is the password i've specified on the configuration file.
I am a beginner with Docker.
Anyone know what's going on?
I'm trying to build out a NodeJS/MySQL stack, but am experiencing an intermittent issue.
Here is my docker compose file:
version: '3'
services:
db:
image: mysql:5.7
command: --default-authentication-plugin=mysql_native_password
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
container_name: 'db'
networks:
- db-network
volumes:
- db-data:/var/lib/mysql
- ./db:/docker-entrypoint-initdb.d
forum:
image: "node:12"
user: "node"
working_dir: /home/node/app
depends_on:
- db
ports:
- 7000:3000
environment:
- NODE_ENV=development
- PORT=3000
volumes:
- ./server:/home/node/app
command: "npm start"
networks:
- db-network
adminer:
image: adminer
restart: always
networks:
- db-network
depends_on:
- db
ports:
- 7777:8080
environment:
ADMINER_DEFAULT_DB_DRIVER: mysql
ADMINER_DEFAULT_DB_HOST: db
volumes:
db-data:
networks:
db-network:
You can see that I've got an SQL script mapped into the initdb entrypoint. This is really simple SQL, it simply creates the db: CREATE DATABASE IF NOT EXISTS forum;
Inside the Node container I'm using knex to talk to the database. When I instantiate knex, I also run any outstanding migrations:
const environment = process.env.ENVIRONMENT || 'development'
const Knex = require('knex');
const knexConfig = require('../knexfile');
const knex = Knex(knexConfig[environment]);
async function init() {
try {
return await knex.migrate.latest();
} catch (error) {
console.log(error);
} finally {
return;
}
}
init();
module.exports = knex;
The problem i'm getting only appears on 'first up' o docker-compose (or more specifically when it needs to create the db-data volume). If I drop the volume docker-compose down -V I get the error when 'up-ing' again. The problem is your classic ECONNREFUSED:
Creating network "forum_db-network" with the default driver
Creating volume "forum_db-data" with default driver
Creating db ... done
Creating forum_adminer_1 ... done
Creating forum_forum_1 ... done
Attaching to db, forum_adminer_1, forum_forum_1
db | Initializing database
db | 2020-02-20T09:50:46.701629Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db | 2020-02-20T09:50:47.004757Z 0 [Warning] InnoDB: New log files created, LSN=45790
db | 2020-02-20T09:50:47.062521Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
db | 2020-02-20T09:50:47.122917Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 7810f3c2-53c6-11ea-ba00-0242c0a81002.
db | 2020-02-20T09:50:47.126689Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
adminer_1 | [Thu Feb 20 09:50:47 2020] PHP 7.4.2 Development Server (http://[::]:8080) started
db | 2020-02-20T09:50:47.127637Z 1 [Warning] root#localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
db | 2020-02-20T09:50:47.955961Z 1 [Warning] 'user' entry 'root#localhost' ignored in --skip-name-resolve mode.
db | 2020-02-20T09:50:47.956454Z 1 [Warning] 'user' entry 'mysql.session#localhost' ignored in --skip-name-resolve mode.
db | 2020-02-20T09:50:47.957026Z 1 [Warning] 'user' entry 'mysql.sys#localhost' ignored in --skip-name-resolve mode.
db | 2020-02-20T09:50:47.957747Z 1 [Warning] 'db' entry 'performance_schema mysql.session#localhost' ignored in --skip-name-resolve mode.
db | 2020-02-20T09:50:47.958212Z 1 [Warning] 'db' entry 'sys mysql.sys#localhost' ignored in --skip-name-resolve mode.
db | 2020-02-20T09:50:47.958797Z 1 [Warning] 'proxies_priv' entry '# root#localhost' ignored in --skip-name-resolve mode.
db | 2020-02-20T09:50:47.959520Z 1 [Warning] 'tables_priv' entry 'user mysql.session#localhost' ignored in --skip-name-resolve mode.
db | 2020-02-20T09:50:47.960113Z 1 [Warning] 'tables_priv' entry 'sys_config mysql.sys#localhost' ignored in --skip-name-resolve mode.
forum_1 |
forum_1 | > express-oauth-vuex-starter#1.0.0 start /home/node/app
forum_1 | > nodemon index.js
forum_1 |
forum_1 | [nodemon] 2.0.2
forum_1 | [nodemon] to restart at any time, enter `rs`
forum_1 | [nodemon] watching dir(s): *.*
forum_1 | [nodemon] watching extensions: js,mjs,json
forum_1 | [nodemon] starting `node index.js`
db | Database initialized
db | Initializing certificates
db | Generating a RSA private key
db | ........................................................................................................................+++++
db | ..........+++++
db | unable to write 'random state'
db | writing new private key to 'ca-key.pem'
db | -----
db | Generating a RSA private key
db | .........................................................................................+++++
db | .............+++++
db | unable to write 'random state'
db | writing new private key to 'server-key.pem'
db | -----
db | Generating a RSA private key
db | .....................................................+++++
db | .+++++
db | unable to write 'random state'
db | writing new private key to 'client-key.pem'
db | -----
db | Certificates initialized
db | MySQL init process in progress...
db | 2020-02-20T09:50:51.037907Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db | 2020-02-20T09:50:51.039423Z 0 [Note] mysqld (mysqld 5.7.24) starting as process 89 ...
db | 2020-02-20T09:50:51.044545Z 0 [Note] InnoDB: PUNCH HOLE support available
db | 2020-02-20T09:50:51.044653Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db | 2020-02-20T09:50:51.044701Z 0 [Note] InnoDB: Uses event mutexes
db | 2020-02-20T09:50:51.044745Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
db | 2020-02-20T09:50:51.044786Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
db | 2020-02-20T09:50:51.044825Z 0 [Note] InnoDB: Using Linux native AIO
db | 2020-02-20T09:50:51.045705Z 0 [Note] InnoDB: Number of pools: 1
db | 2020-02-20T09:50:51.046113Z 0 [Note] InnoDB: Using CPU crc32 instructions
db | 2020-02-20T09:50:51.048701Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
db | 2020-02-20T09:50:51.060691Z 0 [Note] InnoDB: Completed initialization of buffer pool
db | 2020-02-20T09:50:51.064263Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
db | 2020-02-20T09:50:51.076676Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
db | 2020-02-20T09:50:51.097380Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db | 2020-02-20T09:50:51.097533Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db | 2020-02-20T09:50:51.131620Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db | 2020-02-20T09:50:51.134052Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
db | 2020-02-20T09:50:51.134142Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
db | 2020-02-20T09:50:51.135177Z 0 [Note] InnoDB: Waiting for purge to start
db | 2020-02-20T09:50:51.185530Z 0 [Note] InnoDB: 5.7.24 started; log sequence number 2591440
db | 2020-02-20T09:50:51.186329Z 0 [Note] Plugin 'FEDERATED' is disabled.
db | 2020-02-20T09:50:51.192075Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
db | 2020-02-20T09:50:51.192591Z 0 [Warning] CA certificate ca.pem is self signed.
db | 2020-02-20T09:50:51.194602Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db | 2020-02-20T09:50:51.197793Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200220 9:50:51
db | 2020-02-20T09:50:51.198483Z 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 | 2020-02-20T09:50:51.200316Z 0 [Warning] 'user' entry 'root#localhost' ignored in --skip-name-resolve mode.
db | 2020-02-20T09:50:51.200460Z 0 [Warning] 'user' entry 'mysql.session#localhost' ignored in --skip-name-resolve mode.
db | 2020-02-20T09:50:51.200532Z 0 [Warning] 'user' entry 'mysql.sys#localhost' ignored in --skip-name-resolve mode.
db | 2020-02-20T09:50:51.200606Z 0 [Warning] 'db' entry 'performance_schema mysql.session#localhost' ignored in --skip-name-resolve mode.
db | 2020-02-20T09:50:51.200656Z 0 [Warning] 'db' entry 'sys mysql.sys#localhost' ignored in --skip-name-resolve mode.
db | 2020-02-20T09:50:51.200717Z 0 [Warning] 'proxies_priv' entry '# root#localhost' ignored in --skip-name-resolve mode.
db | 2020-02-20T09:50:51.202731Z 0 [Warning] 'tables_priv' entry 'user mysql.session#localhost' ignored in --skip-name-resolve mode.
db | 2020-02-20T09:50:51.202816Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys#localhost' ignored in --skip-name-resolve mode.
db | 2020-02-20T09:50:51.219832Z 0 [Note] Event Scheduler: Loaded 0 events
db | 2020-02-20T09:50:51.221248Z 0 [Note] mysqld: ready for connections.
db | Version: '5.7.24' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server (GPL)
forum_1 | Listening...
forum_1 | Error: connect ECONNREFUSED 192.168.16.2:3306
forum_1 | at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16)
forum_1 | at Protocol._enqueue (/home/node/app/node_modules/mysql/lib/protocol/Protocol.js:144:48)
forum_1 | at Protocol.handshake (/home/node/app/node_modules/mysql/lib/protocol/Protocol.js:51:23)
forum_1 | at Connection.connect (/home/node/app/node_modules/mysql/lib/Connection.js:116:18)
forum_1 | at /home/node/app/node_modules/knex/lib/dialects/mysql/index.js:69:18
forum_1 | From previous event:
forum_1 | at Client_MySQL.acquireRawConnection (/home/node/app/node_modules/knex/lib/dialects/mysql/index.js:64:12)
forum_1 | at create (/home/node/app/node_modules/knex/lib/client.js:291:39)
forum_1 | at processTicksAndRejections (internal/process/task_queues.js:97:5) {
forum_1 | errno: 'ECONNREFUSED',
forum_1 | code: 'ECONNREFUSED',
forum_1 | syscall: 'connect',
forum_1 | address: '192.168.16.2',
forum_1 | port: 3306,
forum_1 | fatal: true
forum_1 | }
db | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
db | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
db | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
db | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
db | 2020-02-20T09:50:54.889060Z 4 [Warning] 'user' entry 'root#localhost' ignored in --skip-name-resolve mode.
db | 2020-02-20T09:50:54.889116Z 4 [Warning] 'user' entry 'mysql.session#localhost' ignored in --skip-name-resolve mode.
db | 2020-02-20T09:50:54.889137Z 4 [Warning] 'user' entry 'mysql.sys#localhost' ignored in --skip-name-resolve mode.
db | 2020-02-20T09:50:54.889164Z 4 [Warning] 'db' entry 'performance_schema mysql.session#localhost' ignored in --skip-name-resolve mode.
db | 2020-02-20T09:50:54.889172Z 4 [Warning] 'db' entry 'sys mysql.sys#localhost' ignored in --skip-name-resolve mode.
db | 2020-02-20T09:50:54.889188Z 4 [Warning] 'proxies_priv' entry '# root#localhost' ignored in --skip-name-resolve mode.
db | 2020-02-20T09:50:54.890011Z 4 [Warning] 'tables_priv' entry 'user mysql.session#localhost' ignored in --skip-name-resolve mode.
db | 2020-02-20T09:50:54.890057Z 4 [Warning] 'tables_priv' entry 'sys_config mysql.sys#localhost' ignored in --skip-name-resolve mode.
db |
db | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init.sql
db | mysql: [Warning] Using a password on the command line interface can be insecure.
db |
db |
db | 2020-02-20T09:50:54.915362Z 0 [Note] Giving 0 client threads a chance to die gracefully
db | 2020-02-20T09:50:54.915705Z 0 [Note] Shutting down slave threads
db | 2020-02-20T09:50:54.916456Z 0 [Note] Forcefully disconnecting 0 remaining clients
db | 2020-02-20T09:50:54.917013Z 0 [Note] Event Scheduler: Purging the queue. 0 events
db | 2020-02-20T09:50:54.917696Z 0 [Note] Binlog end
db | 2020-02-20T09:50:54.918665Z 0 [Note] Shutting down plugin 'ngram'
db | 2020-02-20T09:50:54.919138Z 0 [Note] Shutting down plugin 'partition'
db | 2020-02-20T09:50:54.919357Z 0 [Note] Shutting down plugin 'BLACKHOLE'
db | 2020-02-20T09:50:54.920107Z 0 [Note] Shutting down plugin 'ARCHIVE'
db | 2020-02-20T09:50:54.920322Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
db | 2020-02-20T09:50:54.921325Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
db | 2020-02-20T09:50:54.921840Z 0 [Note] Shutting down plugin 'MyISAM'
db | 2020-02-20T09:50:54.922751Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL'
db | 2020-02-20T09:50:54.923300Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
db | 2020-02-20T09:50:54.923360Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
db | 2020-02-20T09:50:54.923589Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
db | 2020-02-20T09:50:54.923959Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
db | 2020-02-20T09:50:54.924112Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
db | 2020-02-20T09:50:54.924269Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
db | 2020-02-20T09:50:54.924754Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
db | 2020-02-20T09:50:54.925454Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
db | 2020-02-20T09:50:54.925535Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
db | 2020-02-20T09:50:54.925688Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
db | 2020-02-20T09:50:54.925728Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
db | 2020-02-20T09:50:54.926261Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
db | 2020-02-20T09:50:54.926443Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
db | 2020-02-20T09:50:54.926836Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'
db | 2020-02-20T09:50:54.927513Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
db | 2020-02-20T09:50:54.927560Z 0 [Note] Shutting down plugin 'INNODB_METRICS'
db | 2020-02-20T09:50:54.927718Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
db | 2020-02-20T09:50:54.927806Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
db | 2020-02-20T09:50:54.927847Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
db | 2020-02-20T09:50:54.928201Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
db | 2020-02-20T09:50:54.928360Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
db | 2020-02-20T09:50:54.928817Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
db | 2020-02-20T09:50:54.929031Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
db | 2020-02-20T09:50:54.929717Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
db | 2020-02-20T09:50:54.929740Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
db | 2020-02-20T09:50:54.929898Z 0 [Note] Shutting down plugin 'INNODB_CMP'
db | 2020-02-20T09:50:54.929912Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
db | 2020-02-20T09:50:54.930509Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
db | 2020-02-20T09:50:54.930535Z 0 [Note] Shutting down plugin 'INNODB_TRX'
db | 2020-02-20T09:50:54.930549Z 0 [Note] Shutting down plugin 'InnoDB'
db | 2020-02-20T09:50:54.931131Z 0 [Note] InnoDB: FTS optimize thread exiting.
db | 2020-02-20T09:50:54.931746Z 0 [Note] InnoDB: Starting shutdown...
db | 2020-02-20T09:50:55.032188Z 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
db | 2020-02-20T09:50:55.032448Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 200220 9:50:55
If the volume already exists, I get no errors, knex connects and the migrations are run.
In the error log you can see that the Node container starts up directly after mysqld: ready for connections. However, you can see that after the Node error, the db container then runs init.sql. Presumably this means that knex is trying to connect to a specific database before it exists, which I guess could be the cause of the refused connection.
So I guess I'm looking for a way to defer the instantiation of the node container until after the MySQL container has run init.sql. I'm already using the depends_on docker compose property - are there any other docker options available to me?
There's no native solution that I'm aware of, I'm afraid.
For waiting for a service to become available in general, I've used wait-for-it, but in your case you'd need something to verify MySQL also contains the database your app requires.
Maybe a simple Node script that loops a connection and attempts to select the database before running your app proper.
In the end I solved this by setting the MYSQL_DATABASE environment variable for the MySQL container. From the MySQL image docs:
MYSQL_DATABASE
This variable is optional and allows you to specify the
name of a database to be created on image startup. If a user/password
was supplied (see below) then that user will be granted superuser
access (corresponding to GRANT ALL) to this database
db:
image: mysql:5.7
command: --default-authentication-plugin=mysql_native_password
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: forum
MYSQL_ROOT_PASSWORD: root
container_name: 'db'
networks:
- db-network
volumes:
- db-data:/var/lib/mysql
In addition to this, I used is-port-reachable to hold initial migrations until the MySQL container is available.
const isPortReachable = require('is-port-reachable');
const environment = process.env.ENVIRONMENT || 'development'
const Knex = require('knex');
const knexConfig = require('../knexfile');
const knex = Knex(knexConfig[environment]);
async function init() {
let dbStatus = false;
while (!dbStatus) {
dbStatus = await isPortReachable(knexConfig[environment].connection.port, {host: knexConfig[environment].connection.host});
}
try {
return await knex.migrate.latest();
} catch (error) {
console.log(error);
}
}
init();
module.exports = knex;
Update
While the above did solve this specific problem, there was a raft of other issues that kept popping up - all to do with MySQL configuration. In the end I got tired of playing whack-a-mole and switched to Postgres (incredibly simple thanks to Knex). Span the image up and everything just worked...
If you are having issues with docker-compose, knex and mysql, my advice would be to just use Postgres!
I have specified in my docker-compose.yml the version of MySql 8.0.0 and I am having some issues (that I did not have not specifying the version). What is wrong?
Below you can find my docker-compose.yml and error logs:
version: '3.7'
services:
db:
image: mysql:8.0.0
command: ["--default-authentication-plugin=mysql_native_password"]
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: symfony
MYSQL_PASSWORD: symfony
php:
build: ./php-fpm
ports:
- "9000:9001"
volumes:
- ./symfony:/var/www/symfony:cached
- ./logs/symfony:/var/www/symfony/var/log:cached
links:
- db
extra_hosts:
- "docker-host.localhost:127.0.0.1"
- "symfony.localhost:172.24.0.5"
nginx:
build: ./nginx
ports:
- "80:80"
links:
- php
volumes:
- ./logs/nginx:/var/log/nginx:cached
- ./symfony:/var/www/symfony:cached
elk:
image: willdurand/elk
ports:
- "81:80"
volumes:
- ./elk/logstash:/etc/logstash:cached
- ./elk/logstash/patterns:/opt/logstash/patterns:cached
- ./logs/symfony:/var/www/symfony/var/log:cached
- ./logs/nginx:/var/log/nginx:cached
and logs:
db_1 | 2019-06-25T11:12:28.129419Z 0 [Warning] TIMESTAMP with
implicit DEFAULT value is deprecated. Please use --
explicit_defaults_for_timestamp server option (see documentation for
more details).
db_1 | 2019-06-25T11:12:28.130523Z 0 [Note] mysqld (mysqld 8.0.0-
dmr) starting as process 1 ...
db_1 | 2019-06-25T11:12:28.134864Z 0 [Note] InnoDB: Using Linux
native AIO
db_1 | 2019-06-25T11:12:28.135137Z 0 [Note] Plugin 'FEDERATED' is
disabled.
db_1 | 2019-06-25T11:12:28.136567Z 1 [Note] InnoDB: PUNCH HOLE
support available
db_1 | 2019-06-25T11:12:28.136614Z 1 [Note] InnoDB: Mutexes and
rw_locks use GCC atomic builtins
db_1 | 2019-06-25T11:12:28.136620Z 1 [Note] InnoDB: Uses event
mutexes
db_1 | 2019-06-25T11:12:28.136623Z 1 [Note] InnoDB: GCC builtin
__atomic_thread_fence() is used for memory barrier
db_1 | 2019-06-25T11:12:28.136626Z 1 [Note] InnoDB: Compressed
tables use zlib 1.2.3
db_1 | 2019-06-25T11:12:28.137151Z 1 [Note] InnoDB: Number of
pools: 1
db_1 | 2019-06-25T11:12:28.137390Z 1 [Note] InnoDB: Using CPU
crc32 instructions
db_1 | 2019-06-25T11:12:28.139057Z 1 [Note] InnoDB: Initializing
buffer pool, total size = 128M, instances = 1, chunk size = 128M
db_1 | libnuma: Warning: /sys not mounted or invalid. Assuming one
node: No such file or directory
db_1 | mbind: Operation not permitted
db_1 | mbind: Operation not permitted
db_1 | mbind: Operation not permitted
db_1 | mbind: Operation not permitted
db_1 | 2019-06-25T11:12:28.150384Z 1 [Note] InnoDB: Completed
initialization of buffer pool
db_1 | 2019-06-25T11:12:28.152938Z 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 | 2019-06-25T11:12:28.169513Z 1 [ERROR] InnoDB: Unsupported
redo log format. The redo log was created with MySQL 8.0.15. Please
follow the instructions at
http://dev.mysql.com/doc/refman/8.0/en/upgrading-downgrading.html
db_1 | 2019-06-25T11:12:28.169587Z 1 [ERROR] InnoDB: Plugin
initialization aborted with error Generic error
db_1 | 2019-06-25T11:12:28.774335Z 1 [ERROR] Failed to initialize
DD Storage Engine
db_1 | 2019-06-25T11:12:28.774965Z 0 [ERROR] Data Dictionary
initialization failed.
db_1 | 2019-06-25T11:12:28.775132Z 0 [ERROR] Aborting
db_1 |
db_1 | 2019-06-25T11:12:28.775198Z 0 [Note] Binlog end
db_1 | 2019-06-25T11:12:28.775614Z 0 [Note] Shutting down plugin
'InnoDB'
db_1 | 2019-06-25T11:12:28.775986Z 0 [Note] Shutting down plugin
'MyISAM'
db_1 | 2019-06-25T11:12:28.776099Z 0 [Note] Shutting down plugin
'CSV'
db_1 | 2019-06-25T11:12:28.779905Z 0 [Note] mysqld: Shutdown
complete
db_1 |
docker-symfony4-udggui_db_1 exited with code 1
When you did not specify the version as image: mysql, it will use the latest version. At this time the question was raised, it's 8.0.16, see this.
When you specify the version as image: mysql:8.0.0, you just use an old version of mysql.
Unfortunately, this version not compatible with new docker as next:
The server use mbind for NUMA (non-uniform memory access) operations, but Docker blocks this access by default. It's possible to provide a custom profile that allows it, but the syntax of the profile files has changed across Docker versions, so it's kind of messy.
That means, at old time this image work, but now docker upgraded, the mysql image should do corresponding changes. And, 8.0.16 which currently the latest, already made this fix, so it's ok. Detail refers to next discussion:
https://github.com/docker-library/mysql/issues/303
https://github.com/docker-library/mysql/issues/422
I'm trying to connect the official MariaDB docker image to an image of my client-side application with the command docker-compose up; it successfully connects to the server but when trying to connect to the MariaDB database, after about a minute logs "Error: Connection lost: The server closed the connection." I have no problem connecting to the database locally when starting the server, but it throws the error when trying to link docker images of the same code.
My docker-compose.yml:
version: '3.1'
services:
webapp:
image: client
ports:
- "3306:3306"
links:
- db
depends_on:
- db
environment:
DATABASE_URL: "mysql://root:root#db/yelp"
db:
image: mariadb:latest
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: yelp
adminer:
image: adminer
restart: always
ports:
- 3001:3001
Dockerfile:
FROM node:10
WORKDIR /cadenza/documents/SDC/leaveReview
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3306
CMD ["npm", "start"]
mysql/MariaDB index.js connection file:
var mysql = require('mysql')
var connection = mysql.createConnection({
host: '127.0.0.1',
user: 'root',
password: 'root',
database: 'yelp'
});
connection.connect((err) => {
if (err) {
console.log('error when connecting to db', err);
} else {
console.log('connected to db')
}
});
module.exports = connection;
Logs when running docker-compose up:
docker-compose up
Starting leavereview_db_1 ... done
Starting leavereview_adminer_1 ... done
Starting leavereview_webapp_1 ... done
Attaching to leavereview_adminer_1, leavereview_db_1, leavereview_webapp_1
adminer_1 | PHP 7.2.7 Development Server started at Tue Jul 3 02:34:03 2018
webapp_1 |
webapp_1 | > yelp-reviews#1.0.0 start /cadenza/documents/SDC/leaveReview
webapp_1 | > nodemon server/index.js
webapp_1 |
db_1 | 2018-07-03 2:34:04 0 [Note] mysqld (mysqld 10.3.7-MariaDB-1:10.3.7+maria~jessie) starting as process 1 ...
db_1 | 2018-07-03 2:34:04 0 [Note] InnoDB: Using Linux native AIO
db_1 | 2018-07-03 2:34:04 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1 | 2018-07-03 2:34:04 0 [Note] InnoDB: Uses event mutexes
db_1 | 2018-07-03 2:34:04 0 [Note] InnoDB: Compressed tables use zlib 1.2.8
db_1 | 2018-07-03 2:34:04 0 [Note] InnoDB: Number of pools: 1
db_1 | 2018-07-03 2:34:04 0 [Note] InnoDB: Using SSE2 crc32 instructions
db_1 | 2018-07-03 2:34:04 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
db_1 | 2018-07-03 2:34:04 0 [Note] InnoDB: Completed initialization of buffer pool
db_1 | 2018-07-03 2:34:04 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 | 2018-07-03 2:34:04 0 [Note] InnoDB: Starting crash recovery from checkpoint LSN=1630896
db_1 | 2018-07-03 2:34:04 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
db_1 | 2018-07-03 2:34:04 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
db_1 | 2018-07-03 2:34:04 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db_1 | 2018-07-03 2:34:04 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db_1 | 2018-07-03 2:34:04 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db_1 | 2018-07-03 2:34:04 0 [Note] InnoDB: Waiting for purge to start
webapp_1 | [nodemon] 1.17.5
webapp_1 | [nodemon] to restart at any time, enter `rs`
webapp_1 | [nodemon] watching: *.*
webapp_1 | [nodemon] starting `node server/index.js`
db_1 | 2018-07-03 2:34:04 0 [Note] InnoDB: 10.3.7 started; log sequence number 1630905; transaction id 21
db_1 | 2018-07-03 2:34:04 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db_1 | 2018-07-03 2:34:04 0 [Note] Plugin 'FEEDBACK' is disabled.
db_1 | 2018-07-03 2:34:04 0 [Note] Recovering after a crash using tc.log
db_1 | 2018-07-03 2:34:04 0 [Note] Starting crash recovery...
db_1 | 2018-07-03 2:34:04 0 [Note] Crash recovery finished.
db_1 | 2018-07-03 2:34:04 0 [Note] Server socket created on IP: '::'.
db_1 | 2018-07-03 2:34:04 0 [Note] InnoDB: Buffer pool(s) load completed at 180703 2:34:04
db_1 | 2018-07-03 2:34:04 0 [Warning] 'proxies_priv' entry '#% root#a1a244ac54cf' ignored in --skip-name-resolve mode.
db_1 | 2018-07-03 2:34:04 0 [Note] Reading of all Master_info entries succeded
db_1 | 2018-07-03 2:34:04 0 [Note] Added new Master_info '' to hash table
db_1 | 2018-07-03 2:34:04 0 [Note] mysqld: ready for connections.
db_1 | Version: '10.3.7-MariaDB-1:10.3.7+maria~jessie' socket: '/var/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution
webapp_1 | Listening on port 3306
webapp_1 | error when connecting to db { Error: Connection lost: The server closed the connection.
webapp_1 | at Protocol.end (/cadenza/documents/SDC/leaveReview/node_modules/mysql/lib/protocol/Protocol.js:113:13)
webapp_1 | at Socket.<anonymous> (/cadenza/documents/SDC/leaveReview/node_modules/mysql/lib/Connection.js:109:28)
webapp_1 | at Socket.emit (events.js:187:15)
webapp_1 | at endReadableNT (_stream_readable.js:1081:12)
webapp_1 | at process._tickCallback (internal/process/next_tick.js:63:19)
webapp_1 | --------------------
webapp_1 | at Protocol._enqueue (/cadenza/documents/SDC/leaveReview/node_modules/mysql/lib/protocol/Protocol.js:145:48)
webapp_1 | at Protocol.handshake (/cadenza/documents/SDC/leaveReview/node_modules/mysql/lib/protocol/Protocol.js:52:23)
webapp_1 | at Connection.connect (/cadenza/documents/SDC/leaveReview/node_modules/mysql/lib/Connection.js:130:18)
webapp_1 | at Object.<anonymous> (/cadenza/documents/SDC/leaveReview/database/index.js:9:12)
webapp_1 | at Module._compile (internal/modules/cjs/loader.js:702:30)
webapp_1 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
webapp_1 | at Module.load (internal/modules/cjs/loader.js:612:32)
webapp_1 | at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
webapp_1 | at Function.Module._load (internal/modules/cjs/loader.js:543:3)
webapp_1 | at Module.require (internal/modules/cjs/loader.js:650:17) fatal: true, code: 'PROTOCOL_CONNECTION_LOST' }
webapp_1 | (node:29) [DEP0096] DeprecationWarning: timers.unenroll() is deprecated. Please use clearTimeout instead.
It should be logging "connected to db". I have also tried solutions that people have suggest for handling server disconnect due to being idle etc etc, but it doesn't even connect to the database in the first place.
So it connected after I changed the host in the database connection index.js file from '127.0.0.1' to:
var connection = mysql.createConnection({
host: 'db',
user: 'root',
password: 'root',
database: 'yelp'
});
where 'db' is referring to the 'db' image in my docker-compose.yml file.
When a developer approaches me saying that his application cannot connect to a container, this is what I usually do. I give them the following setup.
docker-compose.yml:
version: '3.1'
services:
webapp:
build: .
db:
image: mariadb:latest
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: yelp
Dockerfile:
FROM alpine
RUN apk add -U mysql-client
COPY entry.sh .
CMD ["/bin/sh", "entry.sh"]
entry.sh:
#!/bin/sh
echo "Waiting for mysql..."
until mysqladmin ping -h"db" -P"3306" --silent
do
echo "mysql is not ready will retry in 5..."
sleep 5
done
echo -e "\nmysql is ready"
mysql -h"db" -P"3306" -p"root" -u"root" -e "SHOW DATABASES"
And this works, when you run docker-compose up, output being something along these lines:
Starting 51145943_db_1 ... done
Starting 51145943_webapp_1 ... done
Attaching to 51145943_webapp_1, 51145943_db_1
webapp_1 | Waiting for mysql...
webapp_1 | mysql is not ready will retry in 5...
db_1 | 2018-07-03 3:17:10 0 [Note] mysqld (mysqld 10.3.7-MariaDB-1:10.3.7+maria~jessie) starting as process 1 ...
db_1 | 2018-07-03 3:17:10 0 [Note] InnoDB: Using Linux native AIO
db_1 | 2018-07-03 3:17:10 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1 | 2018-07-03 3:17:10 0 [Note] InnoDB: Uses event mutexes
db_1 | 2018-07-03 3:17:10 0 [Note] InnoDB: Compressed tables use zlib 1.2.8
db_1 | 2018-07-03 3:17:10 0 [Note] InnoDB: Number of pools: 1
db_1 | 2018-07-03 3:17:10 0 [Note] InnoDB: Using SSE2 crc32 instructions
db_1 | 2018-07-03 3:17:10 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
db_1 | 2018-07-03 3:17:10 0 [Note] InnoDB: Completed initialization of buffer pool
db_1 | 2018-07-03 3:17:10 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 | 2018-07-03 3:17:11 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
db_1 | 2018-07-03 3:17:11 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db_1 | 2018-07-03 3:17:11 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db_1 | 2018-07-03 3:17:11 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db_1 | 2018-07-03 3:17:11 0 [Note] InnoDB: 10.3.7 started; log sequence number 1630896; transaction id 21
db_1 | 2018-07-03 3:17:11 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db_1 | 2018-07-03 3:17:11 0 [Note] Plugin 'FEEDBACK' is disabled.
db_1 | 2018-07-03 3:17:11 0 [Note] Server socket created on IP: '::'.
db_1 | 2018-07-03 3:17:11 0 [Warning] 'proxies_priv' entry '#% root#4a91686036a2' ignored in --skip-name-resolve mode.
db_1 | 2018-07-03 3:17:11 0 [Note] InnoDB: Buffer pool(s) load completed at 180703 3:17:11
db_1 | 2018-07-03 3:17:11 0 [Note] Reading of all Master_info entries succeded
db_1 | 2018-07-03 3:17:11 0 [Note] Added new Master_info '' to hash table
db_1 | 2018-07-03 3:17:11 0 [Note] mysqld: ready for connections.
db_1 | Version: '10.3.7-MariaDB-1:10.3.7+maria~jessie' socket: '/var/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distribution
db_1 | 2018-07-03 3:17:15 8 [Warning] Access denied for user 'root'#'172.22.0.3' (using password: NO)
webapp_1 |
webapp_1 | mysql is ready
webapp_1 | Database
webapp_1 | information_schema
webapp_1 | mysql
webapp_1 | performance_schema
webapp_1 | yelp
51145943_webapp_1 exited with code 0
This proves that connectivity between containers is working and whatever problem they have is application specific. May be the pass the connection string in a wrong format, or using wrong server name, or trying to connect to early when mysql is not up yet.
Having proven this, they now can "bridge the gap" making small changes to their own or my setup, trying to bring them closer until something breaks. That last step reveals the culprit. For example, if the add mysql command line connection to their application container and it indeed connects, but their application does not, it means that they need to look for the reason in their application code.
From my experience this the quickest way to sort out problems like this, when the reason is not immediately obvious.
I am having issues getting my MySQL container to run some initialisation scripts (creating some databases) from Docker Compose. As per the documentation on Docker Hub, I mount the .sql files in /docker-entrypoint-initdb.d but to no avail.
My compose files is as follows:
version: '2'
services:
database:
image: mysql
ports:
- "3307:3306"
environment:
MYSQL_ROOT_PASSWORD: root
volumes:
- ./scripts/db:/docker-entrypoint-initdb.d
myservice:
image: company/myservice
expose:
- "10001"
depends_on:
- database
links:
- database
environment:
SERVICE_PORT: 10001
DATABASE_URL: jdbc:mysql://database:3306/myservice?autoReconnect=true&useSSL=false&characterEncoding=UTF-8
And the contents of ./scripts/db is just 1 file init-databases.sql:
CREATE DATABASE myservice;
Once started up, MySQL is running, but the database is not created. The service container also successfully links to the MySQL container. Bashing into the MySQL container; the init scripts are successfully mounted in the correct location.
Can anyone see some obvious issues here?
LOGS FROM compose
database_1 | 2016-04-01T05:35:55.020279Z 0 [Note] mysqld (mysqld 5.7.11) starting as process 1 ...
database_1 | 2016-04-01T05:35:55.023277Z 0 [Note] InnoDB: PUNCH HOLE support available
database_1 | 2016-04-01T05:35:55.023305Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
database_1 | 2016-04-01T05:35:55.023316Z 0 [Note] InnoDB: Uses event mutexes
database_1 | 2016-04-01T05:35:55.023324Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
database_1 | 2016-04-01T05:35:55.023332Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.8
database_1 | 2016-04-01T05:35:55.023344Z 0 [Note] InnoDB: Using Linux native AIO
database_1 | 2016-04-01T05:35:55.023491Z 0 [Note] InnoDB: Number of pools: 1
database_1 | 2016-04-01T05:35:55.023566Z 0 [Note] InnoDB: Using CPU crc32 instructions
database_1 | 2016-04-01T05:35:55.028689Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
database_1 | 2016-04-01T05:35:55.041026Z 0 [Note] InnoDB: Completed initialization of buffer pool
database_1 | 2016-04-01T05:35:55.047324Z 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 | 2016-04-01T05:35:55.061537Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
database_1 | 2016-04-01T05:35:55.076895Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
database_1 | 2016-04-01T05:35:55.076987Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
database_1 | 2016-04-01T05:35:55.095683Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
database_1 | 2016-04-01T05:35:55.096484Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
database_1 | 2016-04-01T05:35:55.096540Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
database_1 | 2016-04-01T05:35:55.096931Z 0 [Note] InnoDB: Waiting for purge to start
database_1 | 2016-04-01T05:35:55.147986Z 0 [Note] InnoDB: 5.7.11 started; log sequence number 11992841
database_1 | 2016-04-01T05:35:55.148204Z 0 [Note] Plugin 'FEDERATED' is disabled.
database_1 | 2016-04-01T05:35:55.149262Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
database_1 | 2016-04-01T05:35:55.149443Z 0 [Warning] CA certificate ca.pem is self signed.
database_1 | 2016-04-01T05:35:55.150272Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
database_1 | 2016-04-01T05:35:55.151068Z 0 [Note] InnoDB: Buffer pool(s) load completed at 160401 5:35:55
database_1 | 2016-04-01T05:35:55.152775Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
database_1 | 2016-04-01T05:35:55.154441Z 0 [Note] IPv6 is available.
database_1 | 2016-04-01T05:35:55.154553Z 0 [Note] - '::' resolves to '::';
database_1 | 2016-04-01T05:35:55.154571Z 0 [Note] Server socket created on IP: '::'.
database_1 | 2016-04-01T05:35:55.156680Z 0 [Warning] 'db' entry 'sys mysql.sys#localhost' ignored in --skip-name-resolve mode.
database_1 | 2016-04-01T05:35:55.156738Z 0 [Warning] 'proxies_priv' entry '# root#localhost' ignored in --skip-name-resolve mode.
database_1 | 2016-04-01T05:35:55.158280Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys#localhost' ignored in --skip-name-resolve mode.
database_1 | 2016-04-01T05:35:55.165273Z 0 [Note] Event Scheduler: Loaded 0 events
database_1 | 2016-04-01T05:35:55.173462Z 0 [Note] mysqld: ready for connections.
database_1 | Version: '5.7.11' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server (GPL)
Check if this is a docker-compose issue (like issue 115 which redirected to issue 2266)
I don't think the error is related to build, it's mostly likely volumes.
Compose preserves volumes so that you don't lose data (this will be better documented in the next release).
To remove those volumes run docker-compose rm -vf. The next time you docker-compose up it should start with fresh empty volumes.
According to hub.docker.com/mysql, check also if this is not a synchronization issue:
If there is no database initialized when the container starts, then a default database will be created. While this is the expected behavior, this means that it will not accept incoming connections until such initialization completes. This may cause issues when using automation tools, such as docker-compose, which start several containers simultaneously.