Docker Community Forums

Share and learn in the Docker community.

Can't build a proper ssh into my php container

I want connect directly into a php container using the normal ssh command for a tool I have that I need to use for my local dev.

With some refrence from github I could build this long docker-compose file. I built and ssh container and everything is good but of course I couldn’t run the php command in it becuase it is contained in another container for this whole. So, how I can overcome this problem? How can I combine maybe two containers?? or expose the php command to another container or so?

This is my fill docker-compose file:

version: '3'

networks:
  laravel:


services:
  nginx:
    image: nginx:stable-alpine
    container_name: test_laravel_nginx
    ports:
      - "10000:80"
    volumes:
      - ./src:/var/www/html
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - php
      - mysql
    networks:
      - laravel

  mysql:
    image: mysql:5.7.29
    container_name: test_laravel_mysql
    restart: unless-stopped
    tty: true
    ports:
      - "4306:3306"
    volumes:
      - ./mysql:/var/lib/mysql
    environment:
      MYSQL_DATABASE: testing_laravel_db
      MYSQL_USER: testing_laravel_use
      MYSQL_PASSWORD: password
      MYSQL_ROOT_PASSWORD: password
      SERVICE_TAGS: dev
      SERVICE_NAME: mysql
    networks:
      - laravel
  php:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: test_laravel_php
    volumes:
      - ./src:/var/www/html
    ports:
      -  "9005:9000"
    networks:
      - laravel
  composer:
    image: composer:latest
    container_name: composer
    volumes:
      - ./src:/var/www/html
    working_dir: /var/www/html
    depends_on:
      - php
    networks:
      - laravel

  npm:
    image: node:13.7
    container_name: npm
    volumes:
      - ./src:/var/www/html
    working_dir: /var/www/html
    entrypoint: ['npm']

  artisan:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: artisan
    volumes:
      - ./src:/var/www/html
    depends_on:
      - php
    working_dir: /var/www/html
    entrypoint: ['php', '/var/www/html/artisan']
    networks:
      - laravel
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    restart: always
    container_name: phpmyadmin
    depends_on:
      - mysql
    ports:
    - "10001:80"
    environment:
      PMA_HOST: mysql
      MYSQL_ROOT_PASSWORD: password
    networks:
      - laravel
  connector:
    image: abobija/ssh
    container_name: connector
    depends_on:
      - nginx
    ports:
      - "2222:22"
    restart: unless-stopped
    volumes:
      - ./src:/var/www/html
    working_dir: /var/www/html
    tty: true
    links:
      - php
    networks:
      - laravel

Thanks in advance for your help. :slight_smile: