0

I have compose file as follows;

redis:
    image: redis
    ports:
    - "6379:6379"
 php:
    build: .
    image: php:fpm
    volumes:
    - ./code:/var/www/html
    links:
      - redis:redis
    networks:
    - code-network

I'm entering into php container with the following command.

docker exec -it php_id /bin/bash

but I can't run "redis-cli" command in this container. What do I need to do to run it.

I added "links" parameter to compose file but it didn't.

Spartan Troy
  • 949
  • 2
  • 9
  • 13
  • could you remove the `networks` part from the compose file, attach to the php-container, run `apt update -yq && apt install -yq iputils-ping` and try `ping redis`? – joppich Oct 09 '18 at 13:34
  • I didn't understand what you said.So when I enter into php container I want to run redis-cli, so I don't want to come out and enter into redis container again. – Spartan Troy Oct 09 '18 at 13:42
  • could you post the output of `docker-compose --version`, please? and is that really your entire compose file? Also, the contents of your `Dockerfile` would be helpful. – joppich Oct 09 '18 at 13:51
  • docker-compose version 1.22.0, build f46880fe – Spartan Troy Oct 09 '18 at 13:53
  • Did you add some args for redis_cli when you execute it? Such as specifying redis server? – Light.G Oct 09 '18 at 13:54

1 Answers1

0

You are putting the php-fpm container in a network of its own. Here is a fixed compose file:

version: "3"
services:
  redis:
    image: redis
    ports:
      - "6379:6379"

  php:
    build: .
    image: php:fpm
    volumes:
      - ./code:/var/www/html
    networks:
      - code-network
      - default

networks:
  code-network:

See this for more info on compose networking.

About the redis-cli issue: You'd need to add the appropriate repository on the php-fpm container and then install it. As you are using the php:fpm image, you propably want to use redis with some php-application, therefore you don't need debians redis-cli package, but rather the php-extension. See this post for more info.

joppich
  • 681
  • 9
  • 20