![]() In order to use a password to connect to MySQL as user, you will need to switch its authentication method from auth_socket to mysql_native_password.Ĭreate a dedicated mysql user for wordpress database in legacy mysql_native_password mode. This allows for some greater security and usability in many cases, but it can also complicate things when you need to allow an external incompatible program like wordpress to access the user. In Ubuntu systems running MySQL 5.7 (and later versions), any MySQL user is set to authenticate using the auth_socket plugin by default rather than with a password. The only caveat is wordpress can't connect with MySQL with default setup. You can very easily connect to MySQL running in host machine with wordpress running inside container by providing -network=host option during docker run. The accepted answer is incomplete and inaccurate. You can change the mapping of the mysql datafiles to a local directory instead, and just ommit the docker volume create statement. The same can be achieved with just docker run, like this: docker volume create db_dataĭocker run -name test-mysql -e MYSQL_ROOT_PASSWORD=somewordpress -e MYSQL_DATABASE=wordpress -e MYSQL_USER=wordpress -e MYSQL_PASSWORD=wordpress -v db_data:/var/lib/mysql -net=mysqlnet -d mysql:5.7ĭocker run -name test-wordpress -e WORDPRESS_DB_HOST=test-mysql:3306 -e WORDPRESS_DB_USER=wordpress -e WORDPRESS_DB_PASSWORD=wordpress -e WORDPRESS_DB_NAME=wordpress -net=mysqlnet -p 8081:80 -d wordpress:latest Then visit: Notice that the database data will be stored in the docker managed volume called db_data.ĭetails on installing docker-compose can be found here: Start both containers with just docker run ![]() You can create a docker-compose.yml file like this:Īnd the start the stack with this: docker-compose up The better alternative here though, is to create an application stack definition with docker-compose, that includes both the database and the wordpress application. You can then: docker run -name test-wordpress -net=dockernet -p 8081:80 -d wordpressĪnd you should then be able to refer to the host from inside the container by the IP: 192.168.0.1. Assuming that your local machine has a fixed IP of 192.168.0.1, you should be able to do this with: docker network create -d bridge -subnet 192.168.0.0/24 -gateway 192.168.0.1 dockernet If you really want to connect the service in the container with a service on the host, you will need to connect the container to the appropriate network.įirst, you will need to create a network. This way your containers can address eachother without issues. The easy was to solve this, is to wrap the MySQL database in a container of it's own. This means that addresses such as: localhost and 127.0.0.1 only refers to the container itself. By default, docker will attach your new container to a bridged network.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |