S
S
Swartex2018-11-14 00:50:03
Docker
Swartex, 2018-11-14 00:50:03

What's wrong with Docker?

There is

Dockerfile
# Для начала указываем исходный образ, он будет использован как основа
FROM php:7.2-fpm
# Необязательная строка с указанием автора образа
MAINTAINER Swartex

# RUN выполняет идущую за ней команду в контексте нашего образа.
# В данном случае мы установим некоторые зависимости и модули PHP.
# Для установки модулей используем команду docker-php-ext-install.
# На каждый RUN создается новый слой в образе, поэтому рекомендуется объединять команды.
RUN apt-get update && apt-get install -y \
        curl \
        wget \
        git \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libmcrypt-dev \
        libpng-dev \
    && docker-php-ext-install -j$(nproc) iconv mbstring zip \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd
# Куда же без composer'а.
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Добавим свой php.ini, можем в нем определять свои значения конфига
ADD php.ini /usr/local/etc/php/conf.d/40-custom.ini

# Указываем рабочую директорию для PHP
WORKDIR /var/www/

# Запускаем контейнер
# Из документации: The main purpose of a CMD is to provide defaults for an executing container. These defaults can include an executable, 
# or they can omit the executable, in which case you must specify an ENTRYPOINT instruction as well.
CMD ["php-fpm"]


And file
docker-compose.yml
# Версия docker-compose
version: '2'
# Список наших сервисов (контейнеров)
services:
    nginx:
        # используем последний стабильный образ nginx
        image: nginx:latest
        # маршрутизируем порты
        ports:
            - "80:80"
            - "443:443"
        # монтируем директории, слева директории на основной машине, справа - куда они монтируются в контейнере
        volumes:
            - ./hosts:/etc/nginx/conf.d
            - ./www:/var/www
            - ./logs:/var/log/nginx
        # nginx должен общаться с php контейнером
        links:
            - php
    php:
        # у нас свой образ для PHP, указываем путь к нему и говорим что его надо собрать
        build: ./images/php
        # этот образ будет общаться с mysql
        links:
            - mysql
        # монтируем директорию с проектами
        volumes:
            - ./www:/var/www
    mysql:
        image: mariadb
        environment:<code></code>
            MYSQL_ROOT_PASSWORD: example
        ports:
            - "3306:3306"
        volumes:
            - ./mysql:/var/lib/mysql
    phpmyadmin:
        image: phpmyadmin/phpmyadmin
        environment:
            PMA_ARBITRARY: 1
            MYSQL_USER: homestead
            MYSQL_PASSWORD: secret
            MYSQL_ROOT_PASSWORD: root
        ports:
            - "8080:80"
        links:
            - "mysql:mysql"


when starting containers, it gives an error:
$ docker-compose up -d
Removing webdev_mysql_1
Recreating e0e98f2b1646_webdev_mysql_1 ... error

ERROR: for e0e98f2b1646_webdev_mysql_1  b'no such image: sha256:2dd01afbe8df1fe326f6609c56b08beefc6bf254d28993263da188b8fbf1254d: No such image: sha256:2dd01afbe8df1fe326f6609c56b08beefc6bf254d28993263da188b8fbf1254d'

ERROR: for mysql  b'no such image: sha256:2dd01afbe8df1fe326f6609c56b08beefc6bf254d28993263da188b8fbf1254d: No such image: sha256:2dd01afbe8df1fe326f6609c56b08beefc6bf254d28993263da188b8fbf1254d'
ERROR: The image for the service you're trying to recreate has been removed. If you continue, volume data could be lost. Consider backing up your data before continuing.

Recreating e0e98f2b1646_webdev_mysql_1 ... error
Recreating e0e98f2b1646_webdev_mysql_1 ...

ERROR: for e0e98f2b1646_webdev_mysql_1  Cannot start service mysql: b"error while creating mount source path '/host_mnt/e/webdev/mysql': mkdir /host_mnt/e: file exists"

ERROR: for mysql  Cannot start service mysql: b"error while creating mount source path '/host_mnt/e/webdev/mysql': mkdir /host_mnt/e: file exists"
ERROR: Encountered errors while bringing up the project.

The folder structure is as follows:
5beb46e09bcd2142118320.png
As an example, I used the article https://phptoday.ru/post/gotovim-lokalnuyu-sredu-d... Is
that what I'm doing wrong?)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
metajiji, 2018-11-15
@metajiji

It's not about the Dockerfile, but about docker-compose
Namely, you seem to have windows, and the problem is with the forwarding of mounts and the integrity of the images. Try to wipe docker and start from scratch :)
ERROR: for mysql Cannot start service mysql: b"error while creating mount source path '/host_mnt/e/webdev/mysql': mkdir /host_mnt/e: file exists"
Forwarding from host (windows) inside a Linux virtual machine is broken. Recreate vm and there will be happiness.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question