如何调试REDIS,APACHE发出Docker容器? [英] How to DEBUG REDIS, APACHE issues a Docker container?

查看:80
本文介绍了如何调试REDIS,APACHE发出Docker容器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是场景:

容器来自使用以下Dockerfile创建的映像:

The container comes from an image created with the follow Dockerfile:

FROM php:5-apache


RUN apachectl -M
RUN a2enmod rewrite
RUN a2enmod expires
RUN service apache2 restart
RUN apachectl -M

RUN php -m
RUN apt-get update
RUN php -m
RUN apt-get install -y php5-redis
RUN apt-get install -y redis-server
#RUN redis-server
RUN cp /etc/php5/mods-available/redis.ini /usr/local/etc/php/conf.d && ln -s /usr/lib/php5/20131226/redis.so /usr/local/lib/php/extensions/no-debug-non-zts-20131226/redis.so
RUN php -m



COPY src/ /var/www/html
EXPOSE 80

#CMD ["redis-server"]

请注意最后一行CMD ["redis-server"].

构建图像后,我像这样创建容器

After the image is built, I create the container like this

docker run -p 80:80 my_img

如果图像是使用浏览器(0.0.0.0:80)中的#CMD ["redis-server"]构建的,则会收到一条错误消息(来自我的index.php文件)"Could not connetc to REDIS".可能是因为REDIS未初始化.

If the image is built with #CMD ["redis-server"] in the browser (0.0.0.0:80) I get an error message (that comes from my index.php file) "Could not connetc to REDIS". Maybe it is because REDIS was not initialized.

如果图像是使用CMD ["redis-server"]构建的,并且初始化了REDIS(我可以在docker终端中看到REDIS符号),但是在浏览器中收到错误消息:

If the image is build with CMD ["redis-server"] and that initializes REDIS (I can see the REDIS symbol in the docker terminal) but I get an error message in the browser:

所以,我不知道发生了什么.我是Docker的新手,不知道如何调试它.它可能与端口冲突(REDISxApache)有关,也可能与REDIS本身有关.或那不是我应该初始化REDIS的方式.

So, I have no clues what is happening. I am new in Docker and have no idea how to debug it. It can be something related to the port conflicts (REDISxApache) or maybe the REDIS itself. Or that is not the way I should initialize REDIS.

有什么帮助吗?

推荐答案

您不能在同一容器中运行依赖服务.您将它们作为compose的一部分运行

You don't run dependent services in the same container. You run them as a part of compose

docker-compose.yml

version: '3'
services:
  php:
    build: 
      context: .
    ports:
      - "80:80"
  redis:
    image: redis

您将使用

$ docker-compose up 

您将必须在PHP代码内连接到地址为redis:6379的redis,而不是使用127.0.0.1:6379 有关docker compose的更多详细信息,请参考 https://docs.docker.com/compose/

You will have to connect to redis at address redis:6379 inside your php code instead of using 127.0.0.1:6379 For more details on docker compose refer to https://docs.docker.com/compose/

这篇关于如何调试REDIS,APACHE发出Docker容器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆