Reputation: 1545
I am using docker for windows, I just installed it and I have the following stack.yml
file which returns an error I will put below the yml
file. I don't understand what may be causing the issue I am running the command docker-compose -f stack.yml up
do get everything to work, could someone please help. Thanks ahead of time.
version: '3.1'
services:
wordpress:
image: wordpress
restart: always
ports:
- 8080:80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: examplepass
WORDPRESS_DB_NAME: exampledb
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass
MYSQL_RANDOM_ROOT_PASSWORD: '1'
error
wordpress_1 | Complete! WordPress has been successfully copied to /var/www/html
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) Connection refused
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): (HY000/2002): Connection refused in Standard input code on line 22
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): (HY000/2002): Connection refused in Standard input code on line 22
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) Connection refused
wordpress_1 |
wordpress_1 | Warning: mysqli::__construct(): (HY000/2002): Connection refused in Standard input code on line 22
Upvotes: 0
Views: 220
Reputation: 727
The app needs to have the db
run beforehand.
Add the depends_on
value for the WordPress service, which will make sure the db is container is up, before the WordPress container.
The MySQL service within the container should boot up soon.
version: '3.1'
services:
wordpress:
image: wordpress
restart: always
depends_on:
- db
ports:
- 8080:80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: exampleuser
WORDPRESS_DB_PASSWORD: examplepass
WORDPRESS_DB_NAME: exampledb
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: exampledb
MYSQL_USER: exampleuser
MYSQL_PASSWORD: examplepass
MYSQL_RANDOM_ROOT_PASSWORD: '1'
Upvotes: 1