Answer the question
In order to leave comments, you need to log in
How to setup connection to mysql docker container?
Good afternoon, I'm trying to deal with docker, set up compose, everything works with one exception, when I try to connect to mysql I get an error: "SQLSTATE[HY000] [2002] Connection refused".
docker-compose.yml:
version: "3.1"
services:
memcached:
image: memcached:alpine
container_name: tkdruzhba-memcached
redis:
image: redis:alpine
container_name: tkdruzhba-redis
mysql:
image: mysql:8.0
container_name: tkdruzhba-mysql
working_dir: /application
volumes:
- .:/application
environment:
- MYSQL_DATABASE=dev
- MYSQL_USER=dev
- MYSQL_PASSWORD=devpass
- MYSQL_ROOT_PASSWORD=root
ports:
- "3306:3306"
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
environment:
- PMA_ARBITRARY=1
- PMA_HOST=mysql
restart: always
ports:
- 8083:80
volumes:
- /sessions
webserver:
image: nginx:alpine
container_name: tkdruzhba-webserver
working_dir: /application
volumes:
- .:/application
- ./phpdocker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "8080:80"
php-fpm:
build: phpdocker/php-fpm
container_name: tkdruzhba-php-fpm
working_dir: /application
volumes:
- .:/application
- ./phpdocker/php-fpm/php-ini-overrides.ini:/etc/php/7.1/fpm/conf.d/99-overrides.ini
FROM phpdockerio/php71-fpm:latest
WORKDIR "/application"
# Fix debconf warnings upon build
ARG DEBIAN_FRONTEND=noninteractive
# Install selected extensions and other stuff
RUN apt-get update \
&& apt-get -y --no-install-recommends install php-memcached php7.1-mysql php-redis php7.1-ldap \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
# Install git
RUN apt-get update \
&& apt-get -y install git \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
Answer the question
In order to leave comments, you need to log in
in containers that need access to mysql:
depends_on:
- mysql
docker exec -it название_запущенного_контейнера bash -c 'PGPASSWORD="$POSTGRES_PASSWORD" psql -U "$POSTGRES_USER" -d "$POSTGRES_DB"'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question