Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > it.comp.www.php > #22476
| From | sky winter <sky@bo.bo> |
|---|---|
| Newsgroups | it.comp.www.php |
| Subject | importare database mysql dentro un contenitore (docker) |
| Date | 2019-01-07 14:57 +0100 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <q0vlro$omj$1@gioia.aioe.org> (permalink) |
$ 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?
Back to it.comp.www.php | Previous | Next — Next in thread | Find similar | Unroll thread
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
csiph-web