I am trying to initialize mysql container within Docker by the following command:
docker run --name some-name -e MYSQL_ROOT_PASSWORD=my-password -e MYSQL_DATABASE=db-name mysql/mysql-server
It pulls the container successfully, runs everything till it reaches this line and stays there forever:
2022-02-28T09:10:03.040757Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.28' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
I tried to add this flag -h 127.0.0.1 still stops at the same line.
This is the output of docker container ls -a
70579fec1ed2 mysql "docker-entrypoint.s…" 3 hours ago Exited (1) 3 hours ago spawning-pool
This is the last line of the output of docker logs $(container-name)
2022-02-28T10:24:24.316843Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.28) MySQL Community Server - GPL.
I found the solution to be adding the flag:
-it and adding at the end /bin/bash
So finally the ending of the command looks like this:
-it -d mysql:mysql-server /bin/bash
Which will run a terminal in the background of mysql and keep it from closing.
Only I hope someone to correct me if this will cause any future errors that a bash terminal is constantly running.
Related
I followed a guide to setup docker and mysql (which i can no longer find) and everything went as expected. However i had to reinstall my OS, and now using the same commands doesn't do what i expect.
when creating a new container, then running "docker logs <container_name>", i expect to see a long string of log info, among which is a one time randomly generated password, which i can then use to change to a more memorable password.
However, i only get a short paragraph of logs with no password.
I even copied commands line-for-line from an official mysql guide that explicitly states should show me a password, but doesn't.
Strangely, i realised docker needed an update, ran the update and found that running the log command now shows the password as expect! But when i tried it again on another container, the original problem returned. I haven't been able to recreate that success since.
I feel like i'm out of options for troubleshooting.
Here is all the code i ran, from installing docker to printing the log file.
#docker setup
sudo systemctl enable docker.service #start docker on startup
sudo systemctl start docker.service #start docker now
sudo docker pull mysql/mysql-server:latest
#create volumes
sudo docker volume create mysql-config
sudo docker volume create mysql-data
#container setup
sudo docker run --name master32-mysql -dp 3306:3306 -v mysql-data:/var/lib/mysql mysql/mysql-server:latest
sudo docker logs master32-mysql
Here are the logs i get after running the last command:
[Entrypoint] MySQL Docker Image 8.0.28-1.2.7-server
[Entrypoint] Starting MySQL 8.0.28-1.2.7-server
2022-01-27T00:52:41.963514Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.28) starting as process 1
2022-01-27T00:52:41.969879Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-01-27T00:52:42.066204Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-01-27T00:52:42.219166Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-01-27T00:52:42.219204Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-01-27T00:52:42.233405Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
2022-01-27T00:52:42.233414Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.28' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server - GPL.
Can anyone figure out why this isn't showing me a password? I'm aware that this command only shows the password one time, but i'm having this problem with every new container i make.
SOLUTION:
The main problem was that i was expecting every new container to generate it's own password, whithout realising that the password is stored in the volume which is linked to the container. To get a new password, i needed to create new volumes and link the new container with that instead.
I also needed to add '-e MYSQL_RANDOM_ROOT_PASSWORD=1' to the 'docker run' command.
You haven't specified '-e MYSQL_RANDOM_ROOT_PASSWORD=1' on startup (docker run).
ref: entrypoint.
ref: docker hub docs
I'm running docker in Ubuntu and trying to create and run a MySql container. I want to use a mounted network share for the data directory. I am trying the following docker run command, but I'm having issues with permissions. How do I fix this?
root#jarvis:/mnt/wayne/mysql-data$ sudo docker run -it -p 3306:3306 -e MYSQL_ROOT_PASSWORD=admin -v /mnt/wayne/mysql:/var/lib/mysql/ --name mysqlserver mysql/mysql-server
[Entrypoint] MySQL Docker Image 8.0.20-1.1.16
[Entrypoint] Initializing database
2020-06-08T21:43:25.253898Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.20) initializing of server in progress as process 22
2020-06-08T21:43:25.281460Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-06-08T21:43:27.815075Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysqld: Cannot change permissions of the file 'ca.pem' (OS errno 1 - Operation not permitted)
2020-06-08T21:43:29.851875Z 0 [ERROR] [MY-010295] [Server] Could not set file permission for ca.pem
2020-06-08T21:43:29.852970Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2020-06-08T21:43:29.854806Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-06-08T21:43:31.947298Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.20) MySQL Community Server - GPL.
You use CIFs for network mount means the remote server is windows right? My answer is based on this assumption.
The latest mysql docker image has a user named mysql and its uid=27,gid=27
You verify this by mounting an empty folder as data_dir. You will see that the files created by mysql container has user and group is as 27.
Hence the mysql container expects files with uid/gid(owner userid and owner group id) as 27 in its data_dir. But the files that you mounted from the windows share has uid/gid which belongs to the user that executes mount command in ubuntu. This is the default behavior of mount command.
To solve this you need to pass "uid=27,gid=27" parameters to the Linux mount command.
For instance
sudo mount -t cifs -o
username=windows-username,uid=27,gid=27
//WIN_SHARE_IP/ /mnt/wayne
You can have look here for further details
I must say it is unlikely to run mysql over a network share. It won't perform well.
This is not exactly with MySQL but I hope it can give you an idea, I basically use this for testing against a MySQL database from my local environment, for this I use docker-compose and MariaDB, I configure the "data-dir" as a volume so that I can stop/start the docker container without the need to "seed" every time the database.
This is the content of the /your/path/docker-compose.yml file:
---
version: '3'
services:
mariadb:
image: mariadb:10.4.13
container_name: mariadb
restart: always
ports:
- 13306:3306
environment:
MYSQL_DATABASE: world
MYSQL_ROOT_PASSWORD: test
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
volumes:
- ${PWD}/mariadb/db/:/var/lib/mysql
In the same directory, I have the volume directory /your/path/mariadb/db
Then to bring up the container I use:
$ docker-compose up
From the docker-compose.yml has you can see I use port 13306 therefore for testing/connection I use:
$ mysql -h 127.0.0.1 -P13306 -uroot -p
All the data (databases) will be in /your/path/mariadb/db
If you run into the same "permissions" problem:
mysqld: Cannot change permissions of the file 'ca.pem' (OS errno 1 - Operation not permitted)
Try to change the permissions of your volume/mount point, for example:
chmod -R 777 /your/volume/mount_point
okay, I tried this and google also, what I found is
https://github.com/docker-library/mysql/issues/302#issuecomment-308745834
So basically if you are using mysql:5.7 then upgrade to mysql:5.7.16.
And if this doesn't help then I have one more solution.
Basically the problem is you are sharing dir to container -v /mnt/wayne/mysql:/var/lib/mysql/ but you ubuntu is not giving permission to access the /mnt/wayne/mysql dir. so give admin permission to this location or you can create a docker user chown and chmode.
Basically give permission to the host machine directory. so that docker container can access it.
and One more thing give permission to the docker container dir also, that is showing in your error
The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
Create a user in a docker container which have chown and chmod permissions to the dir /var/lib/mysql/.
if you are using dockerfile to create mysql container then use these following 2 lines in it
FROM mysql:5.7.16
WORKDIR /app
RUN chown -R admin:admin /app
RUN chmod 755 /app
USER admin
CMD ["Your command"]
To operate normally, MariaDB or MySQL needs to set some permissions on their own files. Some external file systems (such as FTP and many others) do not support these features. You need to use a file system which supports these features.
there is a permission issue to access the mounted volume. Please read the documentation about use volumes:
https://docs.docker.com/storage/volumes/#use-a-volume-driver
For NFSv3 Partition:
$ docker service create -d \
--name nfs-service \
--mount 'type=volume,source=nfsvolume,target=/app,volume-driver=local,volume-opt=type=nfs,volume-opt=device=:/var/docker-nfs,volume-opt=o=addr=10.0.0.10' \
nginx:latest
Or check the CA.pem file permissions (use chmod 777 /path/to/ca.pem)
For NFSv4 Partition:
docker service create -d \
--name nfs-service \
--mount 'type=volume,source=nfsvolume,target=/app,volume-driver=local,volume-opt=type=nfs,volume-opt=device=:/var/docker-nfs,"volume-opt=o=10.0.0.10,rw,nfsvers=4,async"' \
nginx:latest
Check https://docs.docker.com/storage/volumes/#use-a-volume-driver
I was trying to bring up my MySql in the docker container. But, it stopped with code exited(1). Here is how I run it:
docker run --name demo-db -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d mysql:latest --mount type=bind,source=$(pwd),target=/var/lib/mysql
Here is the log of the container
Initializing database
2018-10-12T17:50:42.694183Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2018-10-12T17:50:42.694277Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.12) initializing of server in progress as process 31
mbind: Operation not permitted
mbind: Operation not permitted
mbind: Operation not permitted
mbind: Operation not permitted
2018-10-12T17:51:10.497527Z 0 [ERROR] [MY-011071] [Server] unknown option '--mount'
2018-10-12T17:51:10.497543Z 0 [Warning] [MY-010952] [Server] The privilege system failed to initialize correctly. If you have upgraded your server, make sure you're executing mysql_upgrade to correct the issue.
2018-10-12T17:51:10.497551Z 0 [ERROR] [MY-010119] [Server] Aborting
2018-10-12T17:51:14.130241Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.12) MySQL Community Server - GPL.
Please help me...
Better answer may follow, I used to use Docker as well for MySQL but it's been a while.
Start as detached container:
docker run -v $PWD:/var/lib/mysql --name demo-db -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d mysql:latest
Then attach to it like so:
docker run -i -t demo-db /bin/bash
Note about pwd use:
There's no need to use the pwd command, just get the shell variable $PWD. When you do foo=$(pwd) is kind of overkill, b/c you're actually running the pwd command in a sub shell to return $PWD.
The syntax of the docker run command is basically
docker run <docker run options> IMAGE <command and arguments>
So when you run:
docker run \
--name demo-db -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -d \
mysql:latest \
--mount type=bind,source=$(pwd),target=/var/lib/mysql
The --mount option is after the image name, so it's passed as an argument to the container. Move this option before mysql:latest and you'll be set.
I cannot use MySQL anymore in my Docker container:
root#mysql-container:/# mysql -uroot -proot
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)
mysqld is running:
root#mysql-spirit-ssl:/etc/mysql/conf.d# /etc/init.d/mysql start
[info] A MySQL Server is already started.
Trying to stop mysqld timed out:
root#mysql-container:/# /etc/init.d/mysql stop
............................................................[info] Attempt to shutdown MySQL Community Server 5.7.17 timed out.
So I tried to start using the mysqladmin way:
root#mysql-container:/# /usr/bin/mysqladmin --port=8889 -u root shutdown
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)'
So I checked that MySQL daemon is running:
root#mysql-container:/# ps -eax
PID TTY STAT TIME COMMAND
1 ? Ssl 0:01 mysqld
And that socket exists:
root#mysql-container:/# ls -l /var/run/mysqld/mysqld.sock
-rwxrwxrwx. 1 mysql mysql 0 Jan 4 10:12 /var/run/mysqld/mysqld.sock
I already tried to:
restart my Docker container
comment bind address in my.cnf and restart my Docker container
kill mysqld process => does not work, process is still listed by ps -eax
recreate my Docker container
restart Docker
restart the server
delete pid and sock files, and /etc/init.d/mysql start
Result of cat /var/log/mysql/error.log:
2018-02-27T15:27:35.966028Z 0 [ERROR] InnoDB: Unable to lock ./ibdata1 error: 11
2018-02-27T15:27:35.966061Z 0 [Note] InnoDB: Check that you do not already have another mysqld process using the same InnoDB data or log files.
However I cannot kill that mysqld process, either with pkill mysqld, kill -9 1 or initctl --system stop mysql.
Could this be related to Docker?
Remark: The MySQL daemon could not be killed because it was owned by Docker user systemd+ and it was the entry point of the container. Indeed mysqld was process with PID 1. This means that MySQL daemon could be restarted by simply restarting the Docker container, and that MySQL configuration could be modified in between.
I noticed in MySQL logs tail -f /var/log/mysql/error.log that a data recovery was triggered on daemon start due to an anomaly detected during internal log scan: the database was not closed properly. However the recovery could not repair the data and an intentional crash was performed. As a consequence, the container was restarted and so on. This infinite loop prevented mysqld to start and the socket to be used by the client mysql.
1) This configuration of /etc/mysql/conf.d/my.cnf enabled to skip the recovery:
[mysqld]
innodb_force_recovery=4
and to use mysql client with socket to dump important schemas and/or delete corrupted schemas.
Do not forget to remove this line from my.cnf after you're done!
2) Perfoming a mysql upgrade and repair could also have been beneficial:
docker exec -it mysql-container mysql_upgrade -u root -p --force
mysqlcheck -u root -p --auto-repair --check --all-databases
Restarting the Docker container is necessary after this step.
3) Also, deleting MySQL internal logs (that were scanned and triggered the recovery) was necessary:
cd /var/lib/mysql/mysql/
rm ibdata1 ib_logfile0 ib_logfile1
Now I can use MySQL again, from inside and outside the container.
I have been doing volume mounting with this image for weeks now without an issue. Suddenly now, if I try to mount a volume, ANY volume, the container prints some basic startup logs and exits.
The app itself give no indication of error so this appear to be docker itself squashing things.
This is what I have:
Docker Version (native on mac):
$ docker -v
Docker version 17.09.0-ce, build afdb6d4
local directory:
$ ls
1 Dockerfile README.md Schema dba_utilities docker-compose.yml docs
Fireup a MYSQL container:
$ docker run -d -v $PWD/Schema:/root:ro -v $PWD/dba_utilities:/tmp:ro -e MYSQL_ROOT_PASSWORD=my-secret-pw mysql:5.6
aa213c8cb28ea2f75e3064b296db6e5e450466cc45e60a7de3f21a2ca98987f4
Now prove it's dead:
$ docker ps -a | head -3
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
aa213c8cb28e mysql:5.6 "docker-entrypoint..." 23 seconds ago Exited (141) 21 seconds ago inspiring_curie
cc43d27b29cf mysql:5.6 "docker-entrypoint..." 4 minutes ago Exited (141) 4 minutes ago laughing_shaw
Now show container logs:
$ docker logs aa213c8cb28ea2f75e3064b296db6e5e450466cc45e60a7de3f21a2ca98987f4
Initializing database
2017-10-02 18:31:00 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-10-02 18:31:00 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-10-02 18:31:00 0 [Note] /usr/sbin/mysqld (mysqld 5.6.37) starting as process 36 ...
But, if I try to bring up a shell from that same image with those same volumes all looks good:
$ docker run -it -v $PWD/Schema:/root:ro -v $PWD/dba_utilities:/tmp:ro -e MYSQL_ROOT_PASSWORD=my-secret-pw mysql:5.6 /bin/bash
root#898fe2f883a2:/# cd
root#898fe2f883a2:~# ls
README.md db1 db2
root#898fe2f883a2:~# ls /tmp
README.md apply.sh dump_all.sh pullschema.sh schemata.txt
root#898fe2f883a2:~# pwd
/root
root#898fe2f883a2:~# exit
Now, if I remove the volume mounts:
$ docker run -d -e MYSQL_ROOT_PASSWORD=my-secret-pw mysql:5.6
98b51f96fe482cfd0453a0eb4ff8b9d1f2729244ad2316e245680ce4976a200d
and check the status:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
98b51f96fe48 mysql:5.6 "docker-entrypoint..." 4 seconds ago Up 3 seconds 3306/tcp nervous_mcnulty
It's running. Verifying from logs:
docker logs 98b51f96fe482cfd0453a0eb4ff8b9d1f2729244ad2316e245680ce4976a200d
Initializing database
2017-10-02 18:36:48 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-10-02 18:36:48 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-10-02 18:36:48 0 [Note] /usr/sbin/mysqld (mysqld 5.6.37) starting as process 36 ...
2017-10-02 18:36:53 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-10-02 18:36:53 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2017-10-02 18:36:53 0 [Note] /usr/sbin/mysqld (mysqld 5.6.37) starting as process 59 ...
Database initialized
MySQL init process in progress...
2017-10-02 18:36:56 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-10-02 18:36:56 0 [Note] mysqld (mysqld 5.6.37) starting as process 87 ...
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
MySQL init process done. Ready for start up.
2017-10-02 18:36:59 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-10-02 18:36:59 0 [Note] mysqld (mysqld 5.6.37) starting as process 1 ...
In the past, even when there is an issue with the volume mounts it either errors immediately or I get no mount but not this.
I have also tried this on an ubuntu 14.04 VM with the same results
The solution here is to remove the read-only flag from mount and the env variable addressing, it worked for me and I was able to reproduce your error on Docker version 17.06.1-ce, build 874a737 so it looks like a wider issue, I tried omitting both env variable usage and :ro flag and none worked, only not using both worked here
docker run -d -v Schema:/root -v dba_utils:/tmp -e MYSQL_ROOT_PASSWORD=my-secret-pw mysql:5.6