Vely logo install | documentation | examples | articles | changelog
16.6.0 released on Mar 08, 2023 | articles updated on Mar 20, 2023

Containerize application

This is a short tutorial on building a base Vely image, and an application image (regardless of what your application does) that can be deployed anywhere, even on non-Linux systems. This is one way to deploy your Vely application. See also example_docker for an example you can run. You can use docker or podman (substitute podman for docker).

The application container has a Vely application installed, and your reverse proxy web server and your databases must be created (see application_setup for more information), as they will likely either run on the host machine, or be containers themselves.

The base image used here is "vely" (created in the previous step). User "vely" is created and assigned limited sudo privileges for Vely only. Source code of your application is in "docker" directory on the host, and copied to the container, where application is compiled and linked, then source code is deleted, making the container ready for deployment (if you wish to keep the source, you certaintly can, just remove the lines that delete it). Finally, the entry point will start application - that's what runs when the container is deployed.

The following shows how to create a deployment image and a subsequent running container. The application name is "velydemo" - change it as needed.
#Create base vely image. Install Vely on top of Ubuntu 20.04
FROM ubuntu:20.04
ENV TZ=America/Phoenix
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt update
RUN apt install -y apt-transport-https ca-certificates wget sudo
RUN wget  -qO -|sudo tee /usr/share/keyrings/vely.asc >/dev/null
ARG arch
RUN sudo bash -c "echo 'deb [signed-by=/usr/share/keyrings/vely.asc]$arch/latest ubuntu_20_$arch vely' >/etc/apt/sources.list.d/vely.list"
RUN sudo apt update
RUN sudo apt install -y vely
Create an image with - use --no-cache in order to update the image when new Vely release is available:
sudo docker build --no-cache -t vely .
In some cases your application is stateless, i.e. all the data is through to database(s) and other applications. In other cases, you may want to have file storage that persists even when containers recycle - typically that means persisting Vely directory (which is /var/lib/vv, see how_vely_works). In that case, you can use a container storage option for that purpose; in case of docker, that would be volumes, for instance:
sudo docker volume create velyhome
For example, if your application uploads/downloads files, you may use Vely file_storage (which is under /var/lib/vv); or you may store other files that your application produces. In such cases using a volume (or similar) may be a good idea; in other cases you may want a stateless container and offload such functionality elsewhere (for instance to databases, other applications etc.).

Next is velyapp.dockerfile, which is used to create an image for an application. In this case it is a demo application with source code in "docker" directory (under the current working directory):
#Create image that will be used to compile and link an application. Source code is copied from host,
#application is setup, and the source code is deleted (remove this step if you want to ship the source code).
#After that the image is ready to run in a container. Here, the application name is "velydemo"; change it to
#fit your application. The port used in 2300, you can change that as well.
#Customize the ENTRYPOINT command to fit your runtime.
FROM vely
#create vely user and give it limited sudo powers
RUN useradd -ms /bin/bash vely && echo "vely:vely" | chpasswd
RUN echo "vely ALL=(ALL) NOPASSWD: /usr/bin/vf" >> /etc/sudoers
#default user
USER vely
#default working dir
WORKDIR /home/vely
#copy over source code and make app
COPY ./docker/* /home/vely/
#this is to run app with docker run
ENTRYPOINT [ "./runit" ]
The "runit" script will create an application in the container, build it, and start it in the foreground. This script is in the "docker" directory with your application source code:
#Create Vely application and run it in foreground for docker
#demout has a log of execution
sudo vf -i -u $(whoami) velydemo
vv -c
vv -q --db=mariadb:db -s
vv -c
vf -f -w3 -p2300 velydemo > demout
Stop and remove any current containers/images:
sudo docker stop velyapp || true
sudo docker rmi velyapp || true
Build an application image:
sudo docker build --no-cache -t velyapp -f velyapp.dockerfile .
Assuming you have setup web server and any database(s), start the container (using "host" network interface for simplicity):
sudo docker run --init --name velyapp -d  --network="host" --rm velyapp velyapp
If your application uses volumes for data persistence, you might use:
sudo docker run --init --name velyapp -d -v velyhome:/var/lib/vv  --network="host" --rm velyapp
Note that you can persist any storage you want, however at the minimum you would likely persist Vely directory (/var/lib/vv) which is stored on the host under volume "velyhome".

Now you can use your application through web server:<request name>...

See also

Running application ( application_setup   CGI   Client_API   command_line   containerize_application   FastCGI   FastCGI_client   plain_C_FCGI  )  SEE ALL (documentation)

Copyright (c) 2017-2023 DaSoftver LLC. Vely is a trademark of Dasoftver LLC. The software and information herein are provided "AS IS" and without any warranties or guarantees of any kind. Vely elephant logo (c) 2022 DaSoftver LLC. This web page is licensed under CC-BY-SA-4.0. Contact email