[英]Docker image work well in docker run container but not in swarm
I have a Dockerfile:我有一个 Dockerfile:
FROM php:7.2-apache
COPY ./mysql-init.sh /etc/
RUN apt-get update && apt-get install -y \
mariadb-server \
mariadb-client \
&& docker-php-ext-install mysqli && docker-php-ext-enable mysqli && \
chmod +x /etc/mysql-init.sh && /etc/init.d/mysql start && /etc/mysql-init.sh
COPY ./public-html/ /var/www/html/
CMD service mysql start && service apache2 start && bash
Build image with:构建图像:
docker build -t vhost .
and run container with:并运行容器:
docker run -dt -p 8080:80 --name test vhost
every thing work well and this is the container log:一切正常,这是容器日志:
[ ok ] Starting MariaDB database server: mysqld.
[....] Starting Apache httpd web server: apache2ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
. ok
but in swarm when i create a service with:但是当我创建服务时成群结队:
docker service create -p 8080:80 --name test vhost
service failed and restart again.服务失败并重新启动。 This is the service log:这是服务日志:
test.1.5ywz5uq6p9qc@docker-VirtualBox | Starting MariaDB database server: mysqld.
test.1.5ywz5uq6p9qc@docker-VirtualBox | ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
test.1.5ywz5uq6p9qc@docker-VirtualBox | AH00557: apache2: apr_sockaddr_info_get() failed for 58ff827d9d51
test.1.5ywz5uq6p9qc@docker-VirtualBox | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
.
.
.
test.1.vvd65rc7xxco@docker-VirtualBox | Starting Apache httpd web server: apache2.
test.1.u5nepc5a1jib@docker-VirtualBox | Starting MariaDB database server: mysqld.
test.1.u5nepc5a1jib@docker-VirtualBox | ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
test.1.u5nepc5a1jib@docker-VirtualBox | AH00557: apache2: apr_sockaddr_info_get() failed for 1cd85211c4a7
test.1.u5nepc5a1jib@docker-VirtualBox | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
.
.
.
how can i make service run once and keep running?我怎样才能使服务运行一次并继续运行?
Ok i solve it.好的,我解决了。 when i start apache service in container it return this warning:当我在容器中启动 apache 服务时,它返回此警告:
test.1.5ywz5uq6p9qc@docker-VirtualBox | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
and this is a warning but i think it return error status and service failed.这是一个警告,但我认为它返回错误状态和服务失败。 i change Dockerfile to this and problem solved:我把 Dockerfile 改成这个,问题就解决了:
FROM php:7.2-apache
COPY ./mysql-init.sh /etc/
RUN apt-get update && apt-get install -y \
mariadb-server \
mariadb-client \
&& docker-php-ext-install mysqli && docker-php-ext-enable mysqli && \
chmod +x /etc/mysql-init.sh && /etc/init.d/mysql start && /etc/mysql-init.sh
COPY ./public-html/ /var/www/html/
CMD service mysql start ; service apache2 start ; sleep infinity
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.