Hi, I am trying to create an environmental variables table that all my dockers can reference.
I am looking at this guide: Setting Up Environmental Variables for Docker and Docker Compose
I am confused on OMV were to put the .env file. Any ideas?
Hi, I am trying to create an environmental variables table that all my dockers can reference.
I am looking at this guide: Setting Up Environmental Variables for Docker and Docker Compose
I am confused on OMV were to put the .env file. Any ideas?
I understand it that the .env file has to be in the folder with the docker-compose file.
The guide placed it in the home folder of the docker user
There’s two different environmental variables in discussion here.
First in yaml the environment keywords generates the lists all ev for the running container.
Second the .env file is loaded previous reading of the compose yaml and sources all variables that are going to be rendered in the yaml file. Those are the dollar sign variables in the compose file. Those variables are not passed to the container. As mentioned before the .env file goes along the compose file in the same folder.
So for example in your running container if you exec bash into it and run echo $MEDIA nothing will output as that was a variable used to construct the yaml file.
Alles anzeigenThere’s two different environmental variables in discussion here.
First in yaml the environment keywords generates the lists all ev for the running container.
Second the .env file is loaded previous reading of the compose yaml and sources all variables that are going to be rendered in the yaml file. Those are the dollar sign variables in the compose file. Those variables are not passed to the container. As mentioned before the .env file goes along the compose file in the same folder.
So for example in your running container if you exec bash into it and run echo $MEDIA nothing will output as that was a variable used to construct the yaml file.
So my question is more, how do we point the container to the .env file? How do we declare the .env? So that the container uses those values.
It doesn't look like this works with portainer. Let me know if think different.
seems like the feature is on its way: https://github.com/portainer/portainer/pull/4175
seems like the feature is on its way: https://github.com/portainer/portainer/pull/4175
It looks like soon too. (Hopefully)
You are fixed on using it with Portainer?
No, but for the videos, everyone likes using the UI. Do you use it?
I almost exclusively use the command line. But in this case the files (docker-compose.yml and .env) can be created with notepad++ and then you only need to run docker-compose up -d in the CLI.
Just to try it out, I just ran a test container:
I have a folder where all my docker-compose files are stored. In this case both are here: /srv/dev-disk-by-label-ssd/users/docker/docker-compose/nginx/
---
version: "2.1"
services:
nginx:
image: linuxserver/nginx
container_name: nginx
environment:
- PUID=${PUID}
- PGID=${PGID}
- TZ=${TZ}
volumes:
- ${BASEDIR}:/config
ports:
- ${HTTP_PORT}:80
- ${HTTPS_PORT}:443
restart: unless-stopped
Alles anzeigen
TZ=Europe/Berlin
PUID=1000
PGID=100
BASEDIR=/srv/dev-disk-by-label-ssd/appdata/nginx/
HTTP_PORT=8082
HTTPS_PORT=4444
then just in /srv/dev-disk-by-label-ssd/users/docker/docker-compose/nginx/ I run docker-compose up -d.
docker inspect nginx:
[...]
"Mounts": [
{
"Type": "bind",
"Source": "/srv/dev-disk-by-label-ssd/appdata/nginx",
"Destination": "/config",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
[...]
"PortBindings": {
"443/tcp": [
{
"HostIp": "",
"HostPort": "4444"
}
],
"80/tcp": [
{
"HostIp": "",
"HostPort": "8082"
}
]
},
[...]
"Env": [
"PUID=1000",
"PGID=100",
"TZ=Europe/Berlin",
[...]
Alles anzeigen
So my question is more, how do we point the container to the .env file? How do we declare the .env? So that the container uses those values.
You can use a mount bind to pass the whole folder to the container that has the .env but what’s the point? The container will not read that file automatically. The .env file is used to store values that are you going to keep repeating inside the yaml file. A compose file can have many different containers, if each of them need access to a common path or using same PUID .env saves the tedious work of changing every string, instead is just changed at .env just once.
Inspired by this thread I continued a project, which I had on my list for some time now. I wanted to put all my docker containers into a single docker-compose file. Just for inspiration these are my docker-compose.yml and my .env. All I need to do is run a docker-compose up -d in the folder containing both files.
UID=1000
GID=100
TZ=Europe/Berlin
APPDIR=/srv/dev-disk-by-label-ssd/appdata
BACKUPDIR=/srv/dev-disk-by-label-ssd/backup
SYNCDIR=/srv/dev-disk-by-label-ssd/sync
RESTART=unless-stopped
version: "2.3"
services:
#################################
#PIHOLE
#
#
pihole:
container_name: pihole
image: pihole/pihole:latest
ports:
- "53:53/tcp"
- "53:53/udp"
- "67:67/udp"
- "80:80/tcp"
- "443:443/tcp"
environment:
TZ: '${TZ}'
WEBPASSWORD: 'myPW'
ServerIP: '192.168.188.201'
IPv6: 'false'
DNS1: '1.1.1.1'
DNS2: 'no'
volumes:
- ${APPDIR}/pihole:/etc/pihole/
- ${APPDIR}/pihole/dnsmasq:/etc/dnsmasq.d/
dns:
- 127.0.0.1
# cap_add:
# - NET_ADMIN
restart: ${RESTART}
networks:
pihole:
ipv4_address: 192.168.188.201
#################################
#BITWARDEN
#
#
bitwarden:
image: bitwardenrs/server:raspberry
container_name: bitwarden
volumes:
- ${APPDIR}/bitwarden:/data
- ${APPDIR}/letsencrypt/log/bitwarden:/log #Logfile is mounted to swag container for fail2ban
environment:
WEBSOCKET_ENABLED: 'true' # Required to use websockets
ADMIN_TOKEN: 'mytoken'
LOG_FILE: 'log/bitwarden.log'
LOG_LEVEL: 'warn'
EXTENDED_LOGGING: 'true'
TZ: '${TZ}'
restart: ${RESTART}
networks:
my-net:
bw_backup:
image: bruceforce/bw_backup:rpi3
container_name: bw_backup
restart: ${RESTART}
depends_on:
- bitwarden
volumes:
- ${APPDIR}/bitwarden:/data/
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
- ${BACKUPDIR}/bitwarden:/backup_folder/ #This is where the db-backup is stored
environment:
- DB_FILE=/data/db.sqlite3
- BACKUP_FILE=/backup_folder/backup.sqlite3
- CRON_TIME=30 2 * * *
- TIMESTAMP=true
- DELETE_AFTER=30
- UID=0
- GID=0
- TZ=${TZ}
network_mode: "none"
#################################
#LETSENCRYPT - SWAG
#
#
swag:
image: linuxserver/swag
container_name: swag
cap_add:
- NET_ADMIN
environment:
- PUID=${UID}
- PGID=${GID}
- TZ=${TZ}
- URL=mydomain
- SUBDOMAINS=mysubdomains
- VALIDATION=http
- EMAIL=myemail
volumes:
- ${APPDIR}/letsencrypt:/config
ports:
- 450:443
- 90:80
restart: ${RESTART}
networks:
my-net:
#################################
#NEXTCLOUDPI
#
#
nextcloudpi:
image: ownyourbits/nextcloudpi-armhf
command: "url_of_my_ncp"
container_name: nextcloudpi
ports:
- "4443:4443"
volumes:
- ${APPDIR}/nextcloudpi:/data
- /etc/localtime:/etc/localtime:ro
- ${SYNCDIR}:/mnt/sync #This folder is mounted as an external storage
- ${BACKUPDIR}/calcardbackup:/ccb #Backups of my calendar and contacts via calcardbackup
- ${BACKUPDIR}/ncp_backup:/ncp_backup #Location where the ncp-backups are stored
restart: ${RESTART}
networks:
my-net:
#################################
#RESILIO_SYNC
#
#
resilio-sync:
image: linuxserver/resilio-sync
container_name: resilio-sync
environment:
- PUID=33
- PGID=33
- TZ=${TZ}
- UMASK_SET=000
volumes:
- ${APPDIR}/resilio-sync:/config
- ${APPDIR}/resilio-sync/downloads:/downloads
- ${SYNCDIR}:/sync
ports:
- 8888:8888
- 55555:55555
logging:
options:
max-size: "50m"
max-file: "1"
restart: ${RESTART}
network_mode: "bridge"
#################################
#PORTAINER
#
#
portainer:
image: portainer/portainer
container_name: portainer
command: -H unix:///var/run/docker.sock
restart: always
ports:
- 9000:9000
- 8000:8000
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ${APPDIR}/portainer:/data
networks:
pihole:
driver: macvlan
driver_opts:
parent: enx001e063676f8
ipam:
driver: default
config:
- subnet: 192.168.188.0/24
gateway: 192.168.188.1
ip-range: 192.168.188.201/32
my-net:
name: my-net
Alles anzeigen
Inspired by this thread I continued a project, which I had on my list for some time now. I wanted to put all my docker containers into a single docker-compose file. Just for inspiration these are my docker-compose.yml and my .env. All I need to do is run a docker-compose up -d in the folder containing both files.
Yes, a man after my own heart. This is also on my list. I was hoping to do this in Portainer, but I will be doing this in compose also. So you put the two files in one folder? Which folder did you put it in, just out of curiosity? User folder or in a share?
I put it in a folder in the home directory of my docker user. But it does not matter where the files are.
The most complex part was getting the Macvlan to run from a compose file. And the consideration in general which container connects to which network. But apart from that very straightforward and easy to scale.
I am going to do this, but just very busy for the next few weeks. I'll be back!
Hello TechnoDad.
I have been following your video to install Nexctloud via Docker on my Raspberry Pi4. It all works until I get to the NC init page where it fails to connect to the Maria database (see screenshot). Do you have any ideas what I could try?
Many thanks
Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!