Ctrl + C后杀死Docker容器

时间:2019-01-08 16:36:33

标签: docker ubuntu docker-compose

我有一个nginx和php-fpm容器。 当我在projet的php容器中并且执行任何需要时间的命令(例如vendor / bin / behat或composer update)时,我单击CTRL + C。我从容器中弹出。我不知道为什么。当我在不执行命令的情况下单击CTRL + C时,我没有问题。

有什么想法吗?

这是我的docker-compose.yml文件:

version: '3'

services:
    nginx:
        image: nginx:latest
        restart: always
        ports:
            - "80:80"
        volumes:
            - ./nginx/conf:/etc/nginx/custom_conf
            - ./nginx/hosts:/etc/nginx/conf.d/
            - ./nginx/nginx.conf:/etc/nginx/nginx.conf
            - ./logs/nginx:/var/log/nginx
            - ..:/var/www
        networks:
            my_network:
                ipv4_address: 10.5.0.31

    web:
        build: .
        restart: always
        ports:
            - "9000:9000"
            - "5001:5001"
        volumes:
            - ./php/php.ini:/usr/local/etc/php/conf.d/30-php.ini
            - ./php/app2.conf:/usr/local/etc/php/conf.d/app2.conf
            - ./keys/:/var/www/.ssh
            - ./custom-hosts:/etc/custom-hosts
            - ..:/var/www
            - ./supervisor/supervisord.conf:/etc/supervisor/supervisord.conf
            - ./supervisor/conf/:/etc/supervisor/conf.d/
        networks:
            my_network:
                ipv4_address: 10.5.0.20
        tty: true

    db:
        build: mysql
        restart: always
        ports:
            - "3306:3306"
        volumes:
            - ./logs/mysql:/var/log/mysqld.log
            - ./mysql/sql:/var/dumps
            - data:/var/lib/mysql
        environment:
            - MYSQL_ROOT_PASSWORD=root
            - MYSQL_USER=root
            - MYSQL_PASSWORD=root
        networks:
            my_network:
                ipv4_address: 10.5.0.23

volumes:
    data:
        driver: local

networks:
    my_network:
        driver: bridge
        ipam:
            config:
                - subnet: 10.5.0.0/16

我的php-fpm Dockerfile:

FROM php:7.1-fpm

WORKDIR /var/www

RUN apt-get update && apt-get install -y wget git vim sudo unzip apt-utils
RUN apt-get install -y gnupg
RUN apt-get update


### composer
RUN cd /usr/src
RUN curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

# xdebug
RUN pecl install xdebug-2.5.0 \
    && docker-php-ext-enable xdebug

### php extension
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
RUN apt-get clean && apt-get update && apt-get -y --fix-missing install libfreetype6-dev \
    libjpeg62-turbo-dev \
    libmcrypt-dev \
    libpng-dev \
    libicu-dev \
    libxml2-dev \
    g++ \
    zlib1g-dev

RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install -j$(nproc) gd
RUN docker-php-ext-install exif
RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-configure intl
RUN docker-php-ext-install intl
RUN apt-get install -y libzip-dev
RUN docker-php-ext-install zip

### main
RUN usermod -u 1000 www-data
RUN chmod -R 777 /var/www/
RUN chown -R www-data:www-data /var/www
ADD bash_profile /var/www/.bash_profile
ADD script.sh /usr/bin/script.sh
RUN chmod 755 /usr/bin/script.sh

CMD ["bin/bash"]

ENTRYPOINT ["script.sh"]

EXPOSE 9000

还有我的script.sh:

#! /bin/bash

php-fpm &
echo "Serveur de développement Cartesia Education"

cat /etc/custom-hosts >> /etc/hosts

dpkg-reconfigure -f noninteractive tzdata
echo "LC_TIME=fr_FR.utf8" >> /etc/environment

service supervisor start

exec su -l www-data -s /bin/bash

谢谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您是否尝试过以分离模式(-d选项)运行容器?

> docker run -d [CONTAINER-NAME]

这将导致容器在后台运行。您仍然可以通过以下方式将SSH SSH到正在运行的容器中:

> docker exec -it [CONTAINER-NAME] bash

一次退出容器不会终止它。