Created
March 15, 2020 01:54
-
-
Save geerlingguy/3dabf0ec3befb8c49bbed0ec7cd3d44c to your computer and use it in GitHub Desktop.
Docker Compose exposed port test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create test VM with Vagrant. | |
mkdir testvm && cd testvm | |
vagrant init geerlingguy/ubuntu1804 | |
# (Edit created Vagrantfile and uncomment `config.vm.network "private_network"` line) | |
# Start the VM and log in. | |
vagrant up | |
vagrant ssh | |
# Flush iptables rules (allow access to any port). | |
sudo iptables -F | |
# Install Docker and Docker Compose. | |
sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | |
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | |
sudo apt-get update | |
sudo apt-get -y install docker-ce | |
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose | |
sudo chmod +x /usr/local/bin/docker-compose | |
# Run a container with an exposed port with a Docker Compose file. | |
nano docker-compose.yml | |
# Contents of docker-compose.yml: | |
version: "3.7" | |
services: | |
http: | |
image: tutum/hello-world | |
ports: | |
- "127.0.0.1:80:80" | |
# Start the Docker Compose environment. | |
sudo docker-compose up -d | |
# Test inside the VM (should return a 200 OK) | |
curl --head http://localhost/ | |
# Test outside the VM (should _not_ respond) | |
curl --head http://192.168.33.10/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment