GabrielCYOU_logo

Deploy Docker Compose on Azure Failed

This is a relatively easy post to record the steps to deploy docker images with docker compose.

Reference: Snap install DockerManage Docker as Non Root UserHow Docker Compose Works

Open a new vm and install Docker

This time I’m using Azure to open the new VM, it now offers 12 months free tier B1s/B2pls_v2 ARM and B2ats_v2 AMD for free account. My VM is using B2ats_v2 AMD, with x64 chip and Ubuntu Server 22.04 LTS x64.

Install Docker Compose

# bash
# install snap
sudo apt update
sudo apt install snapd

# install docker
sudo snap install docker

Docker Authorization

You may use docker on your VM now. However, by default docker could only access by sudo. Please refer to snapcraft.io/docker.

If you would like to use docker like normal user, make your user in the docker group.

 sudo addgroup --system docker
 sudo adduser $USER docker
 newgrp docker
 sudo snap disable docker
 sudo snap enable docker

Docker compose

I first open a folder and do compose.yaml in that folder to keep maintenance clear.

About docker-compose, you may refer to my post:

cd ~ && mkdir my-compose-app && cd my-compose-app
vim compose.yaml  # create the file with vim editor
# compose.yaml
services:
  remix-app:
    image: my_docker_username/my-remix-app
    ports:
      - 3000:3000
    environment:  # environment variables
      # the url for scylla and database in composed network, not localhost. cql is the service name, you could try ping cql from remix container sh.
      DB_URL: cql
  cql:
    image: scylladb/scylla
    ports:
      - 9042:9042
    # https://docs.docker.com/storage/volumes/#use-a-volume-with-docker-compose
    volumes:
      - db:/var/lib/scylla  # should be where scylla store files

volumes:
  db:

When finished editing your compose.yaml file, press 😡 to save and quit vim.

You may encounter that the docker command not found (I’m running into this situation using Debian 11). Generally it’s because the PATH environment variable is not added. To debug, first check that /snap/bin/docker -v works. Then follow the instructions and should work when you type docker -v.

BTW, you could check if your user is in the docker group by typing groups in shell, if not, you may need to reboot your linux.

# Open bashrc file to set env
vim ~/.bashrc

# Add the following in the end of the file or wherever you prefer
export PATH=$PATH:/snap/bin

# Reload env
source ~/.bashrc

Run Docker Compose

Because I’m using a private Docker Hub repository, I use docker login before pulling and run.

You should run the docker-compose up right at the folder you store your compose.yaml file.

docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
docker-compose up -d  # run with detached mode

Performance Comparison Azure / GCP

I already runs a GCP e2-micro VM, this time just trying Azure. However, these steps on Azure B2ats_v2 ended up running out of ram and could not successfully open it up. On the other hand, GCP took about 20 minutes and deployed successfully.

Comparison:

e2-microB2ats_v2
CPU2vCPU2vCPU
RAM1GB Ram1GB Ram
Cost$0.0110$0.0094
TopMiB Mem : 975.6 total
MiB Swap: 634.8 total
MiB Mem : 833.3 total
MiB Swap: 0.0 total
As of 2024/03/10

Google Not only provides 17% more Ram and innumerable Swap, but also make e2-micro an alway-free tier.

Not sure if it is because of the SWAP, the GCP e2-micro successfully runs the docker compose in 20 minutes, with a high CPU consumption.
“compose-cql-1 | added 884 packages, and audited 885 packages in 12m”
“compose-remix-app-1 | [info] built (7m 14.2s)”

# docker stats
CONTAINER ID   NAME                  CPU %     MEM USAGE / LIMIT     MEM %     NET I/O         BLOCK I/O         PIDS
369316367d08   compose-remix-app-1   449.64%   96.68MiB / 975.6MiB   9.91%     366kB / 106kB   72.6MB / 2.85MB   12
61220a76a32c   compose-cql-1         555.51%   151.1MiB / 975.6MiB   15.49%    1.5kB / 0B      208MB / 291MB     32