Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #17699 > unrolled thread

docker: apache, php and mysql

Started byalex <1j9448a02@lnx159sneakemail.com.invalid>
First post2018-03-13 20:31 +0100
Last post2018-03-15 20:33 -0400
Articles 13 — 5 participants

Back to article view | Back to comp.lang.php


Contents

  docker: apache, php and mysql alex <1j9448a02@lnx159sneakemail.com.invalid> - 2018-03-13 20:31 +0100
    Re: docker: apache, php and mysql Jerry Stuckle <jstucklex@attglobal.net> - 2018-03-14 17:15 -0400
      Re: docker: apache, php and mysql alex <1j9448a02@lnx159sneakemail.com.invalid> - 2018-03-15 09:08 +0100
        Re: docker: apache, php and mysql Martin Gregorie <martin@mydomain.invalid> - 2018-03-15 12:31 +0000
          Re: docker: apache, php and mysql alex <1j9448a02@lnx159sneakemail.com.invalid> - 2018-03-15 14:38 +0100
            Re: docker: apache, php and mysql Martin Gregorie <martin@mydomain.invalid> - 2018-03-15 14:56 +0000
              Re: docker: apache, php and mysql alex <1j9448a02@lnx159sneakemail.com.invalid> - 2018-03-15 17:41 +0100
                Re: docker: apache, php and mysql MeV <michael.vilain@gmail.com> - 2018-03-15 11:03 -0700
                  Re: docker: apache, php and mysql alex <1j9448a02@lnx159sneakemail.com.invalid> - 2018-03-15 19:14 +0100
        Re: docker: apache, php and mysql Jerry Stuckle <jstucklex@attglobal.net> - 2018-03-15 14:16 -0400
          Re: docker: apache, php and mysql alex <1j9448a02@lnx159sneakemail.com.invalid> - 2018-03-15 20:46 +0100
          Re: docker: apache, php and mysql Percival John Hackworth <pjh@nanoworks.com> - 2018-03-15 16:41 -0700
            Re: docker: apache, php and mysql Jerry Stuckle <jstucklex@attglobal.net> - 2018-03-15 20:33 -0400

#17699 — docker: apache, php and mysql

Fromalex <1j9448a02@lnx159sneakemail.com.invalid>
Date2018-03-13 20:31 +0100
Subjectdocker: apache, php and mysql
Message-ID<p898u7$lb0$1@gioia.aioe.org>
+ 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?

[toc] | [next] | [standalone]


#17700

FromJerry Stuckle <jstucklex@attglobal.net>
Date2018-03-14 17:15 -0400
Message-ID<p8c3cl$nd3$1@jstuckle.eternal-september.org>
In reply to#17699
On 3/13/2018 3:31 PM, alex wrote:
> + 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?

Is your database host actually named "mysql"?

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

[toc] | [prev] | [next] | [standalone]


#17701

Fromalex <1j9448a02@lnx159sneakemail.com.invalid>
Date2018-03-15 09:08 +0100
Message-ID<p8d9l0$ucg$1@gioia.aioe.org>
In reply to#17700
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?

[toc] | [prev] | [next] | [standalone]


#17702

FromMartin Gregorie <martin@mydomain.invalid>
Date2018-03-15 12:31 +0000
Message-ID<p8dp3b$4j8$2@news.albasani.net>
In reply to#17701
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.



-- 
Martin    | martin at
Gregorie  | gregorie dot org

[toc] | [prev] | [next] | [standalone]


#17703

Fromalex <1j9448a02@lnx159sneakemail.com.invalid>
Date2018-03-15 14:38 +0100
Message-ID<p8dt00$14v$1@gioia.aioe.org>
In reply to#17702
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)?

[toc] | [prev] | [next] | [standalone]


#17704

FromMartin Gregorie <martin@mydomain.invalid>
Date2018-03-15 14:56 +0000
Message-ID<p8e1jn$ef2$1@news.albasani.net>
In reply to#17703
On Thu, 15 Mar 2018 14:38:09 +0100, alex wrote:

> 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)?

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.





-- 
Martin    | martin at
Gregorie  | gregorie dot org

[toc] | [prev] | [next] | [standalone]


#17705

Fromalex <1j9448a02@lnx159sneakemail.com.invalid>
Date2018-03-15 17:41 +0100
Message-ID<p8e7n6$ldd$1@gioia.aioe.org>
In reply to#17704
Il 15/03/2018 15:56, Martin Gregorie ha scritto:
> On Thu, 15 Mar 2018 14:38:09 +0100, alex wrote:
> 
>> 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)?
> 
> 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.

$ 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


[toc] | [prev] | [next] | [standalone]


#17706

FromMeV <michael.vilain@gmail.com>
Date2018-03-15 11:03 -0700
Message-ID<4b626346-7e10-4940-84f1-d428abc1576a@googlegroups.com>
In reply to#17705
On Thursday, March 15, 2018 at 9:41:20 AM UTC-7, alex wrote:
> Il 15/03/2018 15:56, Martin Gregorie ha scritto:
> > On Thu, 15 Mar 2018 14:38:09 +0100, alex wrote:
> > 
> >> 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)?
> > 
> > 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.
> 
> $ 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

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.

[toc] | [prev] | [next] | [standalone]


#17707

Fromalex <1j9448a02@lnx159sneakemail.com.invalid>
Date2018-03-15 19:14 +0100
Message-ID<p8ed6g$1016$1@gioia.aioe.org>
In reply to#17706
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?

[toc] | [prev] | [next] | [standalone]


#17708

FromJerry Stuckle <jstucklex@attglobal.net>
Date2018-03-15 14:16 -0400
Message-ID<p8edam$33u$1@jstuckle.eternal-september.org>
In reply to#17701
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.

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

[toc] | [prev] | [next] | [standalone]


#17709

Fromalex <1j9448a02@lnx159sneakemail.com.invalid>
Date2018-03-15 20:46 +0100
Message-ID<p8eiil$1a36$1@gioia.aioe.org>
In reply to#17708
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

[toc] | [prev] | [next] | [standalone]


#17710

FromPercival John Hackworth <pjh@nanoworks.com>
Date2018-03-15 16:41 -0700
Message-ID<0001HW.205B3C2700D093BC14E5F02CF@news.individual.net>
In reply to#17708
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.

-- 
DeeDee, don't press that button! DeeDee! NO! Dee...

[toc] | [prev] | [next] | [standalone]


#17711

FromJerry Stuckle <jstucklex@attglobal.net>
Date2018-03-15 20:33 -0400
Message-ID<p8f3cp$1pt$1@jstuckle.eternal-september.org>
In reply to#17710
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.

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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web