简体   繁体   English

在Docker容器中使用Redis和mysql

[英]Using Redis and mysql with docker container

My web application needs both mysql and redis server to function properly. 我的Web应用程序同时需要mysql和redis服务器才能正常运行。 I am able to link mysql container with app using link tag (mysql is name of mysql image set using -name tag) 我能够使用链接标记将mysql容器与应用程序链接(mysql是使用-name标记设置的mysql映像的名称)

sudo docker run -link mysql:amq -d -p 13310 hitesh/image node app

Now I am not sure how to attach redis to this container. 现在我不确定如何将Redis附加到此容器。 Should it be done via same mysql image (if yes, how two ports ie 3306 & 6379 will be exposed?) or should I make another container for redis and link it to my node.js app (not sure about it is possible or not). 应该通过相同的mysql映像完成(如果是,如何暴露两个端口,即3306和6379?),还是应该为redis创建另一个容器并将其链接到我的node.js应用程序(不确定是否可以) )。

You should have 3 containers 你应该有3个容器

  1. your app 您的应用
  2. your mysql 你的mysql
  3. your redis 您的重做

then expose your mysql port and redis port on the relevant containers. 然后在相关容器上公开您的mysql端口和redis端口。

Then when you run your app container just link both mysql and redis containers to your app 然后,当您运行应用程序容器时,只需将mysql和redis容器都链接到您的应用程序

so something like 所以像

sudo docker run -d -link mysql:mysql -link redis:redis ....

Now your app container will have environment variables for your other two databases 现在,您的应用程序容器将具有其他两个数据库的环境变量

Also, if you want to expose two ports, then in your dockerfile just do EXPOSE port1 port2 另外,如果要公开两个端口,则在dockerfile中只需执行EXPOSE port1 port2

eg EXPOSE 22 80 例如EXPOSE 22 80

Then you'll get environment variables for both exposed ports. 然后,您将获得两个暴露端口的环境变量。 But i'd recommend you don't have a container that runs both mysql and redis. 但我建议您不要同时运行mysql和redis的容器。 Separate your concerns :) 分开您的担心:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM