我有一個 Dockerfile,它構建 Debian 映像并安裝 Apache、Php、MySql。一般來說,如果我運行 docker 命令:docker build --tag my-project-image:2.0 .進而docker run -dit --name my-project-container \ --mount type=bind,source=$(pwd),destination=/var/www/html \ -p 80:80 --rm my-project-image:2.0我的容器保持運行,并且我開發所需的所有服務都已啟動并運行,因此沒有問題。我嘗試將此配置移至 docker-compose 中,但遇到了奇怪的麻煩。我相信我犯了一個非常常見的錯誤,但我搜索了很多,嘗試了很多東西,但無法使其發揮作用。簡而言之,當我運行docker-compose up構建的映像時,它會創建一個容器,運行所有腳本,并且它會立即存在。問題是我想保持該容器運行,因為我在那里有 Apache 和 MySQL 等服務。我有兩個服務,一個是用于 apache、MySQL 和 PHP 的lamp,另一個是用于運行 npm 腳本的Node 。不幸的是,節點容器保持正常運行,但燈立即關閉。這是我的 DockerfileFROM debian:latestENV DOC_ROOT=/var/www/htmlWORKDIR ${DOC_ROOT}RUN apt-get updateRUN apt-get --assume-yes upgradeRUN apt-get --assume-yes install apache2RUN apt-get --assume-yes install curl php-curlRUN apt-get --assume-yes install phpRUN apt-get --assume-yes install php-mysqlRUN apt-get --assume-yes install composerRUN apt-get --assume-yes install php-xdebugRUN apt-get --assume-yes install default-mysql-serverRUN a2enmod rewriteCOPY ./ ${DOC_ROOT}RUN echo "ServerName localhost" >> /etc/apache2/apache2.confCOPY config/000-default.conf /etc/apache2/sites-available/EXPOSE 80這是我的docker-compose.yaml文件內容version: "3.2"services: lamp: container_name: lamp-stack build: . ports: - 80:80 volumes: - .:/var/www/html command: > /bin/sh -c "service apache2 start && \ service mysql start && \ mysql < migrations/migrations.sql && \ mysql < migrations/development.sql && \ bash" node: container_name: node-builder image: node:12-alpine3.9 depends_on: - lamp working_dir: /var/www/html volumes: - .:/var/www/html command: > /bin/ash -c "npm run build:dev > ./.logs/npm/npm-build.log && \ npm run watch:sass > ./.logs/npm/sass-watch.log"
1 回答
慕桂英4014372
TA貢獻1871條經驗 獲得超13個贊
嘗試在 docker-compose 中添加這些行:
stdin_open: true # equivalent of -i
tty: true # equivalent of -t
- 1 回答
- 0 關注
- 188 瀏覽
添加回答
舉報
0/150
提交
取消
