Testing application with docker-compose


A production grade application which requires servers (non serverless ??) is most suited for a containered kubernetes deployment. Even though the sentence doesn’t make any sense, it makes sense to use docker-compose to test such applications instead of spinning up a k8s cluster or namespace.

This post is a quick reference guide to create a single machine setup to test a multi service application.

Create a VM and Login

ssh -i ~/SSH_KEY.pem ubuntu@SERVER_IP

sudo apt-get update

Install Docker

https://docs.docker.com/engine/install/ubuntu/

Prerequisite

sudo apt-get update

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

echo \
  "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

select version

apt-cache madison docker-ce

ubuntu@ip-x-x-x-x:~$ apt-cache madison docker-ce
 docker-ce | 5:20.10.8~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
 docker-ce | 5:20.10.7~3-0~ubuntu-focal | https://download.docker.com/linux/ubuntu focal/stable amd64 Packages
...
sudo apt-get install docker-ce=5:20.10.8~3-0~ubuntu-focal docker-ce-cli=5:20.10.8~3-0~ubuntu-focal containerd.io

Docker Compose

https://docs.docker.com/compose/install/

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

docker-compose --version

Get the code

git clone https://github.com/user/repo

cd repo

docker-compose up -d

Access

http://SERVER_IP

Redeploy

git pull
docker-compose up --force-recreate --build -d
docker image prune -f