SE Hub
Deploying with Docker

Getting Started

A walkthrough of deploying a project with Docker on our servers.

In this guide, we will deploy internal-v2 project at develop-at.vesperia.id. Deploying different projects at different servers should work the same way.

In some cases, you may need to login as root.

Working on a New Project

If the project does not exist, we need to clone the project repository to /var/projects directory.

cd /var/projects
git clone https://gitlab.com/vesperiaGM/internal-v2.git

Change the Git URL with the URL of the repository you want to deploy.

Working on an Existing Project

If the project already exists, we only need to cd to the project directory.

cd /var/projects
cd internal-v2

Setting Up Docker

Check Out Branch

We need to make sure that we are in the correct branch before getting our project running with Docker. To check which branch we are currently in, we can use the git status command.

In this guide, we want to deploy the dev branch.

git checkout dev

Set Up .env File

In most cases, our projects are already bootstrapped with .env.example. If that is the case, we only need to copy the content of .env.example to .env by using the following command:

cp .env.example .env

Otherwise, we can use the following command to manually create the .env file:

touch .env

After creating the .env file, we need to ensure that APP_URL exists. The APP_URL should have the following pattern:

APP_URL=[server_address]:[port_number]

Check Available Ports to see available port number.

Following the above pattern, the APP_URL for our internal-v2 project will have the following value:

APP_URL=http://develop-at.vesperia.id:1009

Build Docker Image

To build the Docker image, we need to run the following command:

docker build -f Docker/Dockerfile -t name:tag .

The . at the end of the command is intentional. Do not leave it out.

By following the naming conventions for name and tag, we will use the following command to build the Docker image for our internal-v2 project:

docker build -f Docker/Dockerfile  -t internal_v2:dev .

Create Docker Volume

You may skip this step if the project does not need to persist data used by the Docker container.

We need to create a Docker volume to keep data from disappearing when the Docker container is restarting or creating anew. For example, we need to persist uploaded files and database data.

docker volume create volume_name

By following the naming conventions for volume_name, we can execute the following command to build the Docker volume for our internal-v2 project:

docker volume create internal_v2_storage

Keep in mind that we don't need to create a volume with the same usage for each deployment. We can use the already existing volume dedicated to the project. To check the list of existing volumes, run the following command:

docker volume ls

Get a Queue Worker Running

You may skip this step if the project does not have any custom channel queues to run.

When we run the Docker container for our project, php artisan queue:worker is automatically executed in the background to ensure that any queues are running. However, if we have a custom channel queue, we need to manually configure it in our Docker's supervisord.conf file.

The internal-v21 project itself does not have any custom channel queues to run. Therefore, in this guide, we will demonstrate how to configure the TKDDJob queue in our SMI GRM project. To do this, add the following configuration code to the project's Docker/Services/supervisord.conf file:

[program:app-worker-tkddjob]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/artisan queue:work --queue=TKDDJob --sleep=3 --tries=3
autostart=true
autorestart=true
numprocs=2
redirect_stderr=true
user=root
stdout_logfile=/var/www/html/storage/logs/worker.log

Run Docker Container

Lastly, we need to run our Docker container to get our project up and running.

docker run --name container_name -dp port:80 name:tag

Change container_name to a name of your choice for the container, and set port to match the value of port number in the APP_URL variable in your .env file. Also, set name and tag to match the name and tag of your Docker image.

Do not forget to following the naming conventions.

To run our internal-v2 Docker container, we can execute the following command:

docker run --name internal_v2_dev -d 1009:80 internal_v2:dev

Mounting a Docker Volume

If we need to mount a Docker volume, we can use this command instead:

docker run --name container_name -dp port:80 -v volume_name:/var/www/html/storage/app/public name:tag

Change volume_name to the name of the Docker volume you have created.

Since our internal-v2 project needs a Docker volume to be mounted, we can run our Docker container and mount our Docker volume with this command:

docker run --name internal_v2_dev  -dp 1009:80 -v internal_v2_storage:/var/www/html/storage/app/public internal_v2:dev

Accessing Project from Browser

The project is now publicly accessible. We can check it in out browser by hitting develop-at.vesperia.id:1009.

On this page