Please tell me how you can pass environment variables to the VUE application from the docker-compose.yml file. For some reason, after the yarn build command in .gitlab-ci.yml, the application sees only env variables that are written in the "env.production" file
My docker-compose.yml
version: "3.7"
services:
develop_dashboard_frontend:
image: some_image:latest
container_name: develop_dashboard_frontend
environment:
VUE_APP_API_URL: "some_api_URL"
ports:
- "127.0.0.1:8016:80"
restart: always
Any ideas?
You will need to put dashes (-) before each environment variable you want to specify, like you did it with ports in your example.
Refer to: https://docs.docker.com/compose/environment-variables/
$ cat docker-compose.yml
version: '3'
services:
api:
image: 'some_image:tag'
environment:
- VARIABLE_NAME=variable_value
You also need to distinguish between build time and runtime environment variables.
You can supply environment variables for your build, but that might not be saved for the runtime. It really depends on your build (I'm not familiar with yarn build).
However, I recommend using supplying the env variables for run time.
Just define them in the yaml as you tried.
Using $ docker stack deploy or docker-compose up it should work.
Related
This is a working code when I only need Docker:
build_stage:
stage: build
image: docker:20.10.16 # This is mandatory to use Docker
services:
- docker:20.10.16-dind
script:
- docker push $MY_IMAGE # This code works
On another stage, I need to use another image:
deploy_stage:
stage: deploy
image: google/cloud-sdk:latest # Another image, so I can not specify here "docker"
services:
- docker:20.10.16-dind # This line is useless because there is no "docker" image
script:
- docker pull $MY_IMAGE # This code not working because there is no Docker
I use another image for the stage, but I also need Docker.
How can I use Docker in my CI stage?
I've found that I do not need to use image: docker to use Docker, but I must to specify variables then:
deploy_stage:
stage: deploy
image: google/cloud-sdk:latest # Note that I do not use Docker. I use another image.
services:
- docker:20.10.16-dind
variables:
# This is mandatory if you did not use `image: docker`
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
script:
- docker pull $MY_IMAGE # This works
About variables you may read at official documentation.
I have a Laravel sail project but when I type sail command there is no reaction in console.
Only sail up and sail down work fine but other commands like sail shell, sail artisan ***, sail php -v ......donn`t response. No error and no any response.
I wonder what happened?
If you renamed the laravel.test service to something else you may also set the APP_SERVICE variable in your .env file to match whatever you renamed it to, this will also work!
.docker-compose.yml
services:
app.test:
build:
context: ./vendor/laravel/sail/runtimes/8.0
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.0/app
ports:
- '${APP_PORT:-80}:80'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mysql
- redis
- selenium
.env
APP_SERVICE=app.test
Ok I know why. I have changed the name laravel.test in docker-compose.yml for a new name and it not worked. When I changed back it works again.
You can define an ENV variable APP_SERVICE with the value same as you changed for laravel.test in docker-compose.file.
I've configured IntelliJ to use python via a stack I've defined in docker-compose. I'm configured my project to execute my pytest via docker-compose so that I can use the debugger. However, I've discovered that after the initial run, when I change my code and re-run my tests, pytest is not seeing my changes, but rather executing a cached version of the code.
The only way I've discovered to get around this is to invoke the File menu option Invalidate Caches and Restart. This is annoying.
This my compose file:
networks:
app: {}
services:
item-set-definitions:
build:
context: /Users/kudrykma/ghoildex/kudrykma/analytics/sa-item-set-definitions
target: build
command:
- /bin/bash
image: item-sets:test
networks:
app: {}
volumes:
- source: /Users/kudrykma/ghoildex/kudrykma/analytics/sa-item-set-definitions
target: /project
type: bind
version: '3.9'
In the pytest Run configuration I've tried adding -force-recreate option in the docker-compose Command and options field but IntelliJ won't recognize it.
Does anyone know how I can configure IntelliJ to not cache any of my source file so that pytest will see my changed code?
Thank you
I setup drone.io instance locally and use it as our CI environment. I need to setup the docker container memory for running my test cases. Below is my .drone.yml file.
pipeline:
build:
image: centor
commands:
- mvn clean install
Is there a way for me to set the maximum memory in the docker container?
The .drone.yml file is a superset of the docker-compose file and supports the mem_limit field [1]
pipeline:
build:
image: golang
commands:
- go build
- go test
mem_limit: 1000000000
Note that this field is only available in Drone version 0.5 and higher. So unfortunately it is not backported to older versions of Drone.
[1] https://docs.docker.com/compose/compose-file/#/cpushares-cpuquota-cpuset-domainname-hostname-ipc-macaddress-memlimit-memswaplimit-oomscoreadj-privileged-readonly-restart-shmsize-stdinopen-tty-user-workingdir
I'm trying to find a more DRY way to use docker-compose env.
docker-compose-base.yml
base:
image: reactjs_web
volumes:
- src:/reactjs/src
- bin/server:/reactjs/bin/server
- config:/reactjs/config
docker-compose-prod.yml
svr:
extends:
file: docker-compose-base.yml
service: base
command: npm run prod:deploy
ports:
- "8081:8081"
environment:
NODE_ENV: production
PORT: "8081"
CLTPORT: "8082"
clt:
extends:
file: docker-compose-base.yml
service: base
command: npm run prod:deploy:clientside
ports:
- "8082:8082"
environment:
NODE_ENV: production
PORT: "8082"
The ports and the env port are equals
Is there a way to reference the clt port to the svr container ?
Docker Environment File
Use a .env file and reference it in both containers. This will ensure you only need to store these settings in a single location.
Compose supports declaring default environment variables in an environment file named .env placed in the folder docker-compose command is executed from (current working directory).
Compose expects each line in an env file to be in VAR=VAL format. Lines beginning with # (i.e. comments) are ignored, as are blank lines.
Compose File Integration:
env_file: .env
env_file:
- ./common.env
- ./apps/web.env
- /opt/secrets.env
Docker Compose File Reference - env_file
Docker Compose Environment File Documentation
You can use environment variable inside docker-compose.
svr:
extends:
file: docker-compose-base.yml
service: base
command: npm run prod:deploy
ports:
- ${CLTPORT}:${PORT}
environment:
NODE_ENV: production
clt:
extends:
file: docker-compose-base.yml
service: base
command: npm run prod:deploy:clientside
ports:
- ${CLTPORT2}:${PORT2}
environment:
NODE_ENV: production
run docker-compose like:
CLTPORT=8082 PORT=8081 CLTPORT2=8081 PORT2=8082 docker-compose -f docker-compose-prod.yml up
Of course change your port variables as you need.
You can reference an environment variable to solve this
https://github.com/docker/compose/issues/1377