我试图建立一个使用docker-compose的容器。所以我像下面这样写了dockerfile和docker-compose.yml:
dockerfile
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -y expect
RUN apt-get -y install software-properties-common
RUN apt-add-repository ppa:ondrej/php
RUN apt-get -y install php7.1 php7.1-fpm
RUN apt-get install php7.1-mysql
RUN apt-get -y install nginx
RUN apt-get -y install vim
COPY default /etc/nginx/sites-available/default
COPY www.conf /etc/php/7.1/fpm/pool.d/www.conf
COPY test /var/www/html/test
CMD service php7.1-fpm start && nginx -g "daemon off;"
docker-compose.yml
version: '3'
services:
web:
build:
context: .
dockerfile: Dockerfile
ports:
- "3011:80"
当我运行以下命令时,php7.1-fpm运行成功。
docker-compose build
docker-compose up --force-recreate -d
但是我想将CMD从dockerfile移到docker-compose,所以我如下更改了文件:
docker-compose.yml
command: service php7.1-fpm start && nginx -g "daemon off;"
但是这次php7.1-fpm没有运行。
如何解决此问题,以便我可以在docker-compose.yml中运行php7.1-fpm?
答案 0 :(得分:-1)
service php7.1-fpm start
,因为容器只是一个进程,而不是真正的虚拟机,主进程关闭,其他进程也不会关闭
FROM php:7.2-fpm
RUN docker-php-ext-install pdo pdo_mysql mbstring
docker-compose.yml:
version: '2.1'
services:
nginx:
image: nginx:latest
ports:
- 8001:80
volumes:
- ./:/app
# nginx configs
- ./docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
php-fpm:
build: ./docker/php-fpm
volumes:
- ./:/app
php-composer:
restart: 'no'
image: composer
volumes:
- ./:/app
command: install
nodejs:
restart: 'no'
image: node:8.9
volumes:
- ./:/app
command: /bin/bash -c "cd /app && npm install && npm run prod"
networks:
default: