Docker : find sendmail in other container

2019-07-17 05:34发布

问题:

I'm learning how to use Docker with multiple containers, as opposed to a single one.

I'd like to learn how to call, from container A, a program located on container B.

(i.e.: I want to be able to call sendmail from my web container, while sendmail and similar programs are located on a mailhog container.)

I have this:

docker-compose.yml

web:
  container_name: centosweb
  image: fab/centosweb
  ports:
    - "80:80"
  volumes:
    # Single files
    - ./config/httpd.conf:/etc/httpd/conf/httpd.conf
    # Directories
    - ./vhosts:/var/www/html
    - /Users/fabien/Dropbox/AppData/XAMPP/web/bilingueanglais/public_html:/var/www/html/bilingueanglais
    - ./logs/apache:/etc/httpd/logs # This will include access_log(s) and error_log(s), including PHP errors.
  links:
    - db:3306
    - mailhog:1025
db:
  container_name: centosdb
  image: fab/centosdb
  hostname: db
  volumes:
    # Single files
    - ./config/my.cnf:/etc/my.cnf
    # Directories
    - ./mysqldata:/var/lib/mysql
    - ./logs/mysql:/var/log/mysql
mailhog:
  image: mailhog/mailhog
  hostname: mailhog
  ports:
      - 1025:1025
      - 8025:8025

However, right now, web cannot find /usr/sbin/sendmail since it's located on the mailhog container. Trying to use a mail function from PHP produces a Could not instantiate mail function error.

How can I link the two?

回答1:

The containers need to be in the same network, that was my problem.