从Docker Compose内部构建Dockerfile



所以我尝试按照以下说明进行操作:

https://github.com/open-forest/sendy

我正在使用Portainer并尝试运行Sendy容器(时事通讯软件(。我没有用它运行MySQL映像,而是使用我的外部托管数据库。

在我的服务器上,我将项目数据保存在:/var/docker/project-name。如果我需要从一开始就将数据带入容器,我会使用这种结构进行绑定挂载。

因此,对于这个项目,在项目名称文件夹中,我有sendy-6.0.2.zip和这个Dockerfile:(这个文件是通过上面链接上的说明提供的(

#
# Docker with Sendy Email Campaign Marketing
#
# Build:
# $ docker build -t sendy:latest --target sendy -f ./Dockerfile .
#
# Build w/ XDEBUG installed
# $ docker build -t sendy:debug-latest --target debug -f ./Dockerfile .
#
# Run:
# $ docker run --rm -d --env-file sendy.env sendy:latest
FROM php:7.4.8-apache as sendy
ARG SENDY_VER=6.0.2
ARG ARTIFACT_DIR=6.0.2
ENV SENDY_VERSION ${SENDY_VER}
RUN apt -qq update && apt -qq upgrade -y 
# Install unzip cron
&& apt -qq install -y unzip cron  
# Install php extension gettext
# Install php extension mysqli
&& docker-php-ext-install calendar gettext mysqli 
# Remove unused packages
&& apt autoremove -y 
# Copy artifacts
COPY ./artifacts/${ARTIFACT_DIR}/ /tmp
# Install Sendy
RUN unzip /tmp/sendy-${SENDY_VER}.zip -d /tmp 
&& cp -r /tmp/includes/* /tmp/sendy/includes 
&& mkdir -p /tmp/sendy/uploads/csvs 
&& chmod -R 777 /tmp/sendy/uploads 
&& rm -rf /var/www/html 
&& mv /tmp/sendy /var/www/html 
&& chown -R www-data:www-data /var/www 
&& mv /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini 
&& rm -rf /tmp/* 
&& echo "nServerName ${SENDY_FQDN}" > /etc/apache2/conf-available/serverName.conf 
# Ensure X-Powered-By is always removed regardless of php.ini or other settings.
&& printf "nn# Ensure X-Powered-By is always removed regardless of php.ini or other settings.n
Header always unset "X-Powered-By"n
Header unset "X-Powered-By"n" >> /var/www/html/.htaccess 
&& printf "[PHP]nerror_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATEDn" > /usr/local/etc/php/conf.d/error_reporting.ini
# Apache config
RUN a2enconf serverName
# Apache modules
RUN a2enmod rewrite headers
# Copy hello-cron file to the cron.d directory
COPY cron /etc/cron.d/cron
# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/cron 
# Apply cron job
&& crontab /etc/cron.d/cron 
# Create the log file to be able to run tail
&& touch /var/log/cron.log
COPY artifacts/docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["apache2-foreground"]
#######################
# XDEBUG Installation
#######################
FROM sendy as debug
# Install xdebug extension
RUN pecl channel-update pecl.php.net 
&& pecl install xdebug 
&& docker-php-ext-enable xdebug 
&& rm -rf /tmp/pear 

这是我的Docker Compose文件:

version: '3.7'
services:
project-sendy:
container_name: project-sendy
image: sendy:6.0.2
build: 
dockerfile: var/docker/project-sendy/Dockerfile
restart: unless-stopped
networks:
- proxy
- default
labels:
- "traefik.enable=true"
- "traefik.docker.network=proxy"
- "traefik.http.routers.project-secure.entrypoints=websecure"
- "traefik.http.routers.project-secure.rule=Host(`project.com`)"
environment:
SENDY_PROTOCOL: https
SENDY_FQDN: project.com
MYSQL_HOST: db-host-name-here
MYSQL_DATABASE: db-name-here
MYSQL_USER: db-user-name-here
MYSQL_PASSWORD: db-password-here
SENDY_DB_PORT: db-port-here

networks:
proxy:
external: true  

当我尝试部署时,我得到:

failed to deploy a stack: project-sendy Pulling project-sendy 
Error could not find /data/compose/126/var/docker/project-sendy: 
stat /data/compose/126/var/docker/project-sendy: no such file or directory

下面是我所做的。

我的cron和artifacts文件夹与Dockerfile位于同一目录中。在Dockerfile中查找以下行:

COPY artifacts/docker-entrypoint.sh /usr/local/bin/

下面写着:

RUN chmod +x /usr/local/bin/docker-entrypoint.sh

否则你会得到这个错误:

Starting Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/usr/local/bin/docker-entrypoint.sh": permission denied: unknown 

然后用构建

docker build -t sendy:6.0.2 .

然后你的图像将显示在门户中。

然后,您可以删除docker compose文件中的构建部分,然后点击deploy。它现在对我有效。

最新更新