I want to access a secret file with docker-compose. I follow many tutorials and reproduce the structure. The container is launched but when I need to log in, the right string to enter is "/run/secrets/sec_pgadmin_default_email". I want the login to be the one inside my secret file: admin. In this secret file pgadmin_default_email.txt, there is only the word admin. I don't know if the structure of this file is good. Should it be a dictionary or something else ?
version: '3.8' services: pgadmin4:
build:
context: ./dockerfiles/
dockerfile: dockerfile_pgadmin4
image: img_pgadmin
container_name: cont_pgadmin4
ports:
- "80:80"
secrets:
- sec_pgadmin_default_email
- sec_pgadmin_default_password
environment:
- PGADMIN_LISTEN_PORT=80
- PGADMIN_DEFAULT_EMAIL=/run/secrets/sec_pgadmin_default_email
- PGADMIN_DEFAULT_PASSWORD=/run/secrets/sec_pgadmin_default_password
secrets:
sec_pgadmin_default_email:
file: ./.secrets/pgadmin_default_email.txt
sec_pgadmin_default_password:
file: ./.secrets/pgadmin_default_password.txt
PS I just use the command docker-compose up -d, without swarn things or else. I don't define external secrets and I prefer not. Is it possible ?
the environment variable will be set to the path of the file containing the actual value. Not the actual value itself.
For example, in Go you could do something like:
var pgAdminDefaultEmailFile = os.Getenv("PGADMIN_DEFAULT_EMAIL") // get the file
pgAdminDefaultEmailValue, err := ioutil.ReadFile(pgAdminDefaultEmailFile) // get the value
if err != nil {
log.Fatal(err)
}
pgAdminDefaultEmail = string(pgAdminDefaultEmailValue) // parse out the value
Related
I have a regular docker-compose.yml
version: "3.9"
services:
test_service:
image: some_img:0.1.0
...
...
env_file:
- .env
...
...
here, I am loading environment variables using a .env file. In the file I have an environment variable with a long string value.
# .env
SPACE=test
SPECIFICS=packageA,packageB,packageC,packageD,...
I want SPECIFICS to parsed as above(SPECIFICS=packageA,packageB,packageC,packageD,... ) but would like to break it down into multiple lines for easy reading, may be like below (with or without indentation)
SPECIFICS=packageA,
packageB,
packageC,
packageD,
...
I do not want to use environment: section in docker-compose.yml because I am loading quite a few environment variables which will bloat the corresponding section.
Can anyone suggest a solution for this
CHeers,
DD.
It seems when my docker compose yml is run via "az containerapp compose create", environment variables are not picked up. Is there a way I can set an env variable so the command picks it up?
I'm seeing this error:
ERROR: The following field(s) are either invalid or missing. Invalid value: "${DOCKER_REGISTRY-}/sample-blazorapp": could not parse reference: ${DOCKER_REGISTRY-}/sample-blazorapp: template.containers.blazorapp.image.
I have set the variable with: export DOCKER_REGISTRY="myregistry"
And when I echo $DOCKER_REGISTRY, the value is returned. So in the bash session it is set (I tried powershell first, I thought that was the issue because $(envvar-) is bash syntax, however the error is the same.)
This is what I have in my compose file (alignment is correct in the file):
blazorapp:
container_name: "blazorapp"
image: ${DOCKER_REGISTRY-}sample-blazorapp
build:
context: .
dockerfile: BlazorApp/BlazorApp/Dockerfile
depends_on:
- redis
ports:
- "55000:443"
If I explicitly set the image name, i.e. not use an env var, then it works. i.e. this change to the image line works:
image: myregistry/sample-blazorapp
I also tried adding the forward slash, this makes no difference (as expected, it works fine without the slash when running docker compose up).
I can set it explicitly but that would be annoying. I feel like I'm missing something. Any help or guidance is greatly appreciated :)
If the image is defined like this into you docker compose file:
image: ${DOCKER_REGISTRY-}sample-blazorapp
then you must export using a slash at the end of the value:
export DOCKER_REGISTRY="myregistry/"
I discovered the issue, I was missing a colon.
Does not work (produces the error described in the question):
image: ${DOCKER_REGISTRY-}sample-blazorapp
Also does not work:
image: ${DOCKER_REGISTRY-mydefault}sample-blazorapp
Add the magic : in and it works:
image: ${DOCKER_REGISTRY:-}sample-blazorapp
Also works:
image: ${DOCKER_REGISTRY:-mydefault}sample-blazorapp
I'm trying to setup selenoid and I'm having trouble with dockercomposer, it throws exception as below:
yaml.parser.ParserError: while parsing a flow mapping in "./docker-compose.yml", line 1, column 1 expected ',' or '}', but got '{' in "./docker-compose.yml", line 2, column 1
when I try to run docker command "$ sudo docker-compose up -d"
I'm in the terminal with same folder where docker-compose.yml present and content is as below,
version: '3'
services:
selenoid:
network_mode: bridge
image: aerokube/selenoid
volumes:
- "/docker:/etc/selenoid"
- "/var/run/docker.sock:/var/run/docker.sock"
- "/docker/video:/opt/selenoid/video"
environment:
- OVERRIDE_VIDEO_OUTPUT_DIR=/opt/selenium/video
- TZ=Europe/Amsterdam
command: ["-conf", "/etc/selenoid/browsers.json", "-video-output-dir", "/opt/selenoid/video"]
ports:
- "4444:4444"
I've also tried many online yml parsers and there is nothing wrong with yml file. Any help would be much appreciated.
Thanks
Sorry being late to answer my own post, there was nothing wrong with YML file, I should have created/edited it using programming editors such as IntelliJ, but I was editing and saving it using EditText. All worked fine after editing them and saving using IntelliJ in mac.
I have the following in my Dockerfile:
. . .
ENV SSL_PORT=443
. . .
EXPOSE ${SSL_PORT}
. . .
And the following in a docker-compose.override.yml file calling that image:
environment:
SSL_PORT: $SSL_PORT
ports:
- "${SSL_PORT}:${SSL_PORT}"
If I do that
WARNING: The SSL_PORT variable is not set. Defaulting to a blank string.
ERROR: The Compose file '.\docker-compose.override.yml' is invalid because:
services.ssl.ports contains an invalid type, it should be a number, or an object
If I set it in the .env file, the container is built.
Is there any way I can set the value of SSL_PORT in docker-compose.override.yml AND use that same value?
There are only two ways to set value of SSL_PORT variable into docker-compose.override.yml:
1. Declaring default environment variables in an environment file named .env placed in the folder where the docker-compose command is executed.
2. Add SSL_PORT variable into environment variables when you execute docker-compose command. It would be either:
SSL_PORT=443 docker-compose -f docker-compose.override.yml up
or
export SSL_PORT=443
docker-compose -f docker-compose.override.yml up
Example:
my-server:
image: my-server:latest
ports:
- 1234:1234
proxy:
image: lb:latest
environment:
- BACKEND=${VAR}??? # must be resolve as 'my-server'
The server name can be changed to any name, but the proxy has a entry-point script where the variable will be substituted in the BACKEND to config.
You can use a .env file to define your variable. This file will be placed in the same directory as your docker-compose.yml file.
When you run docker-compose, it will read this value and use it. Using your example, your .env file would look something like this:
VAR=my-server
and, the line:
- BACKEND=${VAR}??? # must be resolve as 'my-server'
would become just:
- BACKEND=${VAR}
or
BACKEND: ${VAR}