PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 1, 2022

[FIXED] How to map a virtual host to a container in docker?

 March 01, 2022     docker, docker-compose, lamp, nginx     No comments   

Issue

I am trying to setup a LEMP local development environment using Docker. Following is my docker-composer.yml:

version: '2'
services:
  apache:
    build:
      context: ./docker/apache-php7
      dockerfile: Dockerfile
    image: foo/apache-php7
    volumes:
      - .:/var/www/html
    ports:
      - "80:80"
      - "443:443"
    networks:
     - localnet
  node:
    build:
      context: ./docker/node
      dockerfile: Dockerfile
    image: foo/node
    volumes:
     - .:/var/www/html
    networks:
     - localnet
  mysql:
    image: mysql:5.7
    ports:
     - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: "root"
      MYSQL_DATABASE: "root"
      MYSQL_USER: "root"
      MYSQL_PASSWORD: "root"
    volumes:
     - mysqldata:/var/lib/mysql
    networks:
     - localnet
  redis:
    image: redis:alpine
    volumes:
     - redisdata:/data
    networks:
     - localnet
networks:
  localnet:
    driver: "bridge"
volumes:
  mysqldata:
    driver: "local"
  redisdata:
    driver: "local"

I can access the site by going to http://localhost. Instead of accessing the project using http://localhost, I am trying to map it to http://foo.dev but for the life of me I just can't figure out how I can achieve that? One example I have seen is this but it's using a different image and it is also using nginx.


Solution

I am assuming that the foo/apache-php7 image is forked from nimmis/apache-php7, which is based on Ubuntu 16.04, so by default your Apache will answer the same way to HTTP requests, irrespective of host name. So, the only thing you need to do is to set up A/AAAA records in the foo.dev DNS zone pointing at your server.

It looks like the zone needs some attention in any case:

% host foo.dev
foo.dev has address 127.0.53.53
foo.dev mail is handled by 10 your-dns-needs-immediate-attention.dev.

The address record points to a localhost address, which won't work until you're actually on the same host. You'll need a globally routed IP address there.



Answered By - Gerd Flaig
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing