Follow the documentation here,Always fail
Using a custom MySQL configuration file
The default configuration for MySQL can be found in /etc/mysql/my.cnf, which may !includedir additional directories such as /etc/mysql/conf.d or /etc/mysql/mysql.conf.d. Please inspect the relevant files and directories within the mysql image itself for more details.
If /my/custom/config-file.cnf is the path and name of your custom configuration file, you can start your mysql container like this (note that only the directory path of the custom config file is used in this command):
$ docker run --name some-mysql -v /my/custom:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
This will start a new container some-mysql where the MySQL instance uses the combined startup settings from /etc/mysql/my.cnf and /etc/mysql/conf.d/config-file.cnf, with settings from the latter taking precedence.
Configuration without a cnf file
Many configuration options can be passed as flags to mysqld. This will give you the flexibility to customize the container without needing a cnf file. For example, if you want to change the default encoding and collation for all tables to use UTF-8 (utf8mb4) just run the following:
$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
If you would like to see a complete list of available options, just run:
My version Docker version 18.09.7, build 2d0083d
The commands I run
docker run --name mysql2 -v /my/custom:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=root -d mysql:8.0.16
My custom configuration file
[mysqld]
sql_mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION"
I found the reason. Because I set the mysql.cnf permissions to 777.
Related
I want to configure the docker version of Open Project with the configuration.yml. Where has the file to be stored or where can I find it. None of the given external directories .asset and .pgconfig contains the yml file.
You can mount single files into your container. So we can adjust the example from the docs like this to include your own configuration.yml:
sudo mkdir -p /var/lib/openproject/{pgdata,assets}
printf "production:\n disable_password_login: true" > /var/lib/openproject/configuration.yml
docker run -d -p 8080:80 --name openproject -e SECRET_KEY_BASE=secret \
-v /var/lib/openproject/pgdata:/var/openproject/pgdata \
-v /var/lib/openproject/assets:/var/openproject/assets \
-v /var/lib/openproject/configuration.yml:/app/config/configuration.yml \
openproject/community:11
This, for instance, will disable the password login in OpenProject via the configuration.yml. Usually you would do this via env variables (-e OPENPROJECT_DISABLE__PASSWORD__LOGIN=true) but there are configurations such as for SAML which are indeed easier to just define in the configuration.yml instead.
The file inside of the container is /app/config/configuration.yml.
I am trying to start MySQL using docker image, I wanted to have a look at the binlog files, however I couldn't find them in /var/lib/mysql. From a few stackoverflow and Google reads, potential reason could be that mysql doesn't have permissions to write in /var/lib/mysql.
So I tried providing a different path using -v flag while starting the docker using the command docker run -it --rm --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=debezium -e MYSQL_USER=mysqluser -e MYSQL_PASSWORD=mysqlpw -v /home/username/mysql debezium/example-mysql:1.1
However, even after this, datadir variable in client still remains /var/lib/mysql. Can someone help me in this?
Using docker run -it --rm --name mysqlterm --link mysql --rm mysql:5.7 sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD" to start the MySQL client.
You are running client on different container and expect yo find logs there?
if you want see log files, you should run docker exec mysql bash, sometimes bash is not available, then use sh.
I am running Docker on a Macintosh, and have installed the MariaDB image. I would like to access it from another machine on the LAN.
I understand that the solution is to enable bind-address=0.0.0.0 (or something similar) in /etc/mysql/my.cnf. I executed docker exec -it mariadb bash, installed Joe text editor (because I am much more familiar with it than Vi or Nano), and edited the file.
The problem is that when I restart the Docker image,it has forgotten all the changes, and it doesn’t work.
Am I missing a step, or is this not the way to go about it?
Containers are throw-away by design and, as you noticed, any modifications are lost when you run fresh one.
You have two options:
First one is described here: Docker: editing my.cnf in when building the image (just mount your custom config and be done).
Second option is to make your custom container image based on official image + your modification, something like this:
Dockerfile:
# Lets say mariadb v10.3.28... Change for what you want.
FROM mariadb:10.3.28
# there is already `#bind-address=0.0.0.0` in /etc/mysql/my.cnf
# we use sed and replace it with `bind-address=0.0.0.0`)
RUN sed -i "s/#bind-address=0.0.0.0/bind-address=0.0.0.0/g" /etc/mysql/my.cnf && \
# and, for example, lets change `max_allowed_packet` too.
sed -i "s/max_allowed_packet.*/max_allowed_packet=512M/g" /etc/mysql/my.cnf;
(rule of thumbs is "make as many steps in single RUN as possible" to save image layers)
then build it:
$ cd /where/my/dockerfile/is
$ docker build . -t mymysql
and run it:
# In newer mariadb it should be `-e MARIADB_ROOT_PASSWORD=`
# And maybe you should mount datadir somewhere `-v /my/own/datadir:/var/lib/mysql`
$ docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=my-secret-pw mymysql
I started a docker container with mysql.
Actually i want to create a new user and a new table - and i have to do it in the MySQL Workbench.
This ist my docker run command:
docker run -p 3306:3306 --name mysql-server -v ~/Development/web/myproject/docker/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:latest
My Question is:
How can i add a sql startup script (only for the first start of the container) which creates my user and my table?
Which steps do i have to do?
Could some one help me here?
Thanks a lot!
You need to create user via MYSQL_USER, MYSQL_PASSWORD env vars and use volume /docker-entrypoint-initdb.d to map directory with your startup scripts (.sh, .sql, .sql.gz)
docker run -p 3306:3306 --name mysql-server \
-v ~/Development/web/myproject/docker/mysql:/var/lib/mysql \
-v ~/Development/web/myproject/docker/yourstartupscripts:/docker-entrypoint-initdb.d \
-e MYSQL_ROOT_PASSWORD=root \
-e MYSQL_USER=youruser \
-e MYSQL_PASSWORD=youruserpassword \
-d mysql:latest
Explanation from: https://hub.docker.com/_/mysql/
MYSQL_USER, MYSQL_PASSWORD
These variables are optional, used in conjunction to create a new user and to set that user's password. This user will be granted superuser permissions (see above) for the database specified by the MYSQL_DATABASE variable. Both variables are required for a user to be created.
Initializing a fresh instance
When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d. Files will be executed in alphabetical order. You can easily populate your mysql services by mounting a SQL dump into that directory and provide custom images with contributed data. SQL files will be imported by default to the database specified by the MYSQL_DATABASE variable.
What would be the best way to enable binary logging using the official mysql image?
I have tried using the mysql:5.7 image, overriding the command when running it to also pass through the startup options to enable binary logging to mysqld (see below). The problem with this approach is that the mysql user does not have permission to write to the /var/log/mysql directory.
The run command:
docker run -d \
--name mysql \
-v /var/lib/mysql:/var/lib/mysql \
mysql:5.7 \
mysqld \
--datadir=/var/lib/mysql \
--user=mysql \
--server-id=1 \
--log-bin=/var/log/mysql/mysql-bin.log \
--binlog_do_db=test
The output:
mysqld: File '/var/log/mysql/mysql-bin.index' not found (Errcode: 2 - No such file or directory)
Should I fork the repository and add a volume for /var/log/mysql which the mysql user can write to and create a custom image, or is there a better way to do it? Is this possible using only the official mysql image?
The problem with this approach is that the mysql user does not have permission to write to the /var/log/mysql directory
The problem actually is that the directory /var/log/mysql does not exists on the mysql:5.7 Docker image. You can make sure of it running the following container:
$ docker run --rm mysql:5.7 ls /var/log/
alternatives.log
apt
bootstrap.log
btmp
dmesg
dpkg.log
faillog
fsck
lastlog
wtmp
Furthermore, MySQL binary logs aren't logs meant for following your MySQL server activity or errors ; they are logs meant to give your MySQL server a chance to recover data in case of a server crash.
As a consequence, you want those binary logs:
to stay close to your data
to be written on a fast file system
In most cases, Docker container file system is slow and that's why the MySQL data folder for the container is declared as a VOLUME.
So you also want your binary logs to be written on a Docker data volume and not the Docker container file system.
long story short, start your container with:
docker run -d \
--name mysql \
-v /var/lib/mysql:/var/lib/mysql \
mysql:5.7 \
mysqld \
--datadir=/var/lib/mysql \
--user=mysql \
--server-id=1 \
--log-bin=/var/lib/mysql/mysql-bin.log \
--binlog_do_db=test