Can't setup krayin with provided docker files
-
Hi, I have been trying to setup a local krayin using the docker config provided on https://devdocs.krayincrm.com/2.0/introduction/docker.html#introduction and https://github.com/krayin/krayin-docker/tree/main.
I have got the files setup in a directory with the compose.yaml, Dockerfile, setup.sh and relevant .config files in the .config directory.
I can build the docker images fine if i run docker compose up however when I run the setup.sh script i get the following output.
❯ ./setup.sh
Removing network krayin_test_default
WARNING: Network krayin_test_default not found.
Removing volume krayin_test_mysql-data
WARNING: Volume krayin_test_mysql-data not found.
krayin-mysql uses an image, skipping
Building krayin-php-apache
[+] Building 0.5s (27/27) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 1.56kB 0.0s
=> [internal] load metadata for docker.io/library/node:22.9 0.4s
=> [internal] load metadata for docker.io/library/php:8.3-apache 0.4s
=> [internal] load metadata for docker.io/library/composer:2.7 0.4s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [stage-0 1/18] FROM docker.io/library/php:8.3-apache@sha256:7a3fd6ae9c9d240810bae95d3aaf894be4f0ec1a022b0a5f129d658a625e2ac2 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 70B 0.0s
=> FROM docker.io/library/composer:2.7@sha256:cb3483dc851665462a66c59982577dfbbde0ae2059e8b5550c2f49f44b8c333e 0.0s
=> FROM docker.io/library/node:22.9@sha256:8398ea18b8b72817c84af283f72daed9629af2958c4f618fe6db4f453c5c9328 0.0s
=> CACHED [stage-0 2/18] RUN apt-get update && apt-get install -y git ffmpeg libfreetype6-dev libicu-dev libgmp-dev libjpeg62-turbo-dev libpng-dev 0.0s
=> CACHED [stage-0 3/18] RUN docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp 0.0s
=> CACHED [stage-0 4/18] RUN docker-php-ext-configure intl 0.0s
=> CACHED [stage-0 5/18] RUN docker-php-ext-install bcmath calendar exif gd gmp intl mysqli pdo pdo_mysql zip 0.0s
=> CACHED [stage-0 6/18] COPY --from=composer:2.7 /usr/bin/composer /usr/local/bin/composer 0.0s
=> CACHED [stage-0 7/18] COPY --from=node:22.9 /usr/local/lib/node_modules /usr/local/lib/node_modules 0.0s
=> CACHED [stage-0 8/18] COPY --from=node:22.9 /usr/local/bin/node /usr/local/bin/node 0.0s
=> CACHED [stage-0 9/18] RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm 0.0s
=> CACHED [stage-0 10/18] RUN npm install -g npx 0.0s
=> CACHED [stage-0 11/18] RUN npm install -g laravel-echo-server 0.0s
=> CACHED [stage-0 12/18] WORKDIR /var/www/html/ 0.0s
=> CACHED [stage-0 13/18] RUN useradd -G www-data,root -u 1000 -d /home/alex alex 0.0s
=> CACHED [stage-0 14/18] RUN mkdir -p /home/alex/.composer && chown -R alex:alex /home/alex 0.0s
=> CACHED [stage-0 15/18] COPY ./.configs/apache.conf /etc/apache2/sites-available/000-default.conf 0.0s
=> CACHED [stage-0 16/18] RUN a2enmod rewrite 0.0s
=> CACHED [stage-0 17/18] RUN chmod -R 775 /var/www/html/ 0.0s
=> CACHED [stage-0 18/18] RUN chown -R alex:www-data /var/www/html/ 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:46cdbb41e246045935e91856a6442143e1539d75c3a2e2944d0a6098f08e0dad 0.0s
=> => naming to docker.io/library/krayin-php-apache 0.0s
Creating network "krayin_test_default" with the default driver
Creating volume "krayin_test_mysql-data" with default driver
Creating krayin_test_krayin-mysql_1 ... done
Creating krayin_test_krayin-php-apache_1 ... done
Please wait... Waiting for MySQL connection...
Creating empty database for krayin...
Creating empty database for krayin testing...
Now, setting up Krayin...
fatal: could not create work tree dir 'krayin': Permission denied
Now, setting up Krayin stable version...
bash: line 1: cd: krayin: No such file or directory
bash: line 1: cd: krayin: No such file or directory
lstat /home/alex/SourceCode/krayin_test/.configs/.env: no such file or directory
lstat /home/alex/SourceCode/krayin_test/.configs/.env.testing: no such file or directory
sh: 1: cd: can't cd to krayinI believe the issue is due to the user in the compose.yaml not being correct however it isn't clear what it should be. User id 1000 is my host machines user id, but does there need to be a www-data user and have userid be set to that? Any help would be appreciated.
Here are my compose.yaml and Dockerfile
compose.yaml (I removed phpmyadmin as I don't need it):
services:
krayin-php-apache:
build:
args:
container_project_path: /var/www/html/
uid: 1000 # add your uid here
user: $USER
context: .
dockerfile: ./Dockerfile
image: krayin-php-apache
ports:- 80:80 # adjust your port here, if you want to change
volumes: - ./workspace/:/var/www/html/
krayin-mysql:
image: mysql:8.0
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_HOST: '%'
MYSQL_ROOT_PASSWORD: root
ports:- 3306:3306 # adjust your port here, if you want to change
volumes: - ./.configs/mysql-data:/var/lib/mysql/
volumes:
mysql-data:Dockerfile:
# main image
FROM php:8.3-apache# installing dependencies
RUN apt-get update && apt-get install -y
git
ffmpeg
libfreetype6-dev
libicu-dev
libgmp-dev
libjpeg62-turbo-dev
libpng-dev
libwebp-dev
libxpm-dev
libzip-dev
unzip
zlib1g-dev# configuring php extension
RUN docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp
RUN docker-php-ext-configure intl# installing php extension
RUN docker-php-ext-install bcmath calendar exif gd gmp intl mysqli pdo pdo_mysql zip# installing composer
COPY --from=composer:2.7 /usr/bin/composer /usr/local/bin/composer# installing node js
COPY --from=node:22.9 /usr/local/lib/node_modules /usr/local/lib/node_modules
COPY --from=node:22.9 /usr/local/bin/node /usr/local/bin/node
RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm# installing global node dependencies
RUN npm install -g npx
RUN npm install -g laravel-echo-server# arguments
ARG container_project_path
ARG uid
ARG user# setting work directory
WORKDIR $container_project_path# adding user
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer &&
chown -R $user:$user /home/$user# setting apache
COPY ./.configs/apache.conf /etc/apache2/sites-available/000-default.conf
RUN a2enmod rewrite# setting up project from
src
folder
RUN chmod -R 775 $container_project_path
RUN chown -R $user:www-data $container_project_path# changing user
USER $user - 80:80 # adjust your port here, if you want to change
-
Hello @alex-oconnor
If Apache and MySQL servers are running separately from Docker in the system, stop them and then try again. If it still doesn't work, then remove the krayin image from Docker or stop the container.
I hope that will work for you after that.
Thanks & Regards
-
I've tried removing the images entirely and rebuilding them and running setup.sh again to no success. The Apache and MySQL are running in Docker. The issue is still that the line in the setup.sh
docker exec ${apache_container_id} git clone https://github.com/krayin/laravel-crm krayin
is getting permissions denied which I believe is a result of the user not being set correctly in the docker compose file, but there is no documentation on what the user should be so I was hoping to get some clarification on that.
I have included the setup.sh below.
# just to be sure that no traces left docker-compose down -v # building and running docker-compose file docker-compose build && docker-compose up -d # container id by image name apache_container_id=$(docker ps -aqf "name=krayin-php-apache") db_container_id=$(docker ps -aqf "name=krayin-mysql") # checking connection echo "Please wait... Waiting for MySQL connection..." while ! docker exec ${db_container_id} mysql --user=root --password=root -e "SELECT 1" >/dev/null 2>&1; do sleep 1 done # creating empty database for krayin echo "Creating empty database for krayin..." while ! docker exec ${db_container_id} mysql --user=root --password=root -e "CREATE DATABASE IF NOT EXISTS krayin CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" >/dev/null 2>&1; do sleep 1 done # creating empty database for krayin testing echo "Creating empty database for krayin testing..." while ! docker exec ${db_container_id} mysql --user=root --password=root -e "CREATE DATABASE IF NOT EXISTS krayin_testing CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" >/dev/null 2>> sleep 1 done # setting up krayin echo "Now, setting up Krayin..." docker exec ${apache_container_id} git clone https://github.com/krayin/laravel-crm krayin # setting krayin stable version echo "Now, setting up Krayin stable version..." docker exec -i ${apache_container_id} bash -c "cd krayin && git reset --hard v2.0.1" # installing composer dependencies inside container docker exec -i ${apache_container_id} bash -c "cd krayin && composer install" # moving `.env` file docker cp .configs/.env ${apache_container_id}:/var/www/html/krayin/.env docker cp .configs/.env.testing ${apache_container_id}:/var/www/html/krayin/.env.testing # executing final commands docker exec -i ${apache_container_id} sh -c "cd krayin && php artisan optimize:clear && php artisan migrate:fresh --seed && php artisan storage:link && php artisan vendor:publish --provi>
-
Hi
I'm still struggling to get this working, any advice would be appreciated. -
Hello @alex-oconnor
Can you please let us know the Step by Step that how you are set up and doing this?
This will help us to resolve your query.
Thanks & Regards
-
So I have tried multiple methods, but starting from scratch if I delete all the docker images and folders.
I copy/clone the files from the git repo onto my host machine from https://github.com/krayin/krayin-docker/tree/main. From here I either run docker compose up first or run the setup.sh script (I get the same result from either approach).
This runs docker build and puts up the containers as expected and I have tested and I can connect to them via docker exec. However when it gets to the line
docker exec ${apache_container_id} git clone https://github.com/krayin/laravel-crm krayin
In the setup.sh it gets a permission denied error when trying to create the directory krayin inside the docker container. I believe this is due to the user_id that is set in the compose file not being correct, however there is no guidance in the docs as to what this should be set to as there are different values between what is on github and what is in the docs on the website. If it is something else completely please let me know.
Thanks
Alex -
Hello @alex-oconnor,
The issue you're encountering seems to be related to the default Linux
UID: 1000
. To resolve this, you can first confirm your current UID by running the following command:echo $UID
Once you've verified the UID, update the
docker-compose.yml
file accordingly, specifically around line 8, to align with your UID.This adjustment should address the "permission denied" issue effectively. Please let me know if you need further assistance!
-
I've tried setting it to 1000 which is my current local user, but sadly I get the same issue.
Thanks
Alex