30 Jan, 2019

Setting `docker-compose` on fresh Ubuntu 18.04 install

In an effort for setting development tools in the most economical way (and also learn stuff about as much as possible), I am now trying to install docker-compose on a fresh Ubuntu 18.04 instance.

At the end, an nginx is supposed to run at startup and display a generic page.

Assumpions

  • the OS is already installed;
  • ufw is enabled, ports 80 and 443 are accesible;
  • the OS already has a custom user with sudo privileges (e.g. user);
  • we have a domain name pointing at the IP of the server (e.g. example.com) and also a CNAME record (*.example.com);

Install docker

Install docker-compose

Setup Nginx

  • sudo mkdir -p /app
  • cd /app
  • sudo touch docker-compose.yml
  • sudo nano docker-compose.yml
  • docker-compose up -d
  • Access http://example.com and here you should see the default nginx page.

Autostart

  • crontab -e
  • add: @reboot /usr/bin/docker ps && /usr/local/bin/docker-compose -f /app/docker-compose.yml start
  • sudo reboot
  • http://example.com should still be accesible after server starts;
  • http://whatever.example.com should also be aviable, with the same content.

Sources