Skip to content

Docker Persistent Container

Komal Sharma edited this page Sep 6, 2023 · 3 revisions

Get started with Uvdesk now by using the docker container persistent.

To setup with docker container persistent then first you will be install the uvdesk community helpdesk project using composer (recommended), use the following commands:

$ composer create-project uvdesk/community-skeleton

If you don't wish to use composer, you can just download the zip of the project.

Dockerize your Helpdesk

Now you can dockerize your helpdesk project to easily deploy your setup from within a docker container.

To build an image, simply switch to your project's directory and run the following command:

$ docker build -t {IMAGE_NAME} .

image

Upon successfully execution, this will create a docker image with the specified tag using the -t option. You can use this image to deploy your helpdesk project.

For check your docker images list then run the below command:

$ docker images

image

Deploying Container with persistent mount volumes:

  • If you want to persist mysql database setup locally within container use the below line:

uvdesk_db (/var/lib/mysql) [You can use the any name of volume: uvdesk_db ]

  • If you want to persist the entire app and associated data including configurations, logs, and any changes to source code:

uvdesk_app (/var/www/uvdesk)

  • If you want to persist only the app and related environment configurations:

uvdesk_config (/var/www/uvdesk/config)

${PWD}/.env (/var/www/uvdesk/.env)

Now create a container using the mount volumes follow the below deploy container command:

Create container with mounted volumes:

docker run -dit -p 82:80 -p 3306:3306 \
-v uvdesk_app:/var/www/uvdesk \
-v uvdesk_db:/var/lib/mysql \
--name <your-container-name> <your-build-image-name>;

Alternatively:

docker run -dit -p 82:80 -p 3306:3306 \
-v uvdesk_config:/var/www/uvdesk/config \
-v uvdesk_db:/var/lib/mysql \
-v ${PWD}/.env:/var/www/uvdesk/.env \
--name <your-container-name> <your-build-image-name>;

Alternatively:

docker run -dit -p 82:80 -p 3306:3306 \
-e MYSQL_USER={MYSQL_USER} \
-e MYSQL_ROOT_PASSWORD={MYSQL_ROOT_PASSWORD} \
-e MYSQL_PASSWORD={MYSQL_PASSWORD} \
-e MYSQL_DATABASE={MYSQL_DATABASE} \
-v uvdesk_config:/var/www/uvdesk/config \
-v uvdesk_db:/var/lib/mysql \
-v ${PWD}/.env:/var/www/uvdesk/.env \
--name <your-container-name> <your-build-image-name>;

For Reference check the below screenshot:

image

Setup your project using web interface

Now setup your docker project using the port number like this:

http://localhost:4003/

Note: At this moment here shows an error while you will setup of mysql setup, so you will be first create mysql database credentials on your created container.

image

Access Docker Container

Follow the below command:

$ docker exec -it <your-container-name> /bin/bash

image

Configure mysql credentials in created container

After access your docker container now access your mysql terminal using the below command:

$ mysql

or

$ mysql -u root

After access mysql terminal now you will be configure mysql credentials and use containerized database.

Manage and update user credentials & privileges

mysql> ALTER USER root@localhost IDENTIFIED WITH mysql_native_password BY '{MYSQL_ROOT_PASSWORD}';

mysql> CREATE USER {MYSQL_USER}@localhost IDENTIFIED WITH mysql_native_password BY '{MYSQL_PASSWORD}';

mysql> GRANT ALL ON *.* To uvdesk@localhost;

mysql> UPDATE mysql.user SET host='%' WHERE user='{MYSQL_USER}';

mysql> FLUSH PRIVILEGES;`

For Exit mysql terminal & back to container shell terminal using the below command:

mysql> exit

image

After manage your mysql DB details then now setup your project again now add the same mysql DB details you have created.

http://localhost:4003/

After setup you will be shows your helpdesk url with admin and customer/front-end panel.

Admin Panel:

http://localhost:4003/en/member/login

Front-end Panel:

http://localhost:4003/en/

Note: If any reason your container is stop then you need to restart again your container and also restart your mysql service inner your docker container using the below commands.

For docker container restart:

$ docker restart <Container-name/continer-id>

For docker container access:

$ docker exec -it <your-container-name> /bin/bash

For Restart mysql service: [Access your docker container now run this command for restart mysql service]

$ service mysql restart

Additional Notes for docker and mysql commands:

After create mysql credentials access for mysql:

$ mysql -u root -p [Then enter add your created password]

For Restart mysql service:

$ service mysql restart

For check mysql status:

$ service mysql status

For apache service restart:

$ service apache2 restart

For check apache status:

$ service apache2 status

For shows List of running containers:

$ docker ps

For shows List of all created containers:

$ docker ps -a

For Remove created container:

$ docker rm <container id or container name>

For container restart [If container is not running]:

$ docker restart <container name or container id>

For docker stop:

$ docker stop <container id or name>

For stop and remove the container in one command:

$ docker rm -f <my_container-name or id>

For Removes all stopped containers:

$ docker container prune

For create a new docker image:

$ docker build -t <image-name> .

For shows list of all docker created images:

$ docker images

For Remove docker image:

$ docker rmi <image name or image id>

For mysql process kill:

pgrep mysql

For Remove all unused volumes: [All unmounted volumes can be removed by]

$ docker volume prune