Skip to content

Instantly share code, notes, and snippets.

@ajkovar
Last active July 9, 2020 19:46
Show Gist options
  • Select an option

  • Save ajkovar/167125e9030ec42a0ef4817d8934dce7 to your computer and use it in GitHub Desktop.

Select an option

Save ajkovar/167125e9030ec42a0ef4817d8934dce7 to your computer and use it in GitHub Desktop.
docker-machine create default
# this I think not needed because it was started on create?:
# docker-machine start default
eval $(docker-machine env default)
# create/start docker containers based on docker-compose config files
docker-compose up
# list docker docker-machines (houses the containers)
# on mac it can be a VirtualBox virtual machine, more info here:
# https://docs.docker.com/docker-for-mac/docker-toolbox/
docker-machine ls
# list of containers
docker ps
# open shell in docker container
docker exec -it <container_id> /bin/sh
# open root shell in docker container
docker exec -u 0 -it mycontainer bash
# view open ports inside container
netstat -tulpn | grep LISTEN
# # view open ports from host OS
netstat -an | grep LISTEN
################
# this is all to try to debug issue with not being able to site hosted inside docker
# Problem is that OSX not listening on port.. similar issue here:
# https://github.com/docker/for-mac/issues/3350
###############
# Finally was able to resolve this by using the correct IP address from the host OS
# instead of using localhost, it was necessary to use the IP returned by
# the `docker-machine env default` command.
# command for forwarding local port into virtualbox (needed if you want to access services inside
# virtualbox using 'localhost' for example)
# https://www.virtualbox.org/manual/UserManual.html#natforward
VBoxManage modifyvm "VM name" --natpf1 "guestssh,tcp,,2222,,22"
# and then to remove it:
VBoxManage modifyvm "VM name" --natpf1 delete "guestssh"
#Connecting out to host from guest:
In host:
python -m SimpleHTTPServer 8001
Next
curl 192.168.99.1:8001
From inside guest (get IP from 'File > Network administrator' in virtual box)
# install package on guest:
apt update
apt install <package>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment