Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > it.comp.www.php > #22476 > unrolled thread
| Started by | sky winter <sky@bo.bo> |
|---|---|
| First post | 2019-01-07 14:57 +0100 |
| Last post | 2019-01-13 10:36 +0100 |
| Articles | 11 — 2 participants |
Back to article view | Back to it.comp.www.php
importare database mysql dentro un contenitore (docker) sky winter <sky@bo.bo> - 2019-01-07 14:57 +0100
Re: importare database mysql dentro un contenitore (docker) Alessandro Pellizzari <shuriken@amiran.it> - 2019-01-07 15:29 +0000
Re: importare database mysql dentro un contenitore (docker) sky winter <sky@bo.bo> - 2019-01-07 17:49 +0100
Re: importare database mysql dentro un contenitore (docker) Alessandro Pellizzari <shuriken@amiran.it> - 2019-01-08 10:42 +0000
Re: importare database mysql dentro un contenitore (docker) sky winter <sky@bo.bo> - 2019-01-08 13:34 +0100
Re: importare database mysql dentro un contenitore (docker) Alessandro Pellizzari <shuriken@amiran.it> - 2019-01-08 13:25 +0000
Re: importare database mysql dentro un contenitore (docker) sky winter <sky@bo.bo> - 2019-01-08 15:16 +0100
Re: importare database mysql dentro un contenitore (docker) Alessandro Pellizzari <shuriken@amiran.it> - 2019-01-12 09:58 +0000
Re: importare database mysql dentro un contenitore (docker) sky winter <sky@bo.bo> - 2019-01-12 19:23 +0100
Re: importare database mysql dentro un contenitore (docker) Alessandro Pellizzari <shuriken@amiran.it> - 2019-01-12 19:50 +0000
Re: importare database mysql dentro un contenitore (docker) sky winter <sky@bo.bo> - 2019-01-13 10:36 +0100
| From | sky winter <sky@bo.bo> |
|---|---|
| Date | 2019-01-07 14:57 +0100 |
| Subject | importare database mysql dentro un contenitore (docker) |
| Message-ID | <q0vlro$omj$1@gioia.aioe.org> |
$ cat docker-compose.yml
version: '2'
services:
app:
build:
context: .
image: test-image
ports:
- 8080:80
volumes:
- .:/srv/app
links:
- mysql
- redis
environment:
DB_HOST: mysql
DB_DATABASE: laravel_docker
DB_USERNAME: app
DB_PASSWORD: password
REDIS_HOST: redis
SESSION_DRIVER: redis
CACHE_DRIVER: redis
mysql:
image: mysql:5.7
ports:
- 13306:3306
environment:
MYSQL_DATABASE: test
MYSQL_USER: root
MYSQL_PASSWORD: root1
MYSQL_ROOT_PASSWORD: root2
redis:
image: redis:4.0-alpine
ports:
- 16379:6379
$ cat Dockerfile
FROM php:7.2.2-cli
COPY . /usr/local/bin
WORKDIR /usr/local/bin
RUN docker-php-ext-install mbstring pdo pdo_mysql
CMD mysql -u $MYSQL_USER -p $MYSQL_PASSWORD $MYSQL_DATABASE < test.sql
$ cat test.php
<?php
$pdo = new pdo(
"mysql:host=localhost;dbname=test",
'root','root1'
);
$query = $pdo->query("SELECT * FROM people");
var_dump($pdo->errorInfo());
foreach($query as $row ){
var_dump($row);
}
$ cat test.sh
#!/usr/bin/env bash
set -e
cd $(dirname "$0")
docker-compose up --build -d
docker run test-image php /usr/local/bin/test.php
$ ./test.sh
Building app
Step 1/5 : FROM php:7.2.2-cli
---> 21c3582549e6
Step 2/5 : COPY . /usr/local/bin
---> Using cache
---> e0a9005e2907
Step 3/5 : WORKDIR /usr/local/bin
---> Using cache
---> 3efd6cdfab46
Step 4/5 : RUN docker-php-ext-install mbstring pdo pdo_mysql
---> Using cache
---> 282ab8fb5896
Step 5/5 : CMD mysql -u $MYSQL_USER -p $MYSQL_PASSWORD $MYSQL_DATABASE <
test.sql
---> Using cache
---> 7ba640bd690d
Successfully built 7ba640bd690d
dockermysql_redis_1 is up-to-date
dockermysql_mysql_1 is up-to-date
Starting dockermysql_app_1
Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] No such file
or directory in /usr/local/bin/test.php:5
Perchè non funziona?
[toc] | [next] | [standalone]
| From | Alessandro Pellizzari <shuriken@amiran.it> |
|---|---|
| Date | 2019-01-07 15:29 +0000 |
| Message-ID | <g9h9i0F9t0rU1@mid.individual.net> |
| In reply to | #22476 |
On 07/01/2019 13:57, sky winter wrote: > $pdo = new pdo( > "mysql:host=localhost;dbname=test", > 'root','root1' > ); > Perchè non funziona? Se usi "localhost" su un client MySQL (incluso PDO), lui cerca di connettersi alla Unix socket che, essendo in un container diverso, non è accessibile. Devi usare "mysql" (il nome che hai dato al container, che viene esposto dal DNS fittizio di Docker) o 127.0.0.1 per forzarlo a usare la rete. Devi anche assicurarti che il container MySQL abbia la rete abilitata (bind-address=0.0.0.0), ma dovrebbe essere così di default (altrimenti non potresti usarlo... :D ) Bye.
[toc] | [prev] | [next] | [standalone]
| From | sky winter <sky@bo.bo> |
|---|---|
| Date | 2019-01-07 17:49 +0100 |
| Message-ID | <q0vvv7$8cv$1@gioia.aioe.org> |
| In reply to | #22477 |
Il 07/01/19 16:29, Alessandro Pellizzari ha scritto:
>
> Se usi "localhost" su un client MySQL (incluso PDO), lui cerca di
> connettersi alla Unix socket
Cosa sarebbe?
> che, essendo in un container diverso, non è
> accessibile.
>
> Devi usare "mysql" (il nome che hai dato al container, che viene esposto
> dal DNS fittizio di Docker) o 127.0.0.1 per forzarlo a usare la rete.
$ cat test.php
<?php
$pdo = new PDO(
"mysql:host=127.0.0.1;dbname=test",
'root','root1'
);
$query = $pdo->query("SELECT * FROM people");
var_dump($pdo->errorInfo());
foreach($query as $row ){
var_dump($row);
}
$ docker run test-image php /usr/local/bin/test.php
Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] Connection
refused in /usr/local/bin/test.php:5
> Devi anche assicurarti che il container MySQL abbia la rete abilitata
> (bind-address=0.0.0.0), ma dovrebbe essere così di default (altrimenti
> non potresti usarlo... :D )
Tanto per sapere:
1. Come si fa a sapere la subnet mask in uso?
2. Come si fa a modificarla?
[toc] | [prev] | [next] | [standalone]
| From | Alessandro Pellizzari <shuriken@amiran.it> |
|---|---|
| Date | 2019-01-08 10:42 +0000 |
| Message-ID | <g9jd5cFo10pU1@mid.individual.net> |
| In reply to | #22478 |
On 07/01/2019 16:49, sky winter wrote: > Il 07/01/19 16:29, Alessandro Pellizzari ha scritto: >> >> Se usi "localhost" su un client MySQL (incluso PDO), lui cerca di >> connettersi alla Unix socket > Cosa sarebbe? Un file in /var/lock/mysql.sock o qualcosa del genere. > $ docker run test-image php /usr/local/bin/test.php > Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] Connection > refused in /usr/local/bin/test.php:5 Buon segno: significa che trova MySQL, ma lui gli rifiuta la connessione. :) Mi sono accorto che nella config del container mysql dai due password contrastanti per root. Cambia MYSQL_USER a qualcos'altro e collegati con quello. >> Devi anche assicurarti che il container MySQL abbia la rete abilitata >> (bind-address=0.0.0.0), ma dovrebbe essere così di default (altrimenti >> non potresti usarlo... :D ) > Tanto per sapere: > 1. Come si fa a sapere la subnet mask in uso? Non dovrebbe interessarti. Quando usi docker-compose tutti i container che lanci sono nella stessa rete e si vedono tra di loro (se usi `links`), e devi usare i loro nomi per collegarli uno con l'altro, non i loro IP. > 2. Come si fa a modificarla? Devi vedere la configurazione delle reti in docker-compose. Puoi configurare la rete che vuoi, ma sarà sempre privata. Nel 99% dei casi non ti serve toccare la config. Usa `expose` o `port` per rendere pubblica una porta e vederla dalla macchina host. Tutto quello che non esporti con export o port rimane visibile all'interno della rete privata, quindi, per esempio, nel tuo caso non ti serve esporre mysql e redis (a meno che tu non voglia amministrarli dalla macchina host): saranno comunque accessibili dall'applicazione PHP. Bye.
[toc] | [prev] | [next] | [standalone]
| From | sky winter <sky@bo.bo> |
|---|---|
| Date | 2019-01-08 13:34 +0100 |
| Message-ID | <q125dd$1qr8$1@gioia.aioe.org> |
| In reply to | #22479 |
Il 08/01/19 11:42, Alessandro Pellizzari ha scritto:
>
>> $ docker run test-image php /usr/local/bin/test.php
>> Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] Connection
>> refused in /usr/local/bin/test.php:5
>
> Buon segno: significa che trova MySQL, ma lui gli rifiuta la
> connessione. :)
>
> Mi sono accorto che nella config del container mysql dai due password
> contrastanti per root. Cambia MYSQL_USER a qualcos'altro e collegati con
> quello.
+ cat docker-compose.yml
version: '3'
services:
app:
build:
context: .
image: test-image
ports:
- 8080:80
volumes:
- .:/srv/app
links:
- mysql
- redis
environment:
DB_HOST: mysql
DB_DATABASE: laravel_docker
DB_USERNAME: app
DB_PASSWORD: password
REDIS_HOST: redis
SESSION_DRIVER: redis
CACHE_DRIVER: redis
mysql:
image: mysql:5.7
ports:
- 13306:3306
environment:
MYSQL_DATABASE: test
MYSQL_ROOT_PASSWORD: mypass
redis:
image: redis:4.0-alpine
ports:
- 16379:6379
+ docker run test-image php /usr/local/bin/test.php
Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] Connection
refused in /usr/local/bin/test.php:4
Stack trace:
#0 /usr/local/bin/test.php(4): PDO->__construct('mysql:host=127....',
'root', 'mypass')
#1 {main}
thrown in /usr/local/bin/test.php on line 4
Adesso sostituisco
MYSQL_ROOT_PASSWORD: mypass
con
MYSQL_USER: my
MYSQL_PASSWORD: mypass
+ cat docker-compose.yml
version: '3'
services:
app:
build:
context: .
image: test-image
ports:
- 8080:80
volumes:
- .:/srv/app
links:
- mysql
- redis
environment:
DB_HOST: mysql
DB_DATABASE: laravel_docker
DB_USERNAME: app
DB_PASSWORD: password
REDIS_HOST: redis
SESSION_DRIVER: redis
CACHE_DRIVER: redis
mysql:
image: mysql:5.7
ports:
- 13306:3306
environment:
MYSQL_DATABASE: test
MYSQL_USER: my
MYSQL_PASSWORD: mypass
redis:
image: redis:4.0-alpine
ports:
- 16379:6379
+ docker run test-image php /usr/local/bin/test.php
Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] Connection
refused in /usr/local/bin/test.php:5
Stack trace:
#0 /usr/local/bin/test.php(5): PDO->__construct('mysql:host=127....',
'my', 'mypass')
#1 {main}
thrown in /usr/local/bin/test.php on line 5
Come vedi in entrambi i casi non funziona.
[toc] | [prev] | [next] | [standalone]
| From | Alessandro Pellizzari <shuriken@amiran.it> |
|---|---|
| Date | 2019-01-08 13:25 +0000 |
| Message-ID | <g9jmm7Fq2arU1@mid.individual.net> |
| In reply to | #22480 |
On 08/01/2019 12:34, sky winter wrote: > + cat docker-compose.yml > ... > + docker run test-image php /usr/local/bin/test.php Perché definisci un docker-compose.yml e poi usi `docker run` invece di `docker-compose up`? Ho l'impressione che non ti sia chiarissimo come funziona l'ecosistema di docker e che tu stia andando alla cieca (o "alla StackOverflow"). Ti consiglierei di studiarlo un po' meglio. Bye.
[toc] | [prev] | [next] | [standalone]
| From | sky winter <sky@bo.bo> |
|---|---|
| Date | 2019-01-08 15:16 +0100 |
| Message-ID | <q12bb1$mej$1@gioia.aioe.org> |
| In reply to | #22481 |
Il 08/01/19 14:25, Alessandro Pellizzari ha scritto: > On 08/01/2019 12:34, sky winter wrote: > >> + cat docker-compose.yml > > ... >> + docker run test-image php /usr/local/bin/test.php > > Perché definisci un docker-compose.yml e poi usi `docker run` invece di > `docker-compose up`? > > Ho l'impressione che non ti sia chiarissimo come funziona l'ecosistema > di docker e che tu stia andando alla cieca (o "alla StackOverflow"). > > Ti consiglierei di studiarlo un po' meglio. > > Bye. Pensavo fosse ovvio che prima lancio docker-compose up... Comunque ecco qua: $ docker-compose up --build -d > output.txt Building app tmphbzh6gzgcy_redis_1 is up-to-date tmphbzh6gzgcy_mysql_1 is up-to-date Recreating tmphbzh6gzgcy_app_1 ... done I dettagli sono nel file output.txt Scaricalo da qui http://s000.tinyupload.com/index.php?file_id=00953522055497423424 Come vedi ci sono molte cose strane: DONIG_ESCAPE_UCHAR_COLLISION, ecc.
[toc] | [prev] | [next] | [standalone]
| From | Alessandro Pellizzari <shuriken@amiran.it> |
|---|---|
| Date | 2019-01-12 09:58 +0000 |
| Message-ID | <g9ts2kF2t1oU1@mid.individual.net> |
| In reply to | #22482 |
On 08/01/2019 14:16, sky winter wrote: > I dettagli sono nel file output.txt > Scaricalo da qui > http://s000.tinyupload.com/index.php?file_id=00953522055497423424 Anche se potrebbe essere interessante, non ho proprio il tempo per debuggare tutto. In generale, quando lanci un gruppo con docker-compose, viene creata una rete privata tra i container definiti nel file. Se poi lanci un container a part con docker run sarà su una rete diversa, quindi non vedrà i container del compose. O esponi le porte all'host dal compose e dal container solitario ti colleghi a localhost sulle porte esposte, o non lanci il container solitario (che è quello che pensavo tu facessi, visto che il container con PHP era già dentro compose) e magari usi docker exec per lanciare roba dentro un running container. Bye.
[toc] | [prev] | [next] | [standalone]
| From | sky winter <sky@bo.bo> |
|---|---|
| Date | 2019-01-12 19:23 +0100 |
| Message-ID | <q1dbbg$1i4c$1@gioia.aioe.org> |
| In reply to | #22483 |
Il 12/01/19 10:58, Alessandro Pellizzari ha scritto:
> Anche se potrebbe essere interessante, non ho proprio il tempo per
> debuggare tutto.
>
> In generale, quando lanci un gruppo con docker-compose, viene creata una
> rete privata tra i container definiti nel file.
>
> Se poi lanci un container a part con docker run sarà su una rete
> diversa, quindi non vedrà i container del compose.
>
> O esponi le porte all'host dal compose e dal container solitario ti
> colleghi a localhost sulle porte esposte, o non lanci il container
> solitario (che è quello che pensavo tu facessi, visto che il container
> con PHP era già dentro compose) e magari usi docker exec per lanciare
> roba dentro un running container.
Ho fatto alcune modifiche.
Al posto di *php:7.2.2-cli* adesso uso l'immagine *php:7.3-apache*
Ecco tutto il report
+ cat docker-compose.yml
version: '3'
services:
app:
build:
context: .
image: test-image
ports:
- 8080:80
volumes:
- .:/srv/app
links:
- mysql
- redis
environment:
DB_HOST: mysql
DB_DATABASE: laravel_docker
DB_USERNAME: app
DB_PASSWORD: password
REDIS_HOST: redis
SESSION_DRIVER: redis
CACHE_DRIVER: redis
mysql:
image: mysql:5.7
ports:
- 13306:3306
environment:
MYSQL_DATABASE: test
MYSQL_USER: myuser
MYSQL_PASSWORD: mypass
MYSQL_ROOT_PASSWORD: root2
redis:
image: redis:4.0-alpine
ports:
- 16379:6379
+ cat Dockerfile
FROM php:7.3-apache
#FROM php:7.2.2-cli
COPY . /var/www/html
WORKDIR /var/www/html
RUN docker-php-ext-install pdo_mysql
CMD mysql -u $MYSQL_USER -p $MYSQL_PASSWORD $MYSQL_DATABASE < test123.sql
+ docker-compose up --build
Building app
Step 1/5 : FROM php:7.3-apache
---> 3ff40df9d340
Step 2/5 : COPY . /var/www/html
---> 0febd9811534
Step 3/5 : WORKDIR /var/www/html
---> Running in c4524e6126b8
Removing intermediate container c4524e6126b8
---> 65ffb9b2d7be
Step 4/5 : RUN docker-php-ext-install pdo_mysql
---> Running in 9b6d00db21b2
Configuring for:
PHP Api Version: 20180731
Zend Module Api No: 20180731
Zend Extension Api No: 320180731
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for PHP prefix... /usr/local
checking for PHP includes... -I/usr/local/include/php
-I/usr/local/include/php/main -I/usr/local/include/php/TSRM
-I/usr/local/include/php/Zend -I/usr/local/include/php/ext
-I/usr/local/include/php/ext/date/lib
checking for PHP extension directory...
/usr/local/lib/php/extensions/no-debug-non-zts-20180731
checking for PHP installed headers prefix... /usr/local/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... re2c
checking for re2c version... 0.16 (ok)
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking for MySQL support for PDO... yes, shared
checking for the location of libz... no
checking for MySQL UNIX socket location...
checking for PDO includes... checking for PDO includes...
/usr/local/include/php/ext
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 1572864
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports
shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
/bin/bash /usr/src/php/ext/pdo_mysql/libtool --mode=compile cc
-I/usr/local/include/php/ext -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I.
-I/usr/src/php/ext/pdo_mysql -DPHP_ATOM_INC
-I/usr/src/php/ext/pdo_mysql/include -I/usr/src/php/ext/pdo_mysql/main
-I/usr/src/php/ext/pdo_mysql -I/usr/local/include/php
-I/usr/local/include/php/main -I/usr/local/include/php/TSRM
-I/usr/local/include/php/Zend -I/usr/local/include/php/ext
-I/usr/local/include/php/ext/date/lib -fstack-protector-strong -fpic
-fpie -O2 -DHAVE_CONFIG_H -fstack-protector-strong -fpic -fpie -O2 -c
/usr/src/php/ext/pdo_mysql/pdo_mysql.c -o pdo_mysql.lo
mkdir .libs
cc -I/usr/local/include/php/ext -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1
-I. -I/usr/src/php/ext/pdo_mysql -DPHP_ATOM_INC
-I/usr/src/php/ext/pdo_mysql/include -I/usr/src/php/ext/pdo_mysql/main
-I/usr/src/php/ext/pdo_mysql -I/usr/local/include/php
-I/usr/local/include/php/main -I/usr/local/include/php/TSRM
-I/usr/local/include/php/Zend -I/usr/local/include/php/ext
-I/usr/local/include/php/ext/date/lib -fstack-protector-strong -fpic
-fpie -O2 -DHAVE_CONFIG_H -fstack-protector-strong -fpic -fpie -O2 -c
/usr/src/php/ext/pdo_mysql/pdo_mysql.c -fPIC -DPIC -o .libs/pdo_mysql.o
/bin/bash /usr/src/php/ext/pdo_mysql/libtool --mode=compile cc
-I/usr/local/include/php/ext -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I.
-I/usr/src/php/ext/pdo_mysql -DPHP_ATOM_INC
-I/usr/src/php/ext/pdo_mysql/include -I/usr/src/php/ext/pdo_mysql/main
-I/usr/src/php/ext/pdo_mysql -I/usr/local/include/php
-I/usr/local/include/php/main -I/usr/local/include/php/TSRM
-I/usr/local/include/php/Zend -I/usr/local/include/php/ext
-I/usr/local/include/php/ext/date/lib -fstack-protector-strong -fpic
-fpie -O2 -DHAVE_CONFIG_H -fstack-protector-strong -fpic -fpie -O2 -c
/usr/src/php/ext/pdo_mysql/mysql_driver.c -o mysql_driver.lo
cc -I/usr/local/include/php/ext -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1
-I. -I/usr/src/php/ext/pdo_mysql -DPHP_ATOM_INC
-I/usr/src/php/ext/pdo_mysql/include -I/usr/src/php/ext/pdo_mysql/main
-I/usr/src/php/ext/pdo_mysql -I/usr/local/include/php
-I/usr/local/include/php/main -I/usr/local/include/php/TSRM
-I/usr/local/include/php/Zend -I/usr/local/include/php/ext
-I/usr/local/include/php/ext/date/lib -fstack-protector-strong -fpic
-fpie -O2 -DHAVE_CONFIG_H -fstack-protector-strong -fpic -fpie -O2 -c
/usr/src/php/ext/pdo_mysql/mysql_driver.c -fPIC -DPIC -o
.libs/mysql_driver.o
/bin/bash /usr/src/php/ext/pdo_mysql/libtool --mode=compile cc
-I/usr/local/include/php/ext -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I.
-I/usr/src/php/ext/pdo_mysql -DPHP_ATOM_INC
-I/usr/src/php/ext/pdo_mysql/include -I/usr/src/php/ext/pdo_mysql/main
-I/usr/src/php/ext/pdo_mysql -I/usr/local/include/php
-I/usr/local/include/php/main -I/usr/local/include/php/TSRM
-I/usr/local/include/php/Zend -I/usr/local/include/php/ext
-I/usr/local/include/php/ext/date/lib -fstack-protector-strong -fpic
-fpie -O2 -DHAVE_CONFIG_H -fstack-protector-strong -fpic -fpie -O2 -c
/usr/src/php/ext/pdo_mysql/mysql_statement.c -o mysql_statement.lo
cc -I/usr/local/include/php/ext -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1
-I. -I/usr/src/php/ext/pdo_mysql -DPHP_ATOM_INC
-I/usr/src/php/ext/pdo_mysql/include -I/usr/src/php/ext/pdo_mysql/main
-I/usr/src/php/ext/pdo_mysql -I/usr/local/include/php
-I/usr/local/include/php/main -I/usr/local/include/php/TSRM
-I/usr/local/include/php/Zend -I/usr/local/include/php/ext
-I/usr/local/include/php/ext/date/lib -fstack-protector-strong -fpic
-fpie -O2 -DHAVE_CONFIG_H -fstack-protector-strong -fpic -fpie -O2 -c
/usr/src/php/ext/pdo_mysql/mysql_statement.c -fPIC -DPIC -o
.libs/mysql_statement.o
/bin/bash /usr/src/php/ext/pdo_mysql/libtool --mode=link cc
-DPHP_ATOM_INC -I/usr/src/php/ext/pdo_mysql/include
-I/usr/src/php/ext/pdo_mysql/main -I/usr/src/php/ext/pdo_mysql
-I/usr/local/include/php -I/usr/local/include/php/main
-I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend
-I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib
-fstack-protector-strong -fpic -fpie -O2 -DHAVE_CONFIG_H
-fstack-protector-strong -fpic -fpie -O2 -Wl,-O1 -Wl,--hash-style=both
-pie -o pdo_mysql.la -export-dynamic -avoid-version -prefer-pic -module
-rpath /usr/src/php/ext/pdo_mysql/modules pdo_mysql.lo mysql_driver.lo
mysql_statement.lo
cc -shared .libs/pdo_mysql.o .libs/mysql_driver.o
.libs/mysql_statement.o -Wl,-O1 -Wl,--hash-style=both -Wl,-soname
-Wl,pdo_mysql.so -o .libs/pdo_mysql.so
creating pdo_mysql.la
(cd .libs && rm -f pdo_mysql.la && ln -s ../pdo_mysql.la pdo_mysql.la)
/bin/bash /usr/src/php/ext/pdo_mysql/libtool --mode=install cp
./pdo_mysql.la /usr/src/php/ext/pdo_mysql/modules
cp ./.libs/pdo_mysql.so /usr/src/php/ext/pdo_mysql/modules/pdo_mysql.so
cp ./.libs/pdo_mysql.lai /usr/src/php/ext/pdo_mysql/modules/pdo_mysql.la
PATH="$PATH:/sbin" ldconfig -n /usr/src/php/ext/pdo_mysql/modules
----------------------------------------------------------------------
Libraries have been installed in:
/usr/src/php/ext/pdo_mysql/modules
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
Build complete.
Don't forget to run 'make test'.
Installing shared extensions:
/usr/local/lib/php/extensions/no-debug-non-zts-20180731/
find . -name \*.gcno -o -name \*.gcda | xargs rm -f
find . -name \*.lo -o -name \*.o | xargs rm -f
find . -name \*.la -o -name \*.a | xargs rm -f
find . -name \*.so | xargs rm -f
find . -name .libs -a -type d|xargs rm -rf
rm -f libphp.la modules/* libs/*
Removing intermediate container 9b6d00db21b2
---> ae8178f80526
Step 5/5 : CMD mysql -u $MYSQL_USER -p $MYSQL_PASSWORD $MYSQL_DATABASE <
test123.sql
---> Running in ca207a4824a9
Removing intermediate container ca207a4824a9
---> bb4b2f6eb5cf
Successfully built bb4b2f6eb5cf
Successfully tagged test-image:latest
Recreating tmphbzh6gzgcy_mysql_1 ... done
Starting tmphbzh6gzgcy_redis_1 ... done
Recreating tmphbzh6gzgcy_app_1 ... done
Attaching to tmphbzh6gzgcy_redis_1, tmphbzh6gzgcy_mysql_1,
tmphbzh6gzgcy_app_1
redis_1 | 1:C 12 Jan 18:00:07.498 # oO0OoO0OoO0Oo Redis is starting
oO0OoO0OoO0Oo
redis_1 | 1:C 12 Jan 18:00:07.499 # Redis version=4.0.12, bits=64,
commit=00000000, modified=0, pid=1, just started
redis_1 | 1:C 12 Jan 18:00:07.499 # Warning: no config file specified,
using the default config. In order to specify a config file use
redis-server /path/to/redis.conf
redis_1 | 1:M 12 Jan 18:00:07.500 * Running mode=standalone, port=6379.
redis_1 | 1:M 12 Jan 18:00:07.500 # WARNING: The TCP backlog setting of
511 cannot be enforced because /proc/sys/net/core/somaxconn is set to
the lower value of 128.
redis_1 | 1:M 12 Jan 18:00:07.500 # Server initialized
redis_1 | 1:M 12 Jan 18:00:07.500 # WARNING overcommit_memory is set to
0! Background save may fail under low memory condition. To fix this
issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot
or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis_1 | 1:M 12 Jan 18:00:07.500 # WARNING you have Transparent Huge
Pages (THP) support enabled in your kernel. This will create latency and
memory usage issues with Redis. To fix this issue run the command 'echo
never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it
to your /etc/rc.local in order to retain the setting after a reboot.
Redis must be restarted after THP is disabled.
redis_1 | 1:M 12 Jan 18:00:07.500 * DB loaded from disk: 0.000 seconds
redis_1 | 1:M 12 Jan 18:00:07.500 * Ready to accept connections
mysql_1 | 2019-01-12T18:00:08.705961Z 0 [Warning] TIMESTAMP with
implicit DEFAULT value is deprecated. Please use
--explicit_defaults_for_timestamp server option (see documentation for
more details).
mysql_1 | 2019-01-12T18:00:08.719321Z 0 [Note] mysqld (mysqld 5.7.24)
starting as process 1 ...
app_1 | /bin/sh: 1: mysql: not found
mysql_1 | 2019-01-12T18:00:08.724380Z 0 [Note] InnoDB: PUNCH HOLE
support available
mysql_1 | 2019-01-12T18:00:08.724432Z 0 [Note] InnoDB: Mutexes and
rw_locks use GCC atomic builtins
mysql_1 | 2019-01-12T18:00:08.724439Z 0 [Note] InnoDB: Uses event mutexes
mysql_1 | 2019-01-12T18:00:08.724445Z 0 [Note] InnoDB: GCC builtin
__atomic_thread_fence() is used for memory barrier
mysql_1 | 2019-01-12T18:00:08.724450Z 0 [Note] InnoDB: Compressed
tables use zlib 1.2.11
mysql_1 | 2019-01-12T18:00:08.724463Z 0 [Note] InnoDB: Using Linux
native AIO
mysql_1 | 2019-01-12T18:00:08.724942Z 0 [Note] InnoDB: Number of pools: 1
mysql_1 | 2019-01-12T18:00:08.725148Z 0 [Note] InnoDB: Not using CPU
crc32 instructions
mysql_1 | 2019-01-12T18:00:08.730311Z 0 [Note] InnoDB: Initializing
buffer pool, total size = 128M, instances = 1, chunk size = 128M
mysql_1 | 2019-01-12T18:00:08.741690Z 0 [Note] InnoDB: Completed
initialization of buffer pool
mysql_1 | 2019-01-12T18:00:08.744329Z 0 [Note] InnoDB: If the mysqld
execution user is authorized, page cleaner thread priority can be
changed. See the man page of setpriority().
mysql_1 | 2019-01-12T18:00:08.761729Z 0 [Note] InnoDB: Highest
supported file format is Barracuda.
mysql_1 | 2019-01-12T18:00:09.336145Z 0 [Note] InnoDB: Creating shared
tablespace for temporary tables
mysql_1 | 2019-01-12T18:00:09.336433Z 0 [Note] InnoDB: Setting file
'./ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
mysql_1 | 2019-01-12T18:00:09.702172Z 0 [Note] InnoDB: File './ibtmp1'
size is now 12 MB.
mysql_1 | 2019-01-12T18:00:09.705669Z 0 [Note] InnoDB: 96 redo rollback
segment(s) found. 96 redo rollback segment(s) are active.
mysql_1 | 2019-01-12T18:00:09.705724Z 0 [Note] InnoDB: 32 non-redo
rollback segment(s) are active.
mysql_1 | 2019-01-12T18:00:09.706715Z 0 [Note] InnoDB: Waiting for
purge to start
mysql_1 | 2019-01-12T18:00:09.756929Z 0 [Note] InnoDB: 5.7.24 started;
log sequence number 3354953
mysql_1 | 2019-01-12T18:00:09.757147Z 0 [Note] InnoDB: Loading buffer
pool(s) from /var/lib/mysql/ib_buffer_pool
mysql_1 | 2019-01-12T18:00:09.757334Z 0 [Note] Plugin 'FEDERATED' is
disabled.
mysql_1 | 2019-01-12T18:00:09.855346Z 0 [Note] Found ca.pem,
server-cert.pem and server-key.pem in data directory. Trying to enable
SSL support using them.
mysql_1 | 2019-01-12T18:00:09.855660Z 0 [Warning] CA certificate ca.pem
is self signed.
mysql_1 | 2019-01-12T18:00:09.859131Z 0 [Note] Server hostname
(bind-address): '*'; port: 3306
mysql_1 | 2019-01-12T18:00:09.859193Z 0 [Note] IPv6 is available.
mysql_1 | 2019-01-12T18:00:09.859208Z 0 [Note] - '::' resolves to '::';
mysql_1 | 2019-01-12T18:00:09.859251Z 0 [Note] Server socket created on
IP: '::'.
mysql_1 | 2019-01-12T18:00:09.863229Z 0 [Note] InnoDB: Buffer pool(s)
load completed at 190112 18:00:09
mysql_1 | 2019-01-12T18:00:10.077256Z 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.
mysql_1 | 2019-01-12T18:00:10.080573Z 0 [Warning] 'user' entry
'root@localhost' ignored in --skip-name-resolve mode.
mysql_1 | 2019-01-12T18:00:10.080669Z 0 [Warning] 'user' entry
'mysql.session@localhost' ignored in --skip-name-resolve mode.
mysql_1 | 2019-01-12T18:00:10.080703Z 0 [Warning] 'user' entry
'mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1 | 2019-01-12T18:00:10.080756Z 0 [Warning] 'db' entry
'performance_schema mysql.session@localhost' ignored in
--skip-name-resolve mode.
mysql_1 | 2019-01-12T18:00:10.080784Z 0 [Warning] 'db' entry 'sys
mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1 | 2019-01-12T18:00:10.080819Z 0 [Warning] 'proxies_priv' entry
'@ root@localhost' ignored in --skip-name-resolve mode.
mysql_1 | 2019-01-12T18:00:10.083706Z 0 [Warning] 'tables_priv' entry
'user mysql.session@localhost' ignored in --skip-name-resolve mode.
mysql_1 | 2019-01-12T18:00:10.083764Z 0 [Warning] 'tables_priv' entry
'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql_1 | 2019-01-12T18:00:10.090934Z 0 [Note] Event Scheduler: Loaded
0 events
mysql_1 | 2019-01-12T18:00:10.091238Z 0 [Note] mysqld: ready for
connections.
mysql_1 | Version: '5.7.24' socket: '/var/run/mysqld/mysqld.sock'
port: 3306 MySQL Community Server (GPL)
tmphbzh6gzgcy_app_1 exited with code 127
Perchè?
Da notare che però se dal file Dockerfile tolgo la riga per importare il
database
CMD mysql -u $MYSQL_USER -p $MYSQL_PASSWORD $MYSQL_DATABASE < test123.sql
il container viene avviato senza problemi.
A me comunque mi interessa proprio importare il database.
[toc] | [prev] | [next] | [standalone]
| From | Alessandro Pellizzari <shuriken@amiran.it> |
|---|---|
| Date | 2019-01-12 19:50 +0000 |
| Message-ID | <g9uunmFacn7U1@mid.individual.net> |
| In reply to | #22484 |
On 12/01/2019 18:23, sky winter wrote: > Da notare che però se dal file Dockerfile tolgo la riga per importare il > database > > CMD mysql -u $MYSQL_USER -p $MYSQL_PASSWORD $MYSQL_DATABASE < test123.sql > > il container viene avviato senza problemi. > > A me comunque mi interessa proprio importare il database. https://hub.docker.com/_/mysql#initializing-a-fresh-instance Bye.
[toc] | [prev] | [next] | [standalone]
| From | sky winter <sky@bo.bo> |
|---|---|
| Date | 2019-01-13 10:36 +0100 |
| Message-ID | <q1f0q0$l0c$1@gioia.aioe.org> |
| In reply to | #22485 |
Il 12/01/19 20:50, Alessandro Pellizzari ha scritto:
> On 12/01/2019 18:23, sky winter wrote:
>
>> Da notare che però se dal file Dockerfile tolgo la riga per importare il
>> database
>>
>> CMD mysql -u $MYSQL_USER -p $MYSQL_PASSWORD $MYSQL_DATABASE < test123.sql
>>
>> il container viene avviato senza problemi.
>>
>> A me comunque mi interessa proprio importare il database.
>
> https://hub.docker.com/_/mysql#initializing-a-fresh-instance
>
> Bye.
>
L'importazione sembra funzionare (forse...), ma c'è sempre il solito
problema di connessione al database
+ cat docker-compose.yml
version: '3'
services:
app:
build:
context: .
image: test-image
ports:
- 8080:80
volumes:
- .:/srv/app
links:
- mysql
- redis
environment:
DB_HOST: mysql
DB_DATABASE: laravel_docker
DB_USERNAME: app
DB_PASSWORD: password
REDIS_HOST: redis
SESSION_DRIVER: redis
CACHE_DRIVER: redis
mysql:
image: mysql:5.7
ports:
- 13306:3306
environment:
MYSQL_DATABASE: test
MYSQL_USER: myuser
MYSQL_PASSWORD: mypass
MYSQL_ROOT_PASSWORD: root
redis:
image: redis:4.0-alpine
ports:
- 16379:6379
+ cat Dockerfile
FROM php:7.3-apache
COPY . /var/www/html
WORKDIR /var/www/html
RUN docker-php-ext-install pdo_mysql
COPY data.sql /docker-entrypoint-initdb.d
#CMD mysql -u $MYSQL_USER -p $MYSQL_PASSWORD $MYSQL_DATABASE < data.sql
+ cat index.php
<?php
$HOST = '127.0.0.1';
// TEST PRELIMINARE
if (fsockopen($HOST, 3306) === false) {
echo "Test della porta fallito\n";
}
$pdo = new PDO(
"mysql:host=$HOST;dbname=test",
'myuser',//user
'mypass'//pass
);
//require 'index2.php';
+ docker-compose up --build
Building app
...
AH00094: Command line: 'apache2 -D FOREGROUND'
Quindi vado al browser http://localhost:8080/
Compare questo
Warning: fsockopen(): unable to connect to 127.0.0.1:3306 (Connection
refused) in /var/www/html/index.php on line 5
Test della porta fallito
Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] Connection
refused in /var/www/html/index.php:12 Stack trace: #0
/var/www/html/index.php(12): PDO->__construct('mysql:host=127....',
'myuser', 'mypass') #1 {main} thrown in /var/www/html/index.php on line 12
Da notare l'esito del test peliminare: *Test della porta fallito*
Poi stavolta siamo all'interno di docker-composer quindi tutti container
dovrebbero comunicare tra loro, dovrebbero...........
[toc] | [prev] | [standalone]
Back to top | Article view | it.comp.www.php
csiph-web