There is a docker with Apache + PHP + MySQL + OpenSSL, you need to configure the docker so that all the connections are through the docker, and the server remains: the database and the body of the site, but how many instructions on the Internet, I do not understand where to dig further, what has been done :

  1. Docker is configured, hanging on port 80;
  2. Installed volume, docker run -it -p 80:80 --net = "host" --privileged -v mSQL: / var / lib / mysql / demo_ehealth apache2_ufw_mysql_php_iit_ulimit / bin / sh;
  3. Using the docker volume inspect command, mSQL determined the location of the / var / snap / docker / common / var-lib-docker / volumes / mSQL / _data directory;
  4. In _data copied the body of the site and database.

I don’t know what to do next, I will be grateful for clarifying advice on what to do next, as I understand it, you need to create a virtual host for Apache, but how do you know where this directory is mounted in Docker? And how to attach the control to the database, I hope that you do not need to create an IP, it will be enough just to specify the MySQL port, but how do you know the port and IP?

    1 answer 1

    1. It is better to run mysql and apache in different containers.
    2. easier to use docker-compose

    file ./.docker/docker-compose.yml

    version: "2" services: web: build: context: . dockerfile: ./php/Dockerfile volumes: - ${SRC_PATH}:/var/www/html ports: - ${WEB_PORT}:80 environment: DB_HOST: db DB_NAME: ${DB_NAME} DB_USER: ${DB_USER} DB_PASS: ${DB_PASS} depends_on: - db links: - db db: image: mysql:5.7 expose: - 3306 environment: MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD} MYSQL_USER: ${DB_USER} MYSQL_PASSWORD: ${DB_PASS} MYSQL_DATABASE: ${DB_NAME} volumes: - ${MYSQL_DATA_DIR}:/var/lib/mysql 

    file ./.docker/.env

     COMPOSE_TLS_VERSION=TLSv1_2 SRC_PATH=../website WEB_PORT=80 MYSQL_DATA_DIR=../mysql-data DB_ROOT_PASSWORD=test DB_USER=test DB_PASS=test DB_NAME=db_test 

    file ./.docker/php/Dockerfile

     FROM php:7.1-apache WORKDIR /var/www/html COPY ./php/apache.conf /etc/apache2/sites-available/001-front.conf RUN docker-php-ext-install pdo_mysql && \ useradd -ms /bin/bash appuser && usermod -a -G www-data appuser && \ a2ensite 001-front && \ a2dissite 000-default && \ a2enmod rewrite CMD ["apache2-foreground"] 

    file ./.docker/php/apache.conf

     <VirtualHost *:80> ServerAdmin webmaster@example.ru DocumentRoot /var/www/html/web DirectoryIndex index.php <Directory /var/www/html/web> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/www-error_log CustomLog ${APACHE_LOG_DIR}/www-access_log common </VirtualHost> 

    file ./website/web/index.php

     <?php $host = getenv("DB_HOST"); $dbname = getenv("DB_NAME"); $user = getenv("DB_USER"); $pass = getenv("DB_PASS"); $dbh = new PDO('mysql:host='.$host.';dbname='.$dbname, $user, $pass); $stmt = $dbh->query('SELECT NOW() as curtime', PDO::FETCH_ASSOC); $res = $stmt->fetch(); echo "now=".$res['curtime']; 

    set the necessary values ​​in the .env file, execute cd .docker && docker-compose up -d --build

    when opening the page in the browser - the html-page with the time in the mysql database will be displayed