Skip to content

Commit 558363c

Browse files
committed
updated docker to start with mysql
1 parent 2a9387c commit 558363c

3 files changed

Lines changed: 100 additions & 13 deletions

File tree

.env.example

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ LOG_STACK=single
2020
LOG_DEPRECATIONS_CHANNEL=null
2121
LOG_LEVEL=debug
2222

23-
DB_CONNECTION=sqlite
24-
# DB_HOST=127.0.0.1
25-
# DB_PORT=3306
26-
# DB_DATABASE=laravel
27-
# DB_USERNAME=root
28-
# DB_PASSWORD=
23+
DB_CONNECTION=mysql
24+
DB_HOST=mysql
25+
DB_PORT=3306
26+
DB_DATABASE=Hackerinn
27+
DB_USERNAME=sail
28+
DB_PASSWORD=password
2929

3030
SESSION_DRIVER=database
3131
SESSION_LIFETIME=120
@@ -43,14 +43,14 @@ CACHE_STORE=database
4343
MEMCACHED_HOST=127.0.0.1
4444

4545
REDIS_CLIENT=phpredis
46-
REDIS_HOST=127.0.0.1
46+
REDIS_HOST=redis
4747
REDIS_PASSWORD=null
4848
REDIS_PORT=6379
4949

50-
MAIL_MAILER=log
50+
MAIL_MAILER=smtp
5151
MAIL_SCHEME=null
52-
MAIL_HOST=127.0.0.1
53-
MAIL_PORT=2525
52+
MAIL_HOST=mailpit
53+
MAIL_PORT=1025
5454
MAIL_USERNAME=null
5555
MAIL_PASSWORD=null
5656
MAIL_FROM_ADDRESS="hello@example.com"

compose.yaml

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,71 @@ services:
2424
- './docker/start-with-migrate.sh:/usr/local/bin/start-with-migrate:ro'
2525
networks:
2626
- sail
27-
depends_on: { }
27+
depends_on:
28+
- mysql
29+
- redis
30+
- mailpit
31+
- selenium
32+
mysql:
33+
image: 'mysql:8.4'
34+
ports:
35+
- '${FORWARD_DB_PORT:-3306}:3306'
36+
environment:
37+
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
38+
MYSQL_ROOT_HOST: '%'
39+
MYSQL_DATABASE: '${DB_DATABASE}'
40+
MYSQL_USER: '${DB_USERNAME}'
41+
MYSQL_PASSWORD: '${DB_PASSWORD}'
42+
MYSQL_ALLOW_EMPTY_PASSWORD: 1
43+
MYSQL_EXTRA_OPTIONS: '${MYSQL_EXTRA_OPTIONS:-}'
44+
volumes:
45+
- 'sail-mysql:/var/lib/mysql'
46+
- './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
47+
networks:
48+
- sail
49+
healthcheck:
50+
test:
51+
- CMD
52+
- mysqladmin
53+
- ping
54+
- '-p${DB_PASSWORD}'
55+
retries: 3
56+
timeout: 5s
57+
redis:
58+
image: 'redis:alpine'
59+
ports:
60+
- '${FORWARD_REDIS_PORT:-6379}:6379'
61+
volumes:
62+
- 'sail-redis:/data'
63+
networks:
64+
- sail
65+
healthcheck:
66+
test:
67+
- CMD
68+
- redis-cli
69+
- ping
70+
retries: 3
71+
timeout: 5s
72+
mailpit:
73+
image: 'axllent/mailpit:latest'
74+
ports:
75+
- '${FORWARD_MAILPIT_PORT:-1025}:1025'
76+
- '${FORWARD_MAILPIT_DASHBOARD_PORT:-8025}:8025'
77+
networks:
78+
- sail
79+
selenium:
80+
image: selenium/standalone-chromium
81+
extra_hosts:
82+
- 'host.docker.internal:host-gateway'
83+
volumes:
84+
- '/dev/shm:/dev/shm'
85+
networks:
86+
- sail
2887
networks:
2988
sail:
3089
driver: bridge
90+
volumes:
91+
sail-mysql:
92+
driver: local
93+
sail-redis:
94+
driver: local

docker/start-with-migrate.sh

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,42 @@
11
#!/usr/bin/env bash
22
set -e
3+
34
# Same setup as Sail's start-container
45
if [ "$SUPERVISOR_PHP_USER" != "root" ] && [ "$SUPERVISOR_PHP_USER" != "sail" ]; then
56
echo "You should set SUPERVISOR_PHP_USER to either 'sail' or 'root'." >&2
67
exit 1
78
fi
9+
810
if [ -n "$WWWUSER" ]; then
911
usermod -u "$WWWUSER" sail 2>/dev/null || true
1012
fi
13+
1114
if [ ! -d /.composer ]; then
1215
mkdir /.composer
1316
fi
1417
chmod -R ugo+rw /.composer
15-
# Ensure SQLite database exists and run migrations as sail user
16-
touch /var/www/html/database/database.sqlite 2>/dev/null || true
18+
19+
# Wait for MySQL to be ready
20+
echo "Waiting for MySQL to be ready..."
21+
max_attempts=30
22+
attempt=1
23+
while [ $attempt -le $max_attempts ]; do
24+
if mysqladmin ping -h"${DB_HOST}" -u"${DB_USERNAME}" -p"${DB_PASSWORD}" --silent 2>/dev/null; then
25+
echo "MySQL is ready!"
26+
break
27+
fi
28+
echo "Attempt $attempt/$max_attempts: MySQL not ready yet, waiting..."
29+
sleep 2
30+
attempt=$((attempt + 1))
31+
done
32+
33+
if [ $attempt -gt $max_attempts ]; then
34+
echo "Warning: MySQL did not become ready in time. Continuing anyway..."
35+
fi
36+
37+
# Run migrations as sail user
38+
echo "Running migrations..."
1739
gosu sail php /var/www/html/artisan migrate --force 2>/dev/null || true
40+
1841
# Start supervisord (same as Sail's default start-container)
1942
exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf

0 commit comments

Comments
 (0)