1

I have a wordpress app in a container that needs to access a localhost webapp setup with self signed cert. I've tried using extra_hosts (both with 127.0.0.1 & 10.0.2.2) in my docker compose file without much success. Any help with this is greatly appreciated.

version: '3.3'

services:
  wordpress:
    image: mywordpress:latest
    container_name: mywordpress
    networks:
      - db-net
    links:
      - mysql
    ports:
      - "8088:80"
    restart: always
    volumes:
      - wp_data:/var/www/html
    depends_on:
      - mysql
    extra_hosts:
      localhost: 10.0.2.2
    environment:
      WORDPRESS_DB_HOST: mysql:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress

  mysql:
    image: mysql:latest
    container_name: mysql
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    networks:
      - db-net
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress

networks:
  db-net:
    driver: bridge

volumes:
  db_data:
  wp_data:

EDIT The wordpress application in the container needs to access an API hosted locally on the actual host machine (this is the app with the self signed cert)

CraigM
  • 561
  • 8
  • 20
  • Where did you configured SSL certificates ? inside mywordpress container ? – Nuwan Attanayake Jul 23 '18 at 05:07
  • What do you mean with localhost? The host running the docker container? – Henry Jul 23 '18 at 05:24
  • Yes, sorry, I wasn't clear in my explanation. So the wordpress app in the docker container needs to access a web api hosted locally on the actual host (configured with self signed cert) – CraigM Jul 23 '18 at 05:26
  • see https://stackoverflow.com/a/47663730/3788261 – ShrimpPhaser Jul 23 '18 at 07:26
  • Possible duplicate of [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) – David Maze Jul 23 '18 at 10:22

1 Answers1

0

localhost and 127.0.0.1 used inside the container are both referring to the container itself. To refer to the host machine use another IP address (or name) of it.

Henry
  • 42,982
  • 7
  • 68
  • 84