Some docker containers come configured with an EXPOSE option that automatically, but for the MySQL Docker container you need to bind it yourself. If you are planning on running multiple MySQL containers at the same time, then you will need to given them different ports, for example -p 3307:3306 on one, -p 3308:3306 on another. By mapping 3306 on your machine to 3306 inside the container, your MySQL server will appear the same way it would if you were running the service normally. p maps a port from the host (your machine) to the docker container. e MYSQL_DATABASE creates this default database, when you create a user it is given superuser privileges to this database automatically. When creating a user, you must specify a password for it and one of the three “root” password options. e MYSQL_USER=my_user_name and -e MYSQL_PASSWORD=somethingSecret. If you would like to create a user, you can use: If you would rather connect to root with a password, you can specify the password to use with -e MYSQL_ROOT_PASSWORD=rootSecret If you are planning on creating and connecting as a different user as outlined next, but want to leave the root user secure you could use -e MYSQL_RANDOM_ROOT_PASSWORD=true e MSQL_ALLOW_EMPTY_PASSWORD=true allows you to connect as root and no password. e is the option to pass in an env variable into the container, you can use it multiple times if you need to pass several environment vars. It is optional, and each container is assign an id which you can find from docker ps so you could use docker stop container_id but obviously it is easier to set a name that makes sense for you. name name is the name you use in commands like docker stopdocker stop and docker start to interact with a specific container. Docker run \ -name mysql_demo \ -e MYSQL_ALLOW_EMPTY_PASSWORD= true \ -e MYSQL_DATABASE=mysql_demo \ -p 3306 :3306 \ -d mysql
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |