Docker mysql mounted logs directory always empty - mysql

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

Related

My mysql container in Docker, via the feature I gave it from the dockerfile to restart itself, keeps turning itself on and off

My mysql container in docker, via the feature I gave it from the dockerfile to restart itself, keeps turning itself on and off after I attempted the docker-compose up --build command.
My Dockerfile contains several containers, including an apache, a mysql with a volume to save the data of a database and a php.
I ran into this problem as I was carrying out various tests since I had just created the volume and I wanted to see if the database was not losing the data inside it.
After various commands of docker-compose down and docker-compose up it happened that the mysql container did not work anymore, not even after other commands docker-compose down and docker-compose build --no-cache.
below i added my docker.compose.yml
all versions of the images and data for the database are taken from the various dockerfiles
version: "3.2"
services:
php:
build:
context: './php/'
args:
PHP_VERSION: ${PHP_VERSION}
networks:
- backend
volumes:
- ${PROJECT_ROOT}/:/var/www/html/
container_name: php
apache:
build:
context: './apache/'
args:
APACHE_VERSION: ${APACHE_VERSION}
depends_on:
- php
- mysql
networks:
- frontend
- backend
ports:
- "80:80"
volumes:
- ${PROJECT_ROOT}/:/var/www/html/
container_name: apache
mysql:
image: mysql:${MYSQL_VERSION:-latest}
restart: always
ports:
- "3306:3306"
volumes:
- data:/var/lib/mysql
networks:
- backend
environment:
MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
MYSQL_DATABASE: "${DB_NAME}"
MYSQL_USER: "${DB_USERNAME}"
MYSQL_PASSWORD: "${DB_PASSWORD}"
container_name: mysql networks:
frontend:
backend:
volumes:
data:
Anyone can describe me what I can do in this case in order not to lose the progress made so far within the database since doing a little research they tell me that the volume and the image of mysql may have been corrupted?

Why edit contents of docker-compose.yml are not reflected?

I want to use MySQL by using Docker.
I wrote the following DockerFile and docker-compose.yml.
Dockerfile
FROM mysql:8.0
RUN mkdir /var/log/mysql
RUN touch /var/log/mysql/mysqld.log
docker-compose.yml
version: '3'
services:
dbserver:
build: ./docker/mysql
image: test-db:0.0.1
restart: always
environment:
MYSQL_DATABASE: prototype
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: rootpassword
ports:
- "3306:3306"
volumes:
- ./docker/mysql/initdb.d:/docker-entrypoint-initdb.d
- ./docker/mysql/conf.d:/etc/mysql/conf.d
- ./log/mysql:/var/log/mysql
- ./docker/mysql/data:/var/lib/mysql
volumes:
mysql-bd:
driver: local
I succeeded build and could confirm the database.
Then I wanted to change the database name, so I edited a part of the yml file following.
Before
MYSQL_DATABASE: prototype
After
MYSQL_DATABASE: test_db
Then, I confirmed the database but its name was not changed.
I removed the MySQL container and tried again, but the result was not changed.
Why edit contents of docker-compose.yml are not reflected?
You are using a host volume for your database, meaning that the databases are persisted between containers restarts.
...
volumes:
./docker/mysql/data:/var/lib/mysql
...
Delete the local directory ./docker/mysql/data and restart your services. The database change will be reflected.

Not able to create standalone MySQL Docker Container in Azure AppService

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!

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