Part 6: Deploy LAMP Server with phpmyadmin using docker_compose file.

In this post, we will look how to use docker-compose.yml file to deploy multiple containers of an application.

Setup LAMP Server

### Create directories and file structure
$ touch docker-compose.yml
$ ls -ltr
total 8
-rw-r--r--  1 saket1447583  staff  573 Jan 15 05:54 docker-compose.yml
$ mkdir DocumentRoot
$ echo "<h1>Welcome to ngelinux.com</h1>" >> DocumentRoot/index.php

### Create below docker file
$ cat docker-compose.yml 
version: '3'
services:
    php-apache:
        image: php:7.2.1-apache
        ports:
            - 80:80
        volumes:
            - ./DocumentRoot:/var/www/html
        links:
            - 'mariadb'

    mariadb:
        image: mariadb:10.1
        volumes:
            - mariadb:/var/lib/mysql
        environment:
            TZ: "Europe/Rome"
            MYSQL_ALLOW_EMPTY_PASSWORD: "no"
            MYSQL_ROOT_PASSWORD: "rootpass"
            MYSQL_USER: 'test'
            MYSQL_PASSWORD: 'password'
            MYSQL_DATABASE: 'testdb'

    phpmyadmin:
        image: phpmyadmin/phpmyadmin
        container_name: phpmyadmin
        environment:
             - PMA_ARBITRARY=1
        restart: always
        ports:
             - 8080:80
        volumes:
          - /sessions


volumes:
    mariadb:



### We can check the config using config command.
$ docker-compose config 

### Bring the containers up
$ docker-compose up
Creating network "lamp_default" with the default driver
Creating volume "lamp_mariadb" with default driver
Pulling mariadb (mariadb:10.1)...
10.1: Pulling from library/mariadb
84ed7d2f608f: Pull complete
be2bf1c4a48d: Pull complete
a5bdc6303093: Pull complete
e9055237d68d: Pull complete
7eb9915af636: Pull complete
6368844241cc: Pull complete
4f7d49d7c8e4: Pull complete
cecb639f0dca: Pull complete
1cf91091f756: Pull complete
7824abcbc9b1: Pull complete
a20d02775fb3: Pull complete
44fdfa16736c: Pull complete
ff217892c080: Pull complete
26c996199998: Pull complete
Pulling php-apache (php:7.2.1-apache)...
7.2.1-apache: Pulling from library/php
e7bb522d92ff: Pull complete
75651f247827: Pull complete
dbcf8fd0150f: Pull complete
de80263f26f0: Pull complete
65be8ad4c5fd: Pull complete
239d5fed0dda: Pull complete
5ab39b683a9f: Pull complete
4a3f54f2d93a: Pull complete
28c970ad99e9: Pull complete
5d1e20c7c396: Pull complete
05f877a23903: Pull complete
e0a5c61bdaa6: Pull complete
d27d2d70a072: Pull complete
ba039fef4b7e: Pull complete
Creating lamp_mariadb_1 ... done
Creating lamp_php-apache_1 ... done
Attaching to lamp_mariadb_1, lamp_php-apache_1
mariadb_1     | Initializing database
mariadb_1     | 2019-01-15 15:01:15 140186028713984 [Note] /usr/sbin/mysqld (mysqld 10.1.37-MariaDB-1~bionic) starting as process 62 ...
mariadb_1     | 2019-01-15 15:01:15 140186028713984 [Note] InnoDB: Using mutexes to ref count buffer pool pages
mariadb_1     | 2019-01-15 15:01:15 140186028713984 [Note] InnoDB: The InnoDB memory heap is disabled
mariadb_1     | 2019-01-15 15:01:15 140186028713984 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
mariadb_1     | 2019-01-15 15:01:15 140186028713984 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
mariadb_1     | 2019-01-15 15:01:15 140186028713984 [Note] InnoDB: Compressed tables use zlib 1.2.11
mariadb_1     | 2019-01-15 15:01:15 140186028713984 [Note] InnoDB: Using Linux native AIO
mariadb_1     | 2019-01-15 15:01:15 140186028713984 [Note] InnoDB: Using Ngelinux crc32 instructions
mariadb_1     | 2019-01-15 15:01:15 140186028713984 [Note] InnoDB: Initializing buffer pool, size = 256.0M
mariadb_1     | 2019-01-15 15:01:15 140186028713984 [Note] InnoDB: Completed initialization of buffer pool
mariadb_1     | 2019-01-15 15:01:15 140186028713984 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
mariadb_1     | 2019-01-15 15:01:15 140186028713984 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
php-apache_1  | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.19.0.3. Set the 'ServerName' directive globally to suppress this message
php-apache_1  | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.19.0.3. Set the 'ServerName' directive globally to suppress this message
php-apache_1  | [Tue Jan 15 14:01:15.569276 2019] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.25 (Debian) PHP/7.2.1 configured -- resuming normal operations
php-apache_1  | [Tue Jan 15 14:01:15.569365 2019] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
mariadb_1     | 2019-01-15 15:01:15 140186028713984 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
mariadb_1     | 2019-01-15 15:01:16 140186028713984 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
mariadb_1     | 2019-01-15 15:01:17 140186028713984 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
mariadb_1     | 2019-01-15 15:01:17 140186028713984 [Warning] InnoDB: New log files created, LSN=45781
mariadb_1     | 2019-01-15 15:01:17 140186028713984 [Note] InnoDB: Doublewrite buffer not found: creating new
mariadb_1     | 2019-01-15 15:01:17 140186028713984 [Note] InnoDB: Doublewrite buffer created
mariadb_1     | 2019-01-15 15:01:17 140186028713984 [Note] InnoDB: 128 rollback segment(s) are active.
mariadb_1     | 2019-01-15 15:01:17 140186028713984 [Warning] InnoDB: Creating foreign key constraint system tables.
mariadb_1     | 2019-01-15 15:01:17 140186028713984 [Note] InnoDB: Foreign key constraint system tables created
mariadb_1     | 2019-01-15 15:01:17 140186028713984 [Note] InnoDB: Creating tablespace and datafile system tables.
mariadb_1     | 2019-01-15 15:01:17 140186028713984 [Note] InnoDB: Tablespace and datafile system tables created.
mariadb_1     | 2019-01-15 15:01:17 140186028713984 [Note] InnoDB: Waiting for purge to start
mariadb_1     | 2019-01-15 15:01:17 140186028713984 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.41-84.1 started; log sequence number 0
mariadb_1     | 2019-01-15 15:01:17 140185043990272 [Note] InnoDB: Dumping buffer pool(s) not yet started
mariadb_1     | 2019-01-15 15:01:20 140703570577408 [Note] /usr/sbin/mysqld (mysqld 10.1.37-MariaDB-1~bionic) starting as process 90 ...
mariadb_1     | 2019-01-15 15:01:20 140703570577408 [Note] InnoDB: Using mutexes to ref count buffer pool pages
mariadb_1     | 2019-01-15 15:01:20 140703570577408 [Note] InnoDB: The InnoDB memory heap is disabled
mariadb_1     | 2019-01-15 15:01:20 140703570577408 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
mariadb_1     | 2019-01-15 15:01:20 140703570577408 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
mariadb_1     | 2019-01-15 15:01:20 140703570577408 [Note] InnoDB: Compressed tables use zlib 1.2.11
mariadb_1     | 2019-01-15 15:01:20 140703570577408 [Note] InnoDB: Using Linux native AIO
mariadb_1     | 2019-01-15 15:01:20 140703570577408 [Note] InnoDB: Using Ngelinux crc32 instructions
mariadb_1     | 2019-01-15 15:01:20 140703570577408 [Note] InnoDB: Initializing buffer pool, size = 256.0M
mariadb_1     | 2019-01-15 15:01:20 140703570577408 [Note] InnoDB: Completed initialization of buffer pool
mariadb_1     | 2019-01-15 15:01:20 140703570577408 [Note] InnoDB: Highest supported file format is Barracuda.
mariadb_1     | 2019-01-15 15:01:20 140703570577408 [Note] InnoDB: 128 rollback segment(s) are active.
mariadb_1     | 2019-01-15 15:01:20 140703570577408 [Note] InnoDB: Waiting for purge to start
mariadb_1     | 2019-01-15 15:01:20 140703570577408 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.41-84.1 started; log sequence number 1616697
mariadb_1     | 2019-01-15 15:01:20 140702591743744 [Note] InnoDB: Dumping buffer pool(s) not yet started
mariadb_1     | 2019-01-15 15:01:23 140684935059456 [Note] /usr/sbin/mysqld (mysqld 10.1.37-MariaDB-1~bionic) starting as process 119 ...
mariadb_1     | 2019-01-15 15:01:24 140684935059456 [Note] InnoDB: Using mutexes to ref count buffer pool pages
mariadb_1     | 2019-01-15 15:01:24 140684935059456 [Note] InnoDB: The InnoDB memory heap is disabled
mariadb_1     | 2019-01-15 15:01:24 140684935059456 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
mariadb_1     | 2019-01-15 15:01:24 140684935059456 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
mariadb_1     | 2019-01-15 15:01:24 140684935059456 [Note] InnoDB: Compressed tables use zlib 1.2.11
mariadb_1     | 2019-01-15 15:01:24 140684935059456 [Note] InnoDB: Using Linux native AIO
mariadb_1     | 2019-01-15 15:01:24 140684935059456 [Note] InnoDB: Using Ngelinux crc32 instructions
mariadb_1     | 2019-01-15 15:01:24 140684935059456 [Note] InnoDB: Initializing buffer pool, size = 256.0M
mariadb_1     | 2019-01-15 15:01:24 140684935059456 [Note] InnoDB: Completed initialization of buffer pool
mariadb_1     | 2019-01-15 15:01:24 140684935059456 [Note] InnoDB: Highest supported file format is Barracuda.
mariadb_1     | 2019-01-15 15:01:24 140684935059456 [Note] InnoDB: 128 rollback segment(s) are active.
mariadb_1     | 2019-01-15 15:01:24 140684935059456 [Note] InnoDB: Waiting for purge to start
mariadb_1     | 2019-01-15 15:01:24 140684935059456 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.41-84.1 started; log sequence number 1616707
mariadb_1     | 2019-01-15 15:01:24 140683956451072 [Note] InnoDB: Dumping buffer pool(s) not yet started
mariadb_1     | 
mariadb_1     | PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
mariadb_1     | To do so, start the server, then issue the following commands:
mariadb_1     | 
mariadb_1     | '/usr/bin/mysqladmin' -u root password 'new-password'
mariadb_1     | '/usr/bin/mysqladmin' -u root -h  password 'new-password'
mariadb_1     | 
mariadb_1     | Alternatively you can run:
mariadb_1     | '/usr/bin/mysql_secure_installation'
mariadb_1     | 
mariadb_1     | which will also give you the option of removing the test
mariadb_1     | databases and anonymous user created by default.  This is
mariadb_1     | strongly recommended for production servers.
mariadb_1     | 
mariadb_1     | See the MariaDB Knowledgebase at http://mariadb.com/kb or the
mariadb_1     | MySQL manual for more instructions.
mariadb_1     | 
mariadb_1     | Please report any problems at http://mariadb.org/jira
mariadb_1     | 
mariadb_1     | The latest information about MariaDB is available at http://mariadb.org/.
mariadb_1     | You can find additional information about the MySQL part at:
mariadb_1     | http://dev.mysql.com
mariadb_1     | Consider joining MariaDB's strong and vibrant community:
mariadb_1     | https://mariadb.org/get-involved/
mariadb_1     | 
mariadb_1     | Database initialized
mariadb_1     | 2019-01-15 15:01:27 139952076605440 [Note] mysqld (mysqld 10.1.37-MariaDB-1~bionic) starting as process 152 ...
mariadb_1     | MySQL init process in progress...
mariadb_1     | 2019-01-15 15:01:27 139952076605440 [Note] InnoDB: Using mutexes to ref count buffer pool pages
mariadb_1     | 2019-01-15 15:01:27 139952076605440 [Note] InnoDB: The InnoDB memory heap is disabled
mariadb_1     | 2019-01-15 15:01:27 139952076605440 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
mariadb_1     | 2019-01-15 15:01:27 139952076605440 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
mariadb_1     | 2019-01-15 15:01:27 139952076605440 [Note] InnoDB: Compressed tables use zlib 1.2.11
mariadb_1     | 2019-01-15 15:01:27 139952076605440 [Note] InnoDB: Using Linux native AIO
mariadb_1     | 2019-01-15 15:01:27 139952076605440 [Note] InnoDB: Using Neglinux crc32 instructions
mariadb_1     | 2019-01-15 15:01:27 139952076605440 [Note] InnoDB: Initializing buffer pool, size = 256.0M
mariadb_1     | 2019-01-15 15:01:27 139952076605440 [Note] InnoDB: Completed initialization of buffer pool
mariadb_1     | 2019-01-15 15:01:27 139952076605440 [Note] InnoDB: Highest supported file format is Barracuda.
mariadb_1     | 2019-01-15 15:01:27 139952076605440 [Note] InnoDB: 128 rollback segment(s) are active.
mariadb_1     | 2019-01-15 15:01:27 139952076605440 [Note] InnoDB: Waiting for purge to start
mariadb_1     | 2019-01-15 15:01:27 139952076605440 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.41-84.1 started; log sequence number 1616717
mariadb_1     | 2019-01-15 15:01:27 139951098296064 [Note] InnoDB: Dumping buffer pool(s) not yet started
mariadb_1     | 2019-01-15 15:01:27 139952076605440 [Note] Plugin 'FEEDBACK' is disabled.
mariadb_1     | 2019-01-15 15:01:27 139952076605440 [Warning] 'user' entry 'root@18d933aeca50' ignored in --skip-name-resolve mode.
mariadb_1     | 2019-01-15 15:01:27 139952076605440 [Warning] 'proxies_priv' entry '@% root@18d933aeca50' ignored in --skip-name-resolve mode.
mariadb_1     | 2019-01-15 15:01:27 139952076605440 [Note] mysqld: ready for connections.
mariadb_1     | Version: '10.1.37-MariaDB-1~bionic'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  mariadb.org binary distribution
mariadb_1     | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
mariadb_1     | 2019-01-15 15:01:31 139952075754240 [Warning] 'proxies_priv' entry '@% root@18d933aeca50' ignored in --skip-name-resolve mode.
mariadb_1     | 
mariadb_1     | 2019-01-15 15:01:31 139952075447040 [Note] mysqld: Normal shutdown
mariadb_1     | 2019-01-15 15:01:31 139952075447040 [Note] Event Scheduler: Purging the queue. 0 events
mariadb_1     | 2019-01-15 15:01:31 139951144408832 [Note] InnoDB: FTS optimize thread exiting.
mariadb_1     | 2019-01-15 15:01:31 139952075447040 [Note] InnoDB: Starting shutdown...
mariadb_1     | 2019-01-15 15:01:31 139952075447040 [Note] InnoDB: Waiting for page_cleaner to finish flushing of buffer pool
mariadb_1     | 2019-01-15 15:01:33 139952075447040 [Note] InnoDB: Shutdown completed; log sequence number 1616727
mariadb_1     | 2019-01-15 15:01:33 139952075447040 [Note] mysqld: Shutdown complete
mariadb_1     | 
mariadb_1     | 
mariadb_1     | MySQL init process done. Ready for start up.
mariadb_1     | 
mariadb_1     | 2019-01-15 15:01:33 139851696273408 [Note] mysqld (mysqld 10.1.37-MariaDB-1~bionic) starting as process 1 ...
mariadb_1     | 2019-01-15 15:01:33 139851696273408 [Note] InnoDB: Using mutexes to ref count buffer pool pages
mariadb_1     | 2019-01-15 15:01:33 139851696273408 [Note] InnoDB: The InnoDB memory heap is disabled
mariadb_1     | 2019-01-15 15:01:33 139851696273408 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
mariadb_1     | 2019-01-15 15:01:33 139851696273408 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
mariadb_1     | 2019-01-15 15:01:33 139851696273408 [Note] InnoDB: Compressed tables use zlib 1.2.11
mariadb_1     | 2019-01-15 15:01:33 139851696273408 [Note] InnoDB: Using Linux native AIO
mariadb_1     | 2019-01-15 15:01:33 139851696273408 [Note] InnoDB: Using Ngelinux crc32 instructions
mariadb_1     | 2019-01-15 15:01:33 139851696273408 [Note] InnoDB: Initializing buffer pool, size = 256.0M
mariadb_1     | 2019-01-15 15:01:33 139851696273408 [Note] InnoDB: Completed initialization of buffer pool
mariadb_1     | 2019-01-15 15:01:33 139851696273408 [Note] InnoDB: Highest supported file format is Barracuda.
mariadb_1     | 2019-01-15 15:01:33 139851696273408 [Note] InnoDB: 128 rollback segment(s) are active.
mariadb_1     | 2019-01-15 15:01:33 139851696273408 [Note] InnoDB: Waiting for purge to start
mariadb_1     | 2019-01-15 15:01:33 139851696273408 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.41-84.1 started; log sequence number 1616727
mariadb_1     | 2019-01-15 15:01:33 139850716018432 [Note] InnoDB: Dumping buffer pool(s) not yet started
mariadb_1     | 2019-01-15 15:01:33 139851696273408 [Note] Plugin 'FEEDBACK' is disabled.
mariadb_1     | 2019-01-15 15:01:33 139851696273408 [Note] Server socket created on IP: '::'.
mariadb_1     | 2019-01-15 15:01:33 139851696273408 [Warning] 'proxies_priv' entry '@% root@18d933aeca50' ignored in --skip-name-resolve mode.
mariadb_1     | 2019-01-15 15:01:33 139851696273408 [Note] mysqld: ready for connections.
mariadb_1     | Version: '10.1.37-MariaDB-1~bionic'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
php-apache_1  | 172.19.0.1 - - [15/Jan/2019:14:07:22 +0000] "GET / HTTP/1.1" 200 262 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:64.0) Gecko/20100101 Firefox/64.0"
php-apache_1  | 172.19.0.1 - - [15/Jan/2019:14:07:23 +0000] "GET /favicon.ico HTTP/1.1" 404 500 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:64.0) Gecko/20100101 Firefox/64.0"
php-apache_1  | 172.19.0.1 - - [15/Jan/2019:14:07:44 +0000] "GET / HTTP/1.1" 200 262 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.2 Safari/605.1.15"
php-apache_1  | 172.19.0.1 - - [15/Jan/2019:14:07:45 +0000] "GET /favicon.ico HTTP/1.1" 404 501 "http://localhost/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0.2 Safari/605.1.15"

^CGracefully stopping... (press Ctrl+C again to force)
Stopping lamp_php-apache_1 ... done
Stopping lamp_mariadb_1    ... done


Output



$ docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
mariadb                 10.1                5a34bfc8f676        2 weeks ago         375MB
phpmyadmin/phpmyadmin   latest              15ca549393be        5 weeks ago         166MB
php                     7.2.1-apache        f99d319c7004        12 months ago       377MB

$ docker ps --all
CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS                            NAMES
82181b391f92        phpmyadmin/phpmyadmin   "/run.sh supervisord…"   3 minutes ago       Up 3 minutes        9000/tcp, 0.0.0.0:8080->80/tcp   phpmyadmin
265e1f9c08a0        php:7.2.1-apache        "docker-php-entrypoi…"   40 minutes ago      Up 40 minutes       0.0.0.0:80->80/tcp               lamp_php-apache_1
18d933aeca50        mariadb:10.1            "docker-entrypoint.s…"   About an hour ago   Up 40 minutes       3306/tcp                         lamp_mariadb_1
References:
https://linuxconfig.org/how-to-create-a-docker-based-lamp-stack-using-docker-compose-on-ubuntu-18-04-bionic-beaver-linux
https://hub.docker.com/r/phpmyadmin/phpmyadmin/
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments