我正在创建我的Typo3开发实例与docker容器。为了理解我在做什么,所以我可以完全理解我的工作流程,我试图保持简单,一步一步地去一个更高级的实例。这是我的docker-compose文件。
这个挂载的卷很好,它们正在被挂载,它们的权限是root权限。
我所做的是进入容器内部,将用户和组设置为www-data,以便从浏览器访问这些文件,然后在主机上将我的用户设置为所有者,以便我可以从主机编辑它们。
但这是正确的吗?这是正确的方法吗?因为我见过一些脚本,你所需要做的就是在容器内设置www-data,所以我想知道为什么我的情况下的权限是root。
version: "3"
services:
typo3:
build: .
ports:
- "80:80"
volumes:
- ./fileadmin:/var/www/html/fileadmin
- ./typo3conf:/var/www/html/typo3conf
- ./uploads:/var/www/html/uploads
networks:
- backend
database:
image: mysql:8.0
command:
- --character-set-server=utf8
- --collation-server=utf8_unicode_ci
environment:
- "MYSQL_USER=${MYSQL_USER}"
- "MYSQL_PASSWORD=${MYSQL_PASSWORD}"
- "MYSQL_DATABASE=${MYSQL_DATABASE}"
- "MYSQL_RANDOM_ROOT_PASSWORD=${MYSQL_ROOT}"
networks:
- backend
volumes:
database:
fileadmin:
typo3conf:
uploads:
networks:
backend:
Dockerfile:
# Docker image for TYPO3 CMS
# Copyright (C) 2016-2020 Martin Helmich <martin@helmich.me>
# and contributors <https://github.com/martin-helmich/docker-typo3/graphs/contributors>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
FROM php:7.4-apache-buster
LABEL maintainer="Martin Helmich <typo3@martin-helmich.de>"
# Install TYPO3
RUN apt-get update &&
apt-get install -y --no-install-recommends
wget
# Configure PHP
libxml2-dev libfreetype6-dev
libjpeg62-turbo-dev
libmcrypt-dev
libpng-dev
libpq-dev
libzip-dev
zlib1g-dev
# Install required 3rd party tools
graphicsmagick &&
# Configure extensions
docker-php-ext-configure gd --with-libdir=/usr/include/ --with-jpeg --with-freetype &&
docker-php-ext-install -j$(nproc) mysqli soap gd zip opcache intl pgsql pdo_pgsql &&
echo 'always_populate_raw_post_data = -1nmax_execution_time = 240nmax_input_vars = 1500nupload_max_filesize = 32Mnpost_max_size = 32M' > /usr/local/etc/php/conf.d/typo3.ini &&
# Configure Apache as needed
a2enmod rewrite &&
apt-get clean &&
apt-get -y purge
libxml2-dev libfreetype6-dev
libjpeg62-turbo-dev
libmcrypt-dev
libpng-dev
libzip-dev
zlib1g-dev &&
rm -rf /var/lib/apt/lists/* /usr/src/*
RUN cd /var/www/html &&
wget -O download.tar.gz https://get.typo3.org/10.4.19 &&
echo "8eb40d02954ffe431c8a41420e4d73d9e0a702714960ecca89162d87ca0e4118 download.tar.gz" > download.tar.gz.sum &&
sha256sum -c download.tar.gz.sum &&
tar -xzf download.tar.gz &&
rm download.* &&
ln -s typo3_src-* typo3_src &&
ln -s typo3_src/index.php &&
ln -s typo3_src/typo3 &&
cp typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/root-htaccess .htaccess &&
mkdir typo3temp &&
mkdir typo3conf &&
mkdir fileadmin &&
mkdir uploads &&
touch FIRST_INSTALL &&
chown -R www-data. .
# Configure volumes
VOLUME /var/www/html/fileadmin
VOLUME /var/www/html/typo3conf
VOLUME /var/www/html/typo3temp
VOLUME /var/www/html/uploads
有很多方法可以做到这一点,对我来说,我通常使用下面两个选项:
- 使用
docker exec -it $your_container_name /bin/bash
进入容器,在容器中安装vim或nano。 - 现代IDE/编辑器提供了对容器的直接访问,所以你可以在容器中开发/编辑文件,就像你在本地做一样。例如,VSCode提供了"远程容器插件",启用它后,您可以在您的主机pc上开发容器中的文件。详细信息请参考在容器内开发