M
M
Maxim Medvedev2019-01-08 10:32:53
Docker
Maxim Medvedev, 2019-01-08 10:32:53

How to build docker correctly?

Good afternoon,
I decided to try docker at work. I installed docker and docker-compose without problems, I have ubuntu 18.04.
I looked at the articles, compiled my config, it doesn’t work, this is what I got:
docker-compose.yml

# Версия docker-compose
version: '3'
# Список наших сервисов (контейнеров)
services:
    apache:
        image: httpd:latest
        volumes:
            - ./www:/var/www/html
            - ./httpd/httpd.conf:/usr/local/apache2/conf/httpd.conf
        depends_on:
            - php
        
    nginx:
        image: nginx:latest
        # маршрутизируем порты
        ports:
            - "81:81"
        # монтируем директории, слева директории на основной машине, справа - куда они монтируются в контейнере
        volumes:
            - ./www:/var/www/html
           - ./nginx/nginx.conf:/etc/nginx/nginx.conf
        depends_on: 
            - apache

    php:
        # у нас свой образ для PHP, указываем путь к нему и говорим что его надо собрать
        build: ./images/php
        # этот образ будет общаться с mysql

        # монтируем директорию с проектами
        volumes:
            - ./www:/var/www/html
            - ./images/php/php.ini:/usr/local/etc/php/php.ini
        depends_on:
            - mariadb

    mariadb:
        image: mariadb:latest
        volumes:
            - ./mariadb:/var/lib/mysql
        environment:
            MYSQL_ROOT_PASSWORD: qwerty

    phpmyadmin:
        image: phpmyadmin/phpmyadmin
        links: 
            - mariadb:db
        ports:
            - 8765:81
        environment:
            MYSQL_ROOT_PASSWORD: qwerty
        depends_on:
            - mariadb

    redis:
        image: redis:latest

for nginx, I had to write port 81, because when I tried to build, I got an error that 80 was already listening. I plan to store configs for different sites in the /nginx folder:
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       81;
        server_name  test.loc;

        location ~ \.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {
            root /var/www/html;
        }

        location ~ /\.ht {
            deny  all;
        }

        location / {
            proxy_pass http://apache;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_connect_timeout 120;
            proxy_send_timeout 120;
            proxy_read_timeout 180;
        }
    }
}

dockerfile:
FROM php:7.2-apache
RUN apt-get update
RUN docker-php-ext-install pdo pdo_mysql mysqli

Total, does not work and I can not find the error already.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2019-01-08
@q2digger

you have an Apache container falling down, and dragging the rest with it.
get them to work separately for you, and after that use docker-compose.
Well, you don't need to relocate nginx to port 81. you just map port 80 of the container to port 81 of the host.
- 80:81

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question