Skip to content

Instantly share code, notes, and snippets.

@geerlingguy
Created March 15, 2020 01:54
Show Gist options
  • Save geerlingguy/3dabf0ec3befb8c49bbed0ec7cd3d44c to your computer and use it in GitHub Desktop.
Save geerlingguy/3dabf0ec3befb8c49bbed0ec7cd3d44c to your computer and use it in GitHub Desktop.

Revisions

  1. geerlingguy created this gist Mar 15, 2020.
    40 changes: 40 additions & 0 deletions docker-compose-test.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    # 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/