I
I
Islam Ibakaev2019-08-19 04:07:18
Docker
Islam Ibakaev, 2019-08-19 04:07:18

Why is the .env folder mounted instead of the .env file when trying to host Octobercms on docker?

Goodnight. I want to raise this cms through docker, I found a turnip
. I used this docker-compose.yml

#docker-compose.yml
version: '2.2'
services:
  web:
    image: aspendigital/octobercms:latest
    init: true
    restart: always
    ports:
      - 80:80
    environment:
      - TZ=Europe/Moscow
    volumes:
      - ./.env:/var/www/html/.env
      - ./plugins:/var/www/html/plugins
      - ./storage/app:/var/www/html/storage/app
      - ./storage/logs:/var/www/html/storage/logs
      - ./themes:/var/www/html/themes
  mysql:
    image: mysql:5.7
    ports:
      - 3306:3306
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=octobercms

I run the configuration and get an error

Starting 71128a7f7e03_october_web_1 ... error
ERROR: for 71128a7f7e03_october_web_1 Cannot start service web: OCI runtime create failed: container_linux.go:345: starting container process caused "process_linux.go:430: container init caused \"rootfs_linux.go:58: mounting \ \\"/home/devellopah/projects/october/.env\\\" to rootfs \\\"/var/lib/docker/overlay2/f03809fe2b8b7517227a731122a2b22569cad1014295a15a40e73d62c0989b3d/merged\\\" at \\\"/var/lib/ docker/overlay2/f03809fe2b8b7517227a731122a2b22569cad1014295a15a40e73d62c0989b3d/merged/var/www/html/.env\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice versa)? Check if the specified host path exists and is the expected type
ERROR: for web Cannot start service web: OCI runtime create failed: container_linux.go:345: starting container process caused "process_linux.go:430: container init caused \"rootfs_linux.go:58: mounting \\\"/home/ devellopah / projects / october / .env \\\ "to rootfs \\\" / var / lib / docker / overlay2 / f03809fe2b8b7517227a731122a2b22569cad1014295a15a40e73d62c0989b3d / merged \\\ "at \\\" / var / lib / docker / overlay2 / f03809fe2b8b7517227a731122a2b22569cad1014295a15a40e73d62c0989b3d / merged/var/www/html/.env\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
ERROR: Encountered errors while bringing up the project.

the author in the readme file says:

On image build, a default .env is created...

So how do I "pull" the .env file out of the container so I can edit it without having to go into the container itself?
This volume does not do what is expected
- ./.env:/var/www/html/.env
------------------------------------ --------------
os - linux mint 19.1 Tessa
Docker version 19.03.1, build 74b1e89
docker-compose version 1.24.0, build 0aa59064

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrew, 2019-08-19
@devellopah

Because .env is connected like this

version: "3.5"
services:
  db:
    build:
      context: ./docker
      dockerfile: postgresql.Dockerfile
    env_file:
      - .env
    restart: always
    volumes:
      - postgres:/var/lib/postgresql/data
    ports:
      - "127.0.0.1:5432:5432"
  redis:
    env_file:
      - .env
    restart: always
    image: redis:3.0
    expose:
      - "6379"

The .env file is usually (always) not placed in a container, rather, on the contrary, it is avoided in every possible way,
because it stores sensitive information, usually these are various tokens, etc.
Storing something like this in a repository is bad form. But you can store some example.env
as a sample.
In this image , the .env file is created automatically when the image is built and contains one single line.
Here's the command it's made from:
If you take a close look at the README, you'll see what it says about it.
In addition, the author recommends mounting the .env file from outside, or copying it to the container (which is a common practice)
The Readme says:
Database credentials and other sensitive information should not be committed to the repository. Those required settings should be outlined in .env.example
Passing environment variables via Docker can be problematic in production. A phpinfo() call may leak secrets by outputting environment variables. Consider mounting a .env volume or copying it to the container directly.

To be honest, your desire to edit .env in the container itself is not clear, instead of forwarding it inside.

P
Pavel Lovtsevich, 2019-08-19
@lautsevich

Try octobercms-docker-starter-kit .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question