DEV Community

Cover image for DEPLOY YOUR WEB APPLICATIONS IN A MINUTE - MADE WITH 💖 FOR DOCKERISTS
crazyoptimist
crazyoptimist

Posted on • Edited on

DEPLOY YOUR WEB APPLICATIONS IN A MINUTE - MADE WITH 💖 FOR DOCKERISTS

As a software engineer or a DevOps engineer, you may come up with boring tasks frequently, one of which is setting up a new cloud environment for deployment of your awesome web apps/micro services.

Using the following script, you will lose the dull pain. Just grab the script and run it with bash, then you will get the complete environment with docker/docker-compose and nginx which are all on the latest stable version.

Note: This is just for Ubuntu Bionic/Focal. Buzz me anytime in case you want to get the same one for any other distro, I'd love to help!

Happy containerizing! 🐋

Originally posted on my blog here.

Top comments (10)

Collapse
 
aimerib profile image
Aimeri Baddouh

I love this! Will certainly adopt it, and might even turn this into an ansible recipe. My only two pieces of suggestion:

If you want to keep only one nginx per host, but have multiple applications running in container, perhaps you could look into using swarm. Have one stack for your proxy, and deploy other apps in their own stack, but have them communicate via a dedicated nginx network. You already have all the tools necessary, and deploying it becomes a matter of having the right docker-compose.yml files, which you can keep in a repo. It reduces the amount of dependencies on the host, and makes it a little faster to upgrade versions, or replacing proxy/load balancers down the road.

in your script you have the latest version of docker-compose hardcoded, but if you wanted to always get the latest version you could replace the line:

curl -L "https://github.com/docker/compose/releases/download/1.27.0/docker-compose-$(uname -s)-$(uname -m)" -o docker-compose

with:

curl -s https://api.github.com/repos/docker/compose/releases/latest \
| grep -v ".sha256" \
| grep browser_download_url \
| grep "docker-compose-$(uname -s)-$(uname -m)" \
| cut -d '"' -f 4 \
| xargs curl -L -o docker-compose

The above is going to query the github api to get a list of the most recent release, ignore the .sha256 file, filter out any fields that aren't download urls, find the right download for your distro, get only the actual url, and curl download it. Everything else in the script remains the same.

Collapse
 
crazyoptimist profile image
crazyoptimist

Updated according to your advice, thanks!

Collapse
 
crazyoptimist profile image
crazyoptimist

Great!

Collapse
 
crazyoptimist profile image
crazyoptimist • Edited

EDIT: Nov 15, 2021
A few things have been changed on the docker documentation regarding docker-compose installation, above script has been updated accordingly.
Changes made:

  • Convert uname from "Linux" to "linux" using tr command
  • Docker compose cli command is now docker compose, evolved in version 2
Collapse
 
mertsenel profile image
MertSenel

Thanks I always need to go into docker docs each time for this task. Can I recommend converting this to "cloudinit" format. That way you can just run the script while creating the VM.

Collapse
 
crazyoptimist profile image
crazyoptimist

Thanks too! Ya, it's a cool idea! Let me test it soon.

Collapse
 
robkenis profile image
Rob Kenis

Why are you running nginx native on the machine and not in a docker container ?

Collapse
 
crazyoptimist profile image
crazyoptimist • Edited

When it comes to hosting multiple web apps on one machine, it makes me to avoid redundant nginx containers and a few more benefits ..
I found it more painless. Is there any reason to use nginx containers every time or any security concerns? Let me know, I'd love to learn from you!

Collapse
 
robkenis profile image
Rob Kenis

There's no security concern I can think of right now. I was thinking more about using the same setup when developing and in production. For example, when I have 2 projects on my machine with a different nginx config, it would be easier to run both in a container and manage the applications and nginx in docker-compose. Then after it works locally, you can bring your entire nginx container to production.

Thread Thread
 
crazyoptimist profile image
crazyoptimist

I agree with you.
Different nginx configuration across multiple apps on the same machine. 👍