laravel 为什么每次我运行Sail Up,它都会在Docker中创建一个新的容器?

pbpqsu0x  于 2023-03-31  发布在  Docker
关注(0)|答案(1)|浏览(150)

我是Docker和Laravel的新手。为什么每次我在终端中运行bash ./vendor/bin/sail up时,它都会在docker中创建一个新的容器。我不确定这在docker中是否正常,或者我的docker-composer文件有问题?

我已经添加了一个phpmyadmin服务来访问我本地主机上的数据库。请查看我的docker-composer.yml文件。

version: '3'
services:
    laravel.test:
        build:
            context: ./vendor/laravel/sail/runtimes/8.2
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.2/app
        extra_hosts:
            - 'host.docker.internal:host-gateway'
        ports:
            - '${APP_PORT:-80}:80'
            - '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
        environment:
            WWWUSER: '${WWWUSER}'
            LARAVEL_SAIL: 1
            XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
            XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
        volumes:
            - '.:/var/www/html'
        networks:
            - sail
        depends_on:
            - mysql
    mysql:
        image: 'mysql/mysql-server:8.0'
        ports:
            - '${FORWARD_DB_PORT:-3306}:3306'
        environment:
            MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ROOT_HOST: '%'
            MYSQL_DATABASE: '${DB_DATABASE}'
            MYSQL_USER: '${DB_USERNAME}'
            MYSQL_PASSWORD: '${DB_PASSWORD}'
            MYSQL_ALLOW_EMPTY_PASSWORD: 1
        volumes:
            - 'sail-mysql:/var/lib/mysql'
            - './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
        networks:
            - sail
        healthcheck:
            test:
                - CMD
                - mysqladmin
                - ping
                - '-p${DB_PASSWORD}'
            retries: 3
            timeout: 5s
    phpmyadmin:
        depends_on:
            - mysql
        image: phpmyadmin/phpmyadmin
        environment:
            - PMA_HOST=mysql
            - PMO_PORT=3306
        networks:
            - sail
        ports:
            - 8001:80
networks:
    sail:
        driver: bridge
volumes:
    sail-mysql:
        driver: local
des4xlb0

des4xlb01#

是的,这是正常的,你的合成文件是正确的,当你运行sail up时,这些容器不会在后台运行,当你按下Ctrl+C时,这些容器将终止,然后当你再次运行docker时,创建新的容器。
如果你想在后台运行这些容器,请执行以下操作:

sail up -d

相关问题