Skip to content

Use Vagrant to provision a Alpine Linux Virtual inside Oracle Virtual Box, Install Docker in Alpine Linux, Create a docker image with Nginx and Serve a test page

Notifications You must be signed in to change notification settings

vmendis/VagrantAlpineApacheDocker

Repository files navigation

VagrantAlpineApacheDocker

The idea behind this repository is to use Vargrant, Oracle VirtualBox and Ansible to provision a simple Linux server, build a web service based on nginx and serve out a simple web page.

NOTE: The code will run on Linux or MacOS machines. But will not work on Windows machines as there is no native 'sshd' support on Windows.

  1. Download and install the correct versions of following software : 1a. VirtualBox https://www.virtualbox.org/

    1b. Vagrant https://www.vagrantup.com/downloads.html

  2. Download this git repository to your computer and unzip it

  3. cd to the directory where the unziped file are

  4. Run "vagrant up"

  5. Following message indicates the Web server has been built and in service

TASK [start the container] *****************************************************

NOTE: See "screen-capture-of-the-run.txt" for full output of the command

Testing:

  1. Open a browser and enter : http://localhost:8080/

  2. Following message must appear on the browser window:

    Hello World !!!

  3. Interactive login to the docker

    ssh -l vagrant -i .vagrant/machines/default/virtualbox/private_key 192.168.33.99

Cleanup :

  1. Press Ctrl/C on the terminal window where "vagrant up" was run

  2. Tidy up Vagrant enviornment

$ vagrant global-status // look for the id of the virtual box.

$ vagrant destroy d21c245 // destroy the virtualbox
default: Are you sure you want to destroy the 'default' VM? [y/N] y
==> default: Forcing shutdown of VM...
==> default: Destroying VM and associated drives...

NETWORK SETUP

Local computer ip = 192.168.1.146

Guest OS ip = 192.168.33.99
This is specified in Vagrantfile

defined config.vm.network "private_network", ip: "192.168.33.99"

Port 80 in the docker is mapped to port 8080 on local computer

Confirm
config.vm.network "forwarded_port", guest: 80, host: 8080

NOTES:

  1. debian/jessie64 is used as the guest host

  2. Checking of the Debian version is omitted for simplicity

  3. For MacOS users: I encountered the following bugs and used a workaround. Your mileage may vary.

    docker_image, docker_container and docker modules fails with: "Failed to import docker-py - No module named requests.exceptions. Try pip install docker-py"}

    See: ansible/ansible-modules-core#4246 time spent on researching this

    So, I am using the ansible 'command' module as an alternative.

About

Use Vagrant to provision a Alpine Linux Virtual inside Oracle Virtual Box, Install Docker in Alpine Linux, Create a docker image with Nginx and Serve a test page

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published