簡體   English   中英

Docker 圖像在 docker 運行容器中運行良好,但在 swarm 中運行不佳

[英]Docker image work well in docker run container but not in swarm

我有一個 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

構建圖像:

docker build -t vhost . 

並運行容器:

 docker run -dt -p 8080:80 --name test vhost

一切正常,這是容器日志:

[ 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 

但是當我創建服務時成群結隊:

docker service create -p 8080:80 --name test vhost

服務失敗並重新啟動。 這是服務日志:

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
.
.
.

我怎樣才能使服務運行一次並繼續運行?

好的,我解決了。 當我在容器中啟動 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

這是一個警告,但我認為它返回錯誤狀態和服務失敗。 我把 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM