Hello currently I get in touch with Docker. I am doing their getting started and I ran into a problem which I cant solve and I dont understand why it dont work. First of all I create a network using.
$ docker network create todo-app
After that, I set up a Container mysql database and connect it with the network with following code.
$ docker run -d \
--network todo-app --network-alias mysql \
-v todo-mysql-data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=secret \
-e MYSQL_DATABASE=todos \
mysql:5.7
I check for the Container id with
$ docker ps
After that I use the command to get into the mysql CLI ? (not sure on that yet)
$ docker exec -it mysql -u root -p
After getting there I use
mysql> SHOW DATABASES;
to show all DB on my PC? But there is non listed named todos and i dont know why it dont appear.
I would like to hear what you are thinking im struggeling a little there. Thanks for the replies. Sorry for my english skills.
Run container in the foreground and check the logs.
Following Part 7: Multi-container apps, I ran into this exact issue just now.
Chances are, you have run that same command at least once.
# command to run as per the docs
docker run -d \
--network todo-app --network-alias mysql \
-v todo-mysql-data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=secret \
-e MYSQL_DATABASE=todos \
mysql:5.7
And the first time you ran the command you unknowingly made a mistake. For me, I mistyped MYSQL_DATABASE FOR MYSQL_ROOT_PASSWORD. Yours might be different. In any case, it seems making small mistakes like this might have caused the mysql:5.7 image to not be set up correctly with the todos database. (Not entirely sure.)
Adding to that, the first time you run that command, Docker creates a todo-mysql-data volume, which does not get overwritten when you run that same command again.
So as a "fix", you might have to delete the todo-mysql-data volume first.
docker volume rm todo-mysql-data
And then re-create the todo-mysql-data volume implicitly by re-running the image with the above command; this time without mistakes.
Sorry for the trouble it was my fault I guess cause I used the Command I pointed out above but I definetly had to use this command :
docker run -d \
--network todo-app --network-alias mysql \
--platform "linux/amd64" \
-v todo-mysql-data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=secret \
-e MYSQL_DATABASE=todos \
mysql:5.7
Because im using Linux... Such a dumb mistake but i swear this wasnt there two months ago when I asked this Qeustion.
Related
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'm starting to use docker implement mysql in our environment. But I have a little bit confuse about it.
1. I have tried to use command, it's working
sudo docker run --name mysql5.7 --restart always --privileged=true -p 4306:3006 -v /Users/user/mysql/config/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf -v /Users/user/mysql/data:/var/lib/mysql -e MYSQL_USER=“usr” -e MYSQL_PASSWORD=“1234” -e MYSQL_ROOT_PASSWORD=“1234” -d mysql:5.7
But follow docker document, they suggest use volume to persist data. So I tried crate a volume first docker volume -d create local mysql_v
try to link mysql to volume mysql_v, but I don't know how to do it and what is different with step 1.
anyone can suggest it ~?
Like
docker run --name mysql5.7 --restart always -p 4306:3006 \
-v /Users/user/mysql/config/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf \
-v mysql_v:/var/lib/mysql \
-e MYSQL_USER=“usr” -e MYSQL_PASSWORD=“1234” \
-e MYSQL_ROOT_PASSWORD=“1234” -d mysql:5.7
Note, privileged removed, that's just asking for trouble
Ref: official documents
I'm following this guide to use MySQL 8.0 in Docker (on macOS host), but I'm having some issues. I have no Docker experience other than this, so please be easy on me. I tried to debug as best I could. It seems the author of the guide has some outdated commands/syntax errors (not sure which), which I think I've fixed. However, when I try to run the following command, I keep getting the error below:
Command:
docker run --restart always --name mysql8.0 --network dev-network -v /Users/[my-name]/mysql/data/8.0:/var/lib/mysql -p 3306:3308 -d -e MYSQL_ROOT_PASSWORD=[my-password] mysql:8.0
( [my-name] and [my-password] are subbed out).
Error:
"docker run" requires at least 1 argument.
I've checked docker run --help but can't get any further.
I've also found this question and this question, but those cases seem highly specific to the OPs' situation, so the answers didn't yield any successful results for me.
Any help or suggestions are appreciated.
The command you've pasted works fine. There is a possibility that the password you're entering has some special characters making the shell think of it as something else. (Or your volume next to -v flag has some special characters).
Just to test, try with a simple password like this:
docker run --restart always --name mysql8.0 --network dev-network -v /Users/[yourusername]/mysql/data/8.0:/var/lib/mysql -p 3306:3308 -d -e MYSQL_ROOT_PASSWORD=testpass
mysql:8.0
I tried to run mysql 5.6 from docker like this:
docker run --name mysqlxx -e MYSQL_ROOT_PASSWORD=xxx \
--character-set-server=utf8mb4 \
--collation-server=utf8mb4_unicode_ci \
-d mysql:5.6
but got the following error
unknown flag: --character-set-server
anyone knows what happens? is it a bug of mysql 5.6 Dockerfile?
the image is pulled from https://hub.docker.com/_/mysql
What you have written means that you pass --character-set-server and --collation-server as arguments to docker, and NOT to mysql.
As soon as these flags are related to MySQL, you have to pass them to MySQL service, not docker. Command line for container starts right after image name (mysql:5.6). That will look somehow like:
docker run --name mysqlxx -e MYSQL_ROOT_PASSWORD=xxx -d mysql:5.6 mysql --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
If you can supply them as environment, better use this approach, but you would have to prepend -e for each environment variable. Sorry, I have no idea if MySQL accepts such parameters from environment
as #grapes said, the arguments should be put after image name. below command works.
docker run --name mysqlxx -p 3336:3306 \
-e MYSQL_ROOT_PASSWORD=xxx -d mysql:5.6 \
--character-set-server=utf8mb4 \
--collation-server=utf8mb4_unicode_ci
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