Skip to content

Commit b1a5110

Browse files
committed
setup docker file and docker compose file
1 parent 7efc63c commit b1a5110

File tree

4 files changed

+92
-3
lines changed

4 files changed

+92
-3
lines changed

.env.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ LOG_DEPRECATIONS_CHANNEL=null
2222
LOG_LEVEL=debug
2323

2424
DB_CONNECTION=mysql
25-
DB_HOST=127.0.0.1
25+
DB_HOST=mysqldb
2626
DB_PORT=3306
27-
DB_DATABASE=laravel
27+
DB_DATABASE=test-db
2828
DB_USERNAME=root
29-
DB_PASSWORD=
29+
DB_PASSWORD=test-password
3030

3131
SESSION_DRIVER=file
3232
SESSION_LIFETIME=120

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ yarn-error.log
2121
/.nova
2222
/.vscode
2323
/.zed
24+
data

Dockerfile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Base image: PHP 8.3-alpine
2+
FROM php:8.3-alpine
3+
4+
# install system dependencies
5+
RUN apk update && apk add --no-cache \
6+
openssl \
7+
zip \
8+
unzip \
9+
git \
10+
mysql-client \
11+
libzip-dev \
12+
libpng-dev \
13+
libjpeg-turbo-dev \
14+
freetype-dev \
15+
libxml2-dev
16+
17+
#install composer (PHP package manager)
18+
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
19+
20+
# Install PHP extensions for MySQL
21+
RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
22+
&& docker-php-ext-install -j$(nproc) gd pdo pdo_mysql mysqli zip
23+
24+
# check if mbstring extension is installed (for debugging purposes)
25+
RUN php -m | grep mbstring
26+
27+
# set working directory
28+
WORKDIR /app
29+
30+
# copy application file into the container
31+
COPY . /app
32+
33+
# install dependencies
34+
RUN composer install --optimize-autoloader --no-dev
35+
36+
# Generate Laravel application key
37+
RUN php artisan key:generate
38+
39+
# Command to run the laravel development server
40+
CMD php artisan serve --host=0.0.0.0 --port=8000
41+
42+
# Expose port 8000
43+
EXPOSE 8000

docker-compose.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
version: "3"
2+
networks:
3+
application:
4+
driver: bridge
5+
services:
6+
app:
7+
build:
8+
context: .
9+
dockerfile: Dockerfile
10+
container_name: test_backend
11+
ports:
12+
- 8000:8000
13+
volumes:
14+
- .:/app
15+
depends_on:
16+
db:
17+
condition: service_healthy # Ensure MySQL is ready before Laravel starts
18+
environment:
19+
- DB_HOST=mysqldb
20+
- DB_CONNECTION=mysql
21+
- DB_PORT=3306 # MySQL runs on 3306 inside the container
22+
- DB_DATABASE=test-db
23+
- DB_USERNAME=root
24+
- DB_PASSWORD=root # Match MySQL container credentials
25+
networks:
26+
- application
27+
command: php artisan serve --host=0.0.0.0 --port=8000
28+
29+
db:
30+
image: mysql:8.0
31+
ports:
32+
- "3307:3306"
33+
volumes:
34+
- ./data:/var/lib/mysql
35+
environment:
36+
- MYSQL_ROOT_PASSWORD=root
37+
- MYSQL_DATABASE=test-db
38+
networks:
39+
- application
40+
container_name: mysqldb
41+
healthcheck:
42+
test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-uroot", "-proot"]
43+
interval: 5s
44+
timeout: 5s
45+
retries: 5

0 commit comments

Comments
 (0)