我在本地克隆了 drupal 项目。
我有一个 Docker 桌面应用程序。
所以我在命令提示符下运行
docker-compose up -d
。
docker-compose.yml:
services:
mariadb:
image: wodby/mariadb:$MARIADB_TAG
container_name: "${PROJECT_NAME}_mariadb"
stop_grace_period: 30s
environment:
MYSQL_ROOT_PASSWORD: $DB_ROOT_PASSWORD
MYSQL_DATABASE: $DB_NAME
MYSQL_USER: $DB_USER
MYSQL_PASSWORD: $DB_PASSWORD
volumes:
- ./mariadb-init:/docker-entrypoint-initdb.d # Place init .sql file(s) here.
# - /path/to/mariadb/data/on/host:/var/lib/mysql # Use bind mount
php:
image: wodby/drupal-php:$PHP_TAG
container_name: "${PROJECT_NAME}_php"
environment:
SSMTP_MAILHUB: mailhog:1025
PHP_SENDMAIL_PATH: '"/usr/bin/dos2unix -u | /usr/sbin/ssmtp -t -f"'
volumes:
- ./:/var/www/html:cached
## Alternative for macOS users: Mutagen https://wodby.com/docs/stacks/drupal/local#docker-for-mac
# - drupal:/var/www/html
## For XHProf and Xdebug profiler traces
# - files:/mnt/files
crond:
init: true
image: wodby/drupal-php:$PHP_TAG
container_name: "${PROJECT_NAME}_crond"
environment:
CRONTAB: "0 * * * * drush -r /var/www/html/web cron"
command: sudo -E crond -f -d 0
volumes:
- ./:/var/www/html:cached
## Alternative for macOS users: Mutagen https://wodby.com/docs/stacks/drupal/local#docker-for-mac
# - drupal:/var/www/html
nginx:
image: wodby/nginx:$NGINX_TAG
container_name: "${PROJECT_NAME}_nginx"
depends_on:
- php
environment:
NGINX_STATIC_OPEN_FILE_CACHE: "off"
NGINX_ERROR_LOG_LEVEL: error
NGINX_BACKEND_HOST: php
NGINX_SERVER_ROOT: /var/www/html/web
NGINX_VHOST_PRESET: $NGINX_VHOST_PRESET
# NGINX_DRUPAL_FILE_PROXY_URL: http://example.com
volumes:
- ./:/var/www/html:cached
ports:
- "8000:80"
但是我无法运行
drush cim
命令。
使用 docker 时应该在哪里运行此命令。
当我在浏览器上访问 localhost:8000 时,我可以看到这个页面。
docker-compose
命令必须引用您的docker-compose.yml
中列出的服务。您收到有关服务“drupal”未运行的错误的原因是因为您的 drupal
中没有名为 docker-compose.yml
的服务。看来您想要的服务叫做php
。因此,请尝试docker-compose exec php bash
。