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
Related
I'm trying to create a container using a volume that I have already created, but my console shows the error
docker container run" requires at least 1 argument
This is the command I'm trying to run:
docker container run --name db -v volume-dados-do-banco:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=Mypass
I have also tried this one, wih more arguments, but the same error persists:
docker container run -d --name db -p 3306:3306 -e 'ACCEPT_EULA=Y' -e MYSQL_ROOT_PASSWORD=Mypass -v volume-dados-do-banco:/var/lib/mysql
Any thoughts on the reason why this is happening?
Problem is not with docker, you just didn't specify which image to run. Your command should include Docker image as per documentation.
docker run [OPTIONS] IMAGE[:TAG|#DIGEST] [COMMAND] [ARG...]
Example would be:
docker run -d --name db -v volume-dados-do-banco:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=Mypass mysql:latest
i just had the same problem with psql my password simply contained & and i needed to escape it with / before &
try the below command.. it seems a syntax error on your command..
docker container run -d --name db -v volume-dados-do-banco:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=Mypass
i have the same problem when i use this:
docker run -d -p 3306:3306 -v /Volumes/wd4black/mysql -e MYSQL_ROOT_PASSWORD=root mysql
but when i try below, the problem is disappear:
docker run --name my-s -d -p 3306:3306 -v /Volumes/wd4black/mysql -e MYSQL_ROOT_PASSWORD=root mysql
so i think the --name is key, but the doc didn/t write it.
I just restarted docker and ran:
docker run --name torgmysqldb --volumes-from volume-dados-banco-mysql -e MYSQL_ROOT_PASSWORD=Mypass -p 3307:3306 mysql
I found out a known issue about this:
https://github.com/docker/for-win/issues/2722
After you have extracted the image from the Docker repository, you can move on to deploying the new Container with the following code snippet:
sudo docker run --name=[container_name] -d [image_tag_name]
Hello i have created mysql image and with this command
docker run --name db-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest --> Run container with my sql
docker pull mysql --> create image with mysql
docker run --name db_mysql-e MYSQL_ROOT_PASSWORD=1234 -e MYSQL_DATABASE=mami -p 3306:3306 -d mysql
i execute it but after that i don't know what to do and how to make a DB in this container and the job for the backup
If someone can help me with step by step what to do
You could use the cron service from your host system to run the following command as described in the documentation for the mysql docker image:
crontab example for running the command every night at 2:00 am:
00 02 * * * /usr/bin/docker exec db-mysql sh -c 'exec mysqldump --all-databases -uroot -p"my-secret-pw"' > /some/path/on/your/host/all-databases.sql
Alternatively you could run another container designed just for this task such as deitch/mysql-backup:
docker run --name db-mysql -d \
-e MYSQL_ROOT_PASSWORD=my-secret-pw \
-e MYSQL_USER=my-user \
-e MYSQL_PASSWORD=my-user-password \
-e MYSQL_DATABASE=my-db \
mysql:latest
docker run -d --restart=always \
--name=db-backup \
-e DB_DUMP_BEGIN=0200 \
-e DB_SERVER=db-mysql \
-e DB_USER=my-user \
-e DB_PASS=my-user-password \
-e DB_NAMES=my-db \
-e DB_DUMP_TARGET=/db \
-v /somewhere/on/your/host/:/db \
databack/mysql-backup
You also need to make sure the /somewhere/on/your/host/ folder is writable by users of group 1005:
sudo chgrp 1005 /somewhere/on/your/host/
sudo chmod g+rwX /somewhere/on/your/host/
But this container must have a mean to connect to your db-mysql container. For that you create a docker network and connect both containers to it:
docker network create mysql-backup-net
docker network connect mysql-backup-net db-backup
docker network connect mysql-backup-net db-mysql
Is it possible to have several flume's agents (sinks) under the same configuration file (agent.conf)?
I think so. It is a matter of include all the per-sinks configuration in the same agent.conf file. There is an example here.
The preferred way for FIWARE is using Dockers. So, let's imagine we need a Cygnus and we want the data to be "sinked" to MongoDB and MySQL.
A good practice would consist of making a Docker-compose file in order to build the application, but in this case, I'll show how to deploy all dockers needed separately.
We want to deploy a MySQL so Cygnus can store data in it. We can do it this way:
sudo docker run --name mysql_showcases \
-e MYSQL_ROOT_PASSWORD=root \
-e MYSQL_DATABASE=dbcygnus \
-e MYSQL_USER=cygnus \
-e MYSQL_PASSWORD=cygnus \
-e MYSQL_ROOT_HOST='%' \
-p 3306:3306 -it -v /data/mysql:/var/lib/mysql -d -h mysql mysql/mysql-server:5.5
We want to deploy a MongoDB so Cygnus can also store data in it. We can do it this way:
sudo docker run --name mongo_showcases -v /data/mongodb:/data/db -d \
-h mongo mongo:3.6
Finally, we can deploy Cygnus using a Docker linked with both previous dockers:
docker run -d --name cygnus_showcases --link mysql_showcases --link mongo_showcases \
-p 8081:8081 -p 5050:5050 \
-e CYGNUS_MYSQL_HOST=mysql_showcases -e CYGNUS_MYSQL_PORT=3306 \
-e CYGNUS_MYSQL_USER=root -e CYGNUS_MYSQL_PASS=root \
-e CYGNUS_MONGO_HOSTS=mongo_showcases:27017 \
fiware/cygnus-ngsi
So, we've deployed a Docker, using Cygnus which will store data in a MongoDB and a MySQL database. We can also provide more "variables" to configure other sinks to where to store data in.
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
I’m setting up a container on Bluemix using ice from the command line, but every time I try to attach a volume to a container it simply doesn’t work. The mounted folder isn't created in the root directory.
My command is:
ice create -p 80 -p 22 --name test --memory 1024 --volume notebooks:/notebooks registry.ng.bluemix.net/repository/app:latest
Docker gives you the option to create the volume yourself or allow Docker to create it for you. Either one of these will work:
docker run --name mysql_test -v /etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d jw_mysql:latest
OR
docker run --name mysql_test -v /my/custom:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d jw_mysql:latest
For IBM Containers, the situation is different: you need to create a volume before you can use it. So only this will work:
cf ic volume create dbstorage
cf ic run -p 3306 --name cf_mysql_test -v dbstorage:/etc/mysql/config/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d registry.ng.bluemix.net/jw_image_reg/jw_mysql:latest
(Assuming you want to use port 3306.)