0

I have lamp and phpmyadmin by docker.

My setting is like this below localhost:80 -> web localhost:8081 -> phpmyadmin

However if I access to phpmyadmin

it shows error like this mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'172.27.0.4' (using password: YES)

These are my setting.

docker-compose.yml

version: '2' services: mysql: container_name: lampmysql build: ./mysql environment: MYSQL_ROOT_PASSWORD: passsql volumes: - db:/var/lib/mysql php: container_name: lampphp build: ./php ports: - '80:80' volumes: - ./html:/var/www/html depends_on: - mysql phpmyadmin: container_name: lampphpmyadmin image: phpmyadmin/phpmyadmin environment: - PMA_ARBITRARY=1 - PMA_HOST=mysql - PMA_USER=root - PMA_PASSWORD=passsql links: - mysql:mysql ports: - 8081:80 volumes: - /sessions volumes: db: 

phpmyadmin/Dockerfile

FROM php:7.2-fpm-alpine RUN apk add --no-cache \ nginx \ supervisor # Install dependencies RUN set -ex; \ \ apk add --no-cache --virtual .build-deps \ bzip2-dev \ freetype-dev \ libjpeg-turbo-dev \ libpng-dev \ libwebp-dev \ libxpm-dev \ ; \ \ docker-php-ext-configure gd --with-freetype-dir=/usr --with-jpeg-dir=/usr --with-webp-dir=/usr --with-png-dir=/usr --with-xpm-dir=/usr; \ docker-php-ext-install bz2 gd mysqli opcache zip; \ \ runDeps="$( \ scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \ | tr ',' '\n' \ | sort -u \ | awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \ )"; \ apk add --virtual .phpmyadmin-phpexts-rundeps $runDeps; \ apk del .build-deps # Copy configuration COPY etc /etc/ # Copy main script COPY run.sh /run.sh RUN chmod u+rwx /run.sh # Calculate download URL ENV VERSION 4.8+snapshot ENV URL https://files.phpmyadmin.net/snapshots/phpMyAdmin-${VERSION}-all-languages.tar.gz LABEL version=$VERSION # Download tarball, verify it using gpg and extract RUN set -ex; \ curl --output phpMyAdmin.tar.gz --location $URL; \ tar xzf phpMyAdmin.tar.gz; \ rm -f phpMyAdmin.tar.gz phpMyAdmin.tar.gz.asc; \ mv phpMyAdmin-$VERSION-all-languages /www; \ rm -rf /www/setup/ /www/examples/ /www/test/ /www/po/ /www/composer.json /www/RELEASE-DATE-$VERSION; \ sed -i "s@define('CONFIG_DIR'.*@define('CONFIG_DIR', '/etc/phpmyadmin/');@" /www/libraries/vendor_config.php; \ chown -R root:nobody /www; \ find /www -type d -exec chmod 750 {} \; ; \ find /www -type f -exec chmod 640 {} \; # Add directory for sessions to allow session persistence RUN mkdir /sessions \ && mkdir -p /www/tmp \ && chmod -R 777 /www/tmp # We expose phpMyAdmin on port 80 EXPOSE 80 ENTRYPOINT [ "/run.sh" ] CMD ["phpmyadmin"] 

1 Answer 1

1

my suggestion is to change the links of phpmyadmin to: - mysql:mysql_db_server.

In addition, try to add all environment variables to mysql:

MYSQL_ROOT_PASSWORD=root MYSQL_DATABASE=db_name MYSQL_HOST= mysql MYSQL_USER=root MYSQL_PASSWORD=root MYSQL_PORT=3306 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks to your reply. I found out MYSQL_ROOT_PASSWORD: passsql in docker-composer.yml was wring. I changed this to MYSQL_ROOT_PASSWORD=passsql. it works

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.