randall
randall

Reputation: 173

How can I separate wordpress in backend & frontend with docker container?

I've created two containers for this using the following commands:

docker run --detach --name=test-mysql --env="MYSQL_ROOT_PASSWORD=mypassword" mysql

and, with the command docker inspect test-mysql I can see the containers IP address "IPAddress": "172.17.0.20",

After that, I'm trying to connect it with mysql but I get this error:

can't connect to MySQL server on '172.17.0.20' (60) 

but if I do: "docker exec -it test-mysql bash" I can connect it.

If I want to connect a front end for a wordpress to this mysql container, how should I do it?

I tried with docker run --detach --name test-wordpress --link test-mysql:mysql wordpress but is not working and I have nothing in localhost:80 enter image description here

Upvotes: 3

Views: 526

Answers (1)

OscarAkaElvis
OscarAkaElvis

Reputation: 5724

You must expose the ports using -p on docker run command. You can map ports from your container to be accessed from your host:

docker run --detach -p 3306:3306 --name=test-mysql --env="MYSQL_ROOT_PASSWORD=mypassword" mysql

The same for wordpress using -p 80:80

Upvotes: 3

Related Questions