Skip to content

Instantly share code, notes, and snippets.

@khusseini
Last active March 18, 2022 03:28
Show Gist options
  • Save khusseini/508c887e916d67f64166609cdfe7abda to your computer and use it in GitHub Desktop.
Save khusseini/508c887e916d67f64166609cdfe7abda to your computer and use it in GitHub Desktop.
Update your #hosts file to point to #docker #container #ip
Update your hosts file to point to docker container ip
MAKEFLAGS += --warn-undefined-variables
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
.SUFFIXES:
##Option: Development domain
domain = mysite.development.local
container = mysite
define container_ip
docker inspect \
--format '{{ .NetworkSettings.Networks.haneudevelopment_orocommerce.IPAddress }}' \
$$(docker ps | grep $(container) | awk '{print $$1}')
endef
.PHONY: host
host:
# Updating /etc/hosts file
@grep -q '$(strip $(domain))' /etc/hosts \
&& sudo sed \
-i 's/^.* $(strip $(domain))//' \
/etc/hosts; \
echo "$$($(container_ip)) $(strip $(domain))" | sudo tee --append /etc/hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment