I need to execute these commands on every startup since it looks to be overwritten every time I set and restart it
mysql -uroot -padmin;
set global general_log = 1;
I start the docker container with docker-compose for development purposes only and it looks like this.
version: "3.8"
services:
mysql_service:
container_name: db_container
build:
context: .
dockerfile: ./db/Dockerfile.dev
# needed for mysql 8+
command: --default-authentication-plugin=mysql_native_password
restart: always
hostname: db
ports:
- target: 3306
published: 3306
protocol: tcp
mode: host
environment:
- MYSQL_ROOT_PASSWORD=admin
- MYSQL_DATABASE=example
- MYSQL_ROOT_HOST=localhost
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
volumes:
- ./db/:/docker-entrypoint-initdb.d/
- data_volume:/var/lib/mysql/
cap_add:
- ALL
volumes:
data_volume:
driver: local
and the Dockerfile
FROM mysql:8.0
COPY ./DevOps/Docker/db/set_logging.sh /usr/local/bin
ENTRYPOINT ["docker-entrypoint.sh", "./usr/local/bin/set_logging.sh"]
However the copy goes through but the script is never executed. Where the script looks like
#!/bin/bash
mysql -uroot -padmin -e "set global general_log = 1"
Any suggestions on getting this command to go through? This is only for development
--general-log=1to your service command in your docker-compose file. To see a list of all config option you can set on the docker command line for mysql:8.0 without having to push a custom config to your container:docker run -it --rm mysql:8.0 --verbose --help. The official mysql docker image documentation has much more info on how to customize your container for various use cases.- commandsection of a docker-compose file.