Not able to create standalone MySQL Docker Container in Azure AppService - mysql

I am doing a Proof of Concept where in, I have 3 Azure App Service. Two of the App Service are API's and One of them has a MySql container. I am unable to get the App Service running with My Sql Container. I followed the example in this website minus the Wordpress portion.
I tried to get the My Sql Portion of the container working. When I start the App Service, it starts My SQL Instance but get below error. Do not see any other information.
"INFO - Stoping site MySqlTest because it failed during startup."
I am using the below docker compose
version: '3.3'
services:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
ports:
- "8000:80"

Try providing the volume as well
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress

You can add the command in the docker-compose file:
version: '3.3'
services:
db:
image: mysql:5.7
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
ports:
- "8000:80"
The command will solve your current problem. In addition, I think the port you had exposed in the docker-compose file is not right. The MySQL listens to the port 3306 inside the container. So you need to expose the port 3306 for the container.

I tried multiple ways to create MySQl container deployed in Azure App Service, but had issues to get it working. I tried with Azure Container Instance and it worked fine!

Related

how to use docker with wordpress and nginx

i try to use docker for use wordpress with https, but that not work,
i have the message :
wordpress | MySQL Connection Error: (2002) Connection refused
version: "3.8"
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
container_name: wordpress
image: wordpress:php7.4-apache
restart: always
stdin_open: true
tty: true
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
- ./wordpress:/var/www/html
nginx:
container_name: nginx
image: nginx:latest
restart: unless-stopped
ports:
- 80:80
- 443:443
volumes:
- ./nginx/conf:/etc/nginx/conf.d
I had the same problem today and after lots of unsuccessful attempts, I think adding expose helped :
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
expose:
-"3306"
Reference : https://docs.docker.com/compose/compose-file/#expose
firstly, your title is "how to use wp with nginx" but in your docker compose file, you are clearly pulling a wordpress:apache image.
secondly, you can delete the whole content related to nginx since that container runs alone and outside the scope of your wordpress.
now, that you only have wordpress and db as services in your yml file (which is how it should be), you must add a ports directive to wordpress:
ports:
- 80:80
And finally, for the containers to be able to resolve their ips within the same network, you need to add this at the end of your yml file:
volumes:
wordpress:
db:
Now this will ensure you're running a wordpress with a db, and the wordpress image runs apache (which is httpd, not nginx).
Thirdly, if you're not satisfied with httpd and want an nginx container, you'll need to look for a wordpress image on hub.docker.com that runs on nginx.

docker mysql wordpress port doesn't connect

I downloaded the mysql and wordpress images. Mysql ports are
3306 localhost:32781
33060 localhost:32780
Wordpress configuration is
WORDPRESS_DB_HOST 192.168.99.100:32774
MYSQL_ROOT_PASSWORD and WORDPRESS_DB_PASSWORD are the same
I try to connect to wordpress with
http://192.168.99.100:32774/
I get the message
This site can’t be reached
How do I have to configure the ports of mysql and wordpress?
CONFIGURATION MYSQL
WORDPRESS
Error trace
From what you can find on the docker configuration page, you should take this example and modify it to your needs.
There is the following docker-compose file that will launch a wordpress in a minute:
https://docs.docker.com/compose/wordpress/
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
From that file you have various options like, using docker compose tool (https://docs.docker.com/compose), or if you have a swarm running you could use docker stack command(https://vsupalov.com/difference-docker-compose-and-docker-stack/) or you can divide the configuration of both elements and create separate Dockerfile's(the configuration of a Docker file differs from what you can see on docker-compose so take the information an create your own) and launch them separated, you should launch mysql first as wordpress depends on a bbdd running first.
The easiest way to implement this is using docker-compose. Here is an example:
version: '3.2'
services:
database:
image: mysql:5.7
volumes:
- my_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: root_password
MYSQL_DATABASE: wordpress
MYSQL_USER: wp_user
MYSQL_PASSWORD: password
wordpress:
depends_on:
- database
image: wordpress:php7.3-apache
ports:
- '8000:80'
restart: always
environment:
WORDPRESS_DB_HOST: database:3306
WORDPRESS_DB_USER: wp_user
WORDPRESS_DB_PASSWORD: password
working_dir: /var/www/html
volumes:
my_data: {}
A few notes: the database doesn't mount any port on host because it doesn't need to. If you don't want to use docker-compose you can run docker run commands for this but then you have to create your own network for the containers and attach them to it.
Wordpress will be available on http://localhost:8000.
WORDPRESS_DB_HOST is the connection to the database and you won't be able to access that through http anyway.
Hope this helps you.

Docker Wordpress keeps redirecting to online version of site

I'm trying to set up docker wordpress as my dev environment on Ubuntu 17.10. I've made a copy of the db and placed it into the docker mysql service on port 8080 (using a wp plugin, which changes the home and site url)
I've arrived at the docker-compose.yml file below, but everytime I go to localhost:8000 or port 80 I get redirected to the original site online. I'm at a loss as to know what is wrong?
version: '3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: rootPword
MYSQL_DATABASE: xyz_wp
MYSQL_USER: xyz_2015
MYSQL_PASSWORD: userPword
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
# generally need to use non-default values
WORDPRESS_DB_HOST: db:3306
# next line often not in tutorials - https://stackoverflow.com/questions/46117771/issue-getting-docker-to-access-my-database-properly-with-wordpress
WORDPRESS_DB_NAME: xyz_wp
WORDPRESS_DB_USER: xyz_2015
WORDPRESS_DB_PASSWORD: userPword
WORDPRESS_TABLE_PREFIX: "af_"
working_dir: /var/www/html
volumes:
- /home/simon/code/wp_af2015/wp-content:/var/www/html/wp-content
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
environment:
MYSQL_USERNAME: root
MYSQL_ROOT_PASSWORD: rootPword
restart: always
ports:
- 8080:80
links:
- db
volumes:
db_data:
I think there is a little misunderstanding here.
when you add : after the domain it specifies the port.
From the Screenshot of PhpMyAdmin, it seems you set the Wordpress on port 8000. Because after :, 8000 has been set.
From your docker file, there is a mistake, because from what you written, it is wrong.
The ports should be or :80 or :8000, but not both.
If you want your docker to listen to localhost port 8000 (your WP),
then on your docker config, you should set:
ports:
- "8000"
Restart Docker, and it should work as expected.
A day later I tried to reach the dev site using an incognito window and everything worked! So the solve was to delete my browsing data from my normal browser. I do not understand what happened but the issue is fixed

Docker: how to use SQL file in Directory

I'm trying to open a Wordpress website locally with Docker.
Here is the docker-compose.yml file for this container:
version: '3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
db_data:
The Dockerfile:
FROM orchardup/php5
ADD . /code
In the terminal, I enter docker-compose up -d. I can then visit the site at localhost:8080, but it's not the actual website - it's just a Wordpress template. I'm guessing I have to incorporate the .sql file in the directory somehow? How would I go about doing this? Do I need to specify this in the .yml file?
Just add a volume mapping to map a local folder to the /docker-entrypoint-initdb.d container folder, for example : ./init-db:/docker-entrypoint-initdb.d. This file will be loaded on the first container startup.
Considering the docker-compose.yml bellow :
drop your sql files into /path-to-sql-files-on-your-host host folder)
run docker-compose down -v to destroy containers and volumes
run docker-compose up to recreate them.
-
version: '3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
- /path-to-sql-files-on-your-host:/docker-entrypoint-initdb.d
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
db_data:
According to the MySQL-Docker documentation, you have a couple of options.
After the 'db' docker is running, simply connect to it using the mysql client, and import your .sql dump. Read the section 'Connect to MySQL from the MySQL command line client' If you where not using docker, you would restore this backup like this mysql fooDB < fooDB_dump.sql It will be similar with docker commands.
Docs, "Initializing a fresh instance", says "...it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d" That looks more like what you want. Just copy your .sql file into that location within the docker image and then it will automatically parse it.

Docker mysql mounted logs directory always empty

I am trying to mount MySql logs on my host machine, using MySql official image. But it seems like its not mounting properly, the directory is always empty, however, the other volumes that I am mounting are working properly. Am I missing something?
version: "2"
services:
mysql:
image: mysql:5.7
restart: always
environment:
MYSQL_ROOT_PASSWORD: testing
MYSQL_DATABASE: testing
MYSQL_USER: test
MYSQL_PASSWORD: testing
ports:
- 3306:3306
volumes:
- ./.data/mysql/logs:/var/log/mysql
- ./.data/mysql/data:/var/lib/mysql
- ./mysql/conf.d:/etc/mysql/conf.d
- ./mysql/initdb.d:/docker-entrypoint-initdb.d