Answer the question
In order to leave comments, you need to log in
Why does an error occur when starting Bitrix in docker?
There was an error connecting to the database when starting Bitrix in docker.
Previously, I used OpenServer to work locally with PHP projects, now I decided to start working on docker. Deployed docker under windows 10.
In the Win-10 host system at the root of drive D at my project/local/.docker I placed the docker settings files and folders
This
is how the contents of my docker folder look like:
go to my project/local/.docker folder and run docker commands
In docker, I created several containers
project-web - php container where the project is located on Bitrix (business edition)
db - mysql container
phpmyadmin - container for phpmyadmin
elasticsearch - container for elasticsearch application
docker-compose.yml file code
version: "3"
services:
bitrix:
container_name: project-web
build:
./php
ports:
- 8018:80
volumes:
- ../..:/var/www/html:cached
- ./apache/site.conf:/etc/apache2/sites-available/000-default.conf
links:
- db
- elasticsearch
environment:
MYSQL_ROOT_PASSWORD: qwerty
depends_on:
- db
- elasticsearch
db:
container_name: project-db
build:
./mysql
command:
mysqld --innodb-flush-method=littlesync --innodb-use-native-aio=OFF --log_bin=ON
volumes:
- ./db:/var/lib/mysql:cached
- ./mysql/backup:/home/backup
environment:
MYSQL_ROOT_PASSWORD: qwerty
phpmyadmin:
container_name: project-pma
image: phpmyadmin/phpmyadmin
links:
- db
ports:
- 8765:80
environment:
MYSQL_ROOT_PASSWORD: qwerty
PMA_HOST: db
depends_on:
- db
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.9.1
container_name: project-es
environment:
ES_JAVA_OPTS: '-Xms256m -Xmx256m'
discovery.type: single-node
mbstring.func_overload = 2
mbstring.internal_encoding = UTF-8
memory_limit = 512M
short_open_tag = 1
display_errors = 1
opcache.revalidate_freq = 0
max_input_vars = 100000
date.timezone = Europe/Moscow
max_execution_time = 120
#extension=tideways_xhprof.so
FROM php:7.1-apache
RUN apt-get update
RUN apt-get install libxml2 curl -y
RUN docker-php-ext-install pdo pdo_mysql mysqli json mbstring opcache
RUN apt-get update && apt-get install -y libpng-dev
RUN apt-get install -y \
libwebp-dev \
libjpeg62-turbo-dev \
libpng-dev libxpm-dev \
libfreetype6-dev
RUN docker-php-ext-configure gd \
--with-gd \
--with-webp-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-xpm-dir \
--with-freetype-dir \
--enable-gd-native-ttf
RUN docker-php-ext-install gd
RUN apt-get install libxml2-dev libxslt-dev -y
RUN docker-php-ext-install xsl
RUN apt-get install -y libcurl4-openssl-dev pkg-config libssl-dev
RUN docker-php-ext-install zip
RUN a2enmod rewrite
RUN usermod -u 1000 www-data && groupmod -g 1000 www-data
WORKDIR /var/www/html
COPY custom.ini $PHP_INI_DIR/conf.d/
Bitrix\Main\DB\ConnectionException]
Mysql connect error [localhost]: (2002) No such file or directory (400)
/var/www/html/bitrix/modules/main/lib/db/mysqliconnection.php:65
#0: Bitrix\Main\DB\MysqliConnection->connectInternal()
/var/www/html/bitrix/modules/main/lib/data/connection.php:53
#1: Bitrix\Main\Data\Connection->getResource()
/var/www/html/bitrix/modules/main/lib/db/mysqlisqlhelper.php:21
#2: Bitrix\Main\DB\MysqliSqlHelper->forSql(string)
/var/www/html/bitrix/modules/main/lib/config/option.php:193
#3: Bitrix\Main\Config\Option::load(string)
/var/www/html/bitrix/modules/main/lib/config/option.php:38
#4: Bitrix\Main\Config\Option::get(string, string, string)
/var/www/html/bitrix/modules/main/lib/httprequest.php:394
#5: Bitrix\Main\HttpRequest->prepareCookie(array)
/var/www/html/bitrix/modules/main/lib/httprequest.php:71
#6: Bitrix\Main\HttpRequest->__construct(object, array, array, array, array)
/var/www/html/bitrix/modules/main/lib/httpapplication.php:48
#7: Bitrix\Main\HttpApplication->initializeContext(array)
/var/www/html/bitrix/modules/main/lib/application.php:123
#8: Bitrix\Main\Application->initializeExtendedKernel(array)
/var/www/html/bitrix/modules/main/include.php:24
#9: require_once(string)
/var/www/html/bitrix/modules/main/include/prolog_before.php:14
#10: require_once(string)
/var/www/html/bitrix/modules/main/include/prolog.php:10
#11: require_once(string)
/var/www/html/bitrix/header.php:1
#12: require(string)
/var/www/html/index.php:2
Answer the question
In order to leave comments, you need to log in
You specified the Localhost host in the connection configs in MYSQL, but you have the database in a separate container, db.
Specify it as a connection host
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question