Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

docker: apache, php and mysql

64 views
Skip to first unread message

alex

unread,
Mar 13, 2018, 3:31:27 PM3/13/18
to
+ cat docker-compose.yml
version: '3.3'
services:
app:
build:
context: .
dockerfile: docker/Dockerfile
image: laravel-docker
ports:
- 4000:80
volumes:
- ./src:/var/www/html
links:
- mysql
- redis
environment:
DB_HOST: mysql
DB_DATABASE: test
DB_USERNAME: root
DB_PASSWORD: root
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: root
MYSQL_ROOT_PASSWORD: root
volumes:
- ./dump.sql:/docker-entrypoint-initdb.d/dump.sql
redis:
image: redis:4.0-alpine
ports:
- 16379:6379

+ cat docker/Dockerfile
FROM php:7.2.2-apache
RUN docker-php-ext-install mbstring pdo pdo_mysql

+ cat src/index.php
<?php
error_reporting(255);

$pdo = new PDO(
'mysql:dbname=test;host=mysql',
'root',
'root'
);

+ docker-compose up -d --build
Building app
...

+ curl http://localhost:4000
<b>Fatal error</b>: Uncaught PDOException: SQLSTATE[HY000] [2002]
Connection refused in /var/www/html/index.php:7

Because it does not work?

Jerry Stuckle

unread,
Mar 14, 2018, 5:15:13 PM3/14/18
to
Is your database host actually named "mysql"?

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstu...@attglobal.net
==================

alex

unread,
Mar 15, 2018, 4:08:10 AM3/15/18
to
Il 14/03/2018 22:15, Jerry Stuckle ha scritto:
>
> Is your database host actually named "mysql"?

Maybe you're right, but how do I know the name?
How can I configure it?

Martin Gregorie

unread,
Mar 15, 2018, 8:31:49 AM3/15/18
to
Try reading the mysql configuration file, looking at parameters passed to
the ODBC module by another application, etc.



--
Martin | martin at
Gregorie | gregorie dot org

alex

unread,
Mar 15, 2018, 9:38:16 AM3/15/18
to
Il 15/03/2018 13:31, Martin Gregorie ha scritto:
> On Thu, 15 Mar 2018 09:08:01 +0100, alex wrote:
>
>> Il 14/03/2018 22:15, Jerry Stuckle ha scritto:
>>>
>>> Is your database host actually named "mysql"?
>>
>> Maybe you're right, but how do I know the name?
>> How can I configure it?
>
> Try reading the mysql configuration file, looking at parameters passed to
> the ODBC module by another application, etc.
>
>
>

How (excuse the ignorance)?

Martin Gregorie

unread,
Mar 15, 2018, 10:57:01 AM3/15/18
to
Read manpage or manual to find the name of the config file.
Find config file on the computer running mysql
Read it.

OR

Find source for an application that talks to mysql
Read its source.

alex

unread,
Mar 15, 2018, 12:41:20 PM3/15/18
to
$ sudo mysqld --verbose --help | grep -A 1 "Default options"
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf

OK, but into docker

$ docker-compose run app mysqld --verbose --help

Starting dockermysql_mysql_1 ...
Starting dockermysql_mysql_1 ... done
/usr/local/bin/docker-php-entrypoint: 9: exec: mysqld: not found



MeV

unread,
Mar 15, 2018, 2:03:18 PM3/15/18
to
Change the Dockerfile that builds the mysql container to default to the mysql binary directory or better yet change the startup script to be tolerant of absolute and relative paths.

alex

unread,
Mar 15, 2018, 2:14:52 PM3/15/18
to
Il 15/03/2018 19:03, MeV ha scritto:
> Change the Dockerfile that builds the mysql container to default to the mysql binary directory

Could you explain me better?
I'm sorry, but I've been using docker for a short time.

> or better yet change the startup script to be tolerant of absolute and relative paths.

What script?
index.php?

Jerry Stuckle

unread,
Mar 15, 2018, 2:17:29 PM3/15/18
to
Forget docker. MySQL is not that hard to configure. Look at the manual
at dev.mysql.com; it's long but all you need to look at is the
installation and configuration section for your OS.

Or, better yet - which flavor of Linux are you using? Most have RPMs or
similar to install MySQL on the system from their repository.

And the host name is the name of your server - i.e. "localhost" if MySQL
is on the same server you are running your scripts on, or the host name
or ip address of a remote server.

alex

unread,
Mar 15, 2018, 3:46:39 PM3/15/18
to
Il 15/03/2018 19:16, Jerry Stuckle ha scritto:
>
> Forget docker.

And then what is it for?

> MySQL is not that hard to configure.  Look at the manual
> at dev.mysql.com; it's long but all you need to look at is the
> installation and configuration section for your OS.
>

On my operating system it is installed, and it works properly.

> Or, better yet - which flavor of Linux are you using?

ubuntu 16.04

>  Most have RPMs or
> similar to install MySQL on the system from their repository.
>

Certainly.

> And the host name is the name of your server - i.e. "localhost" if MySQL
> is on the same server you are running your scripts on, or the host name
> or ip address of a remote server.

version: '3.3'
services:
app:
build:
context: .
dockerfile: docker/Dockerfile
image: laravel-docker
ports:
- 4000:80
volumes:
- ./src:/var/www/html
links:
- mysql
- redis
environment:
DB_HOST: localhost
...

but it does not change anything

Jerry Stuckle

unread,
Mar 15, 2018, 8:33:35 PM3/15/18
to
On 3/15/2018 7:41 PM, Percival John Hackworth wrote:
> On 15-Mar-2018, Jerry Stuckle wrote
> (in article<p8edam$33u$1...@jstuckle.eternal-september.org>):
>
>> On 3/15/2018 4:08 AM, alex wrote:
>>> Il 14/03/2018 22:15, Jerry Stuckle ha scritto:
>>>>
>>>> Is your database host actually named "mysql"?
>>>
>>> Maybe you're right, but how do I know the name?
>>> How can I configure it?
>>
>> Forget docker. MySQL is not that hard to configure. Look at the manual
>> at dev.mysql.com; it's long but all you need to look at is the
>> installation and configuration section for your OS.
>>
>> Or, better yet - which flavor of Linux are you using? Most have RPMs or
>> similar to install MySQL on the system from their repository.
>>
>> And the host name is the name of your server - i.e. "localhost" if MySQL
>> is on the same server you are running your scripts on, or the host name
>> or ip address of a remote server.
>
> Jerry's recommendations (hell almost anything he posts) should be taken with
> several Kg of NaCl. Usually all I hear when I read his stuff are those
> trombones from the Peanuts cartoons.
>
> Anyway, the Docker container for mysql or mariadb has everything you need to
> run an instance with on-system storage. All you need is an init sql script
> and a mount point to store the files. You can either take it and run it as
> part of your Docker-compose file or take the container's Dockerfile and
> modify it to your own needs.
>
> If this is running on a VM then I'd follow Jerry's advise and just install
> mysql/maria into the base VM (Yes, I'm just a shocked as you are). Populate
> it and just have it as part of the system that that your containers access.
>

OTOH, I've installed MySQL many times and never needed Docker. It just
adds another unnecessary level of complexity. You can install both PHP
and MySQL from the Ubuntu repository and PDO requires nothing more. No
init script required and the mount point is already defined.

But then we already know you have limited technical capabilities and
have no idea how to manually install and configure anything. There is
zero difference between running in a VM and running standalone as far as
the applications are concerned. You can get a full server, or a virtual
server. In the latter case you're running under a VM. But as far as
the applications, everything is identical. Just some minor differences
deep in the kernel.
0 new messages