You need to create users when startig your database in your docker image. # otherwise our database would not be reachable from outside the container) (replace " boot2docker-vm" by the name of your vm: see docker-machine ls)Īs illustrated in nkratzke/EasyMySQL/Dockerfile, you need to enable remote access: # Enable remote access (default is localhost only, we change this ( controlvm if the VM is running, modifyvm is the VM is stopped) If you need to use localhost, you would need to do some port forwarding at the VirtualBox level: VBoxManage controlvm "boot2docker-vm" natpf1 "tcp-port3306,tcp,3306,3306" Second, if you are using docker in a VM (docker-machine, with boot2docker), you need to use the ip of docker-machine ip, with the host mapped port. (for instance: docker run -d -p 3306:3306 tutum/mysql) You should now be able to connect to your mysql container.įirst, your docker run must map the mysql port to an host port: docker run -p host:container Use MYSQL_PASSWORD as specified in your docker-compose.yml file. In your MySQL Workbench provide the connection details. Grant all privileges on *.* to with grant option Execute following commands to create new user. Use MYSQL_ROOT_PASSWORD as specified in the docker-compose.yml. Inside the container, to connect to mysql command line type, mysql -u root -p Restart docker container and run following commands to get to the bash shell in the mysql container docker ps I have following mysql block under services object in my docker-compose.yml file. Specify mysql configuration block in your docker-compose.yml. You have to do few configuration in you docker container. Now you will be able to connect from MySQL Workbench to host: `0.0.0.0`Īfter all the changes the query will show: select host, user from er Update er set host = '%' where user='root' If this is a fresh installation you will be asked to change the password using ALTER USER command. If this is the fresh installation - grab the default password:ĭocker logs mysql57 2>&1 | grep GENERATEDĬonnect using mysql client directly to the mysqld in docker: Or, if the complete port mapping is required: docker run -p 3306:3306 -p 33060:33060 -name=mysql57 -d mysql/mysql-server:5.7 Start your mysql image with all port mappings required:ĭocker run -p 3306:3306 -name=mysql57 -d mysql/mysql-server:5.7 If you need to change that to allow root to connect from any host (say, for development purposes), do the following: By default after deployment MySQL has following connection restrictions: mysql> select host, user from er Īpparently, for security purposes, you will not be able to connect to it from outside of the docker container.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |