我在下面有 Dockerfile 和 compose 文件。在 dockerfile 中,如果还没有应用程序,我会创建一个新的 symfony 应用程序。当我运行
docker compose build --build-arg CREATE_APP=true --no-cache --pull
时,该过程运行良好。
但是当我运行 docker compose up -d
然后因为我的 ./app/ 文件夹在主机上是空的,/var/www/html
的内容在容器中被删除。
我怎样才能防止这种情况发生?也许整个方法都不正确。我应该在容器运行后创建应用程序吗?
# syntax=docker/dockerfile:1.4
FROM php:8.2.3-fpm-alpine
ARG TIMEZONE
ARG SYMFONY_VERSION=6.*
ARG CREATE_APP=false
ARG GIT_USER_NAME
ARG GIT_USER_EMAIL
RUN apk add --no-cache \
bash \
acl \
fcgi \
file \
gettext \
git \
unzip \
;
ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && \
install-php-extensions gd xdebug intl pdo_mysql zip opcache apcu @composer
# Set timezone
RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone \
&& printf '[PHP]\ndate.timezone = "%s"\n', ${TIMEZONE} > /usr/local/etc/php/conf.d/tzone.ini \
&& "date"
COPY --link xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
COPY --link ./php.ini /usr/local/etc/php/conf.d/docker-php-config.ini
RUN curl -sS https://get.symfony.com/cli/installer | bash \
&& mv /root/.symfony5/bin/symfony /usr/local/bin
# Install symfony if required
ENV COMPOSER_ALLOW_SUPERUSER=1
RUN set -eux; \
if [ "${CREATE_APP}" = "true" ]; then \
# composer create-project symfony/skeleton:${SYMFONY_VERSION} . --stability=stable; \
# composer require webapp; \
git config --global --add safe.directory /var/www/html; \
git config --global user.name ${GIT_USER_NAME} ; \
git config --global user.email ${GIT_USER_EMAIL}; \
symfony new . --webapp; \
fi
WORKDIR /var/www/html
version: '3'
services:
php:
build:
context: ./docker/php
args:
TIMEZONE: ${TIMEZONE}
username: ${username}
GIT_USER_NAME: ${GIT_USER_NAME}
GIT_USER_EMAIL: ${GIT_USER_EMAIL}
depends_on:
- db
networks:
- backend
volumes:
- ./app/:/var/www/html
• 如何修复docker在ubuntu上docker-compose后进入重启状态的问题?
• 当这个图像没有被使用时,如何修复 docker-compose no such image latest?
• 如何从我的主机卷曲在 Docker 容器中运行的服务器?
• 无法在 docker-compose 中给定的端口上在浏览器中打开本地主机
• 如何在 Nginx 中使用多个 docker-compose 副本
• docker compose / spring boot |错误:无法访问 jarfile app.jar
• 如何使用docker-compe.yml运行init.sql?
• 如何在postgress docker容器上执行init.sql?
• 如何在容器执行的脚本调用 exit() 后退出“docker run”容器
• 在 docker 容器中创建与 mysql 的新连接(vagrant/windows 10/virtualbox)
• 在docker容器中运行nginx导致bind() to 0.0.0.0:80 failed (98: Unknown error)