Docker Compose not reading multiple files - docker

Using the below docker compose files, i am unable to bring up my app correctly. Docker says my LAPIS_ENV environment variable is not set, but i am setting it in my second compose file which I am expecting to be merged into the first one. I have tried including them in reverse order to no avail.
version: '2.4'
services:
backend:
mem_limit: 50mb
memswap_limit: 50mb
build:
context: ./backend
dockerfile: Dockerfile
depends_on:
- postgres
volumes:
- ./backend:/var/www
- ./data:/var/data
restart: unless-stopped
command: bash -c "/usr/local/bin/docker-entrypoint.sh ${LAPIS_ENV}"
postgres:
build:
context: ./postgres
dockerfile: Dockerfile
environment:
PGDATA: /var/lib/postgresql/data/pgdata
POSTGRES_HOST_AUTH_METHOD: trust
volumes:
- postgres:/var/lib/postgresql/data
- ./postgres/pg_hba.conf:/var/lib/postgres/data/pg_hba.conf
- ./data/backup:/pgbackup
restart: unless-stopped
volumes:
postgres:
version: '2.4'
services:
backend:
environment:
LAPIS_ENV: development
ports:
- 8080:80
#!/usr/bin/env bash
docker compose -f docker-compose.yml -f docker-compose.dev.yml up

Related

How to reach localhost services from docker container with IPv4?

I have this docker-compose file where I have a couple of services:
version: "3.8"
services:
app:
container_name: mobile_app_api
env_file:
- .env.development
command: npm run watch:dev
build:
context: .
target: development
dockerfile: ./Dockerfile
restart: always
volumes:
- /usr/src/app/node_modules
- ./:/usr/src/app
depends_on:
- postgres
- redis
extra_hosts:
- host-machine:host-gateway
network_mode: host
redis:
image: "redis:alpine"
container_name: mobile_app_cache
postgres:
image: postgres
container_name: mobile_app_database
restart: "unless-stopped"
environment:
TZ: 'GMT'
PGTZ: 'GMT'
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: mobile_app_database
volumes:
- /:/data/postgres
network_mode: host
Api is supposed to work on localhost:3333, but when I start this with docker-compose up --build in terminal I get this:
mobile_app_api | server running on http://[::1]:3333
And here is 2 things.
Why does it work on IPv6?
How can I change host and make it work on localhost?
PS. My computer is MacOS, but in settings I have turned off IPv6.
I was trying to use host.docker.internal (and gateway.docker.internal) in my compose file, but it didn't work:
extra_hosts:
- host.docker.internal:host-gateway

docker-compose up; ERROR: 'network_mode' and 'networks' cannot be combined

After rebuild .jar file, and rebuild docker image, i try to docker-compose up, then i have error ERROR: 'network_mode' and 'networks' cannot be combined
This is docker-compose.yml file
version: "3"
services:
postgres:
image: postgres:latest
restart: always
container_name: postgresdb
ports:
- 5432:5432
environment:
- POSTGRES_PASSWORD=admin
- POSTGRES_USER=postgres
- POSTGRES_DB=postgres
volumes:
- ./tables.sql:/docker-entrypoint-initdb.d/shema.sql
networks:
- rent-manager-network
rent-service-manager:
image: rent-service-manager
network_mode: bridge
container_name: rent-manager-app
ports:
- 8080:8080
environment:
SPRING_DATASOURCE_URL: ${POSTGRESS_URL}
restart: always
depends_on:
- postgres
networks:
- rent-manager-network
networks:
rent-manager-network:
driver: bridge
Dockerfile:
FROM openjdk:11.0.1-slim as builder
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} application.jar
RUN java -Djarmode=layertools -jar application.jar extract
ENTRYPOINT ["java", "-jar", "application.jar"]
Please remove network_mode: bridge from the rent-service-manager service.
You don't need it when your network is bridged.

How to swap env file for another docker service

I have a docker-compose.yml
services:
nextjs:
container_name: next_app
build:
context: ./
restart: on-failure
command: npm run dev
volumes:
- ./:/app
- /app/node_modules
- /app/.next
ports:
- "3000:3000"
cypress:
image: "cypress/included:9.4.1"
depends_on:
- next_app
environment:
- CYPRESS_baseUrl=http://nextjs:3000
working_dir: /e2e
volumes:
- ./e2e:/e2e
I want to change env_file for next_app from cypress service. I found solution like this
cypress:
image: "cypress/included:9.4.1"
depends_on:
- next_app
environment:
- CYPRESS_baseUrl=http://nextjs:3000
working_dir: /e2e
volumes:
- ./e2e:/e2e
next_app:
env_file: .env.test
But this solution does not work. Is it even possible ?
Try something like cp .env #docker/.env
No. In Compose (or Docker, or even more generally in Linux/Unix) there is no way for one container (process) to specify environment variables for another.
You can think of a docker-compose.yml file as a set of instructions only for running containers. If you need a specific set of containers for a specific context – you don't normally need to run Cypress in production, but this is an integration-test setup – it's fine to write a separate Compose file just for that setup.
# docker-compose.cypress.yml
# Used only for integration testing
version: '3.8'
services:
nextjs:
build: .
restart: on-failure
ports:
- "3000:3000"
env_file: .env.test # <-- specific to this test-oriented Compose file
cypress:
build: ./e2e
depends_on:
- nextjs
environment:
- CYPRESS_baseUrl=http://nextjs:3000
docker-compose -f docker-compose.cypress.yml up --build
This can also be a case where using multiple Compose files together can be a reasonable option. You can define a "standard" Compose setup that only defines the main service, and then an e2e-test Compose file that adds the Cypress container and the environment settings.
# docker-compose.yml
version: '3.8'
services:
nextjs:
image: registry.example.com/nextjs:${NEXTJS_TAG:-latest}
restart: on-failure
ports:
- '3000:3000'
# docker-compose.e2e.yaml
version: '3.8'
services:
nextjs:
# These add to the definitions in the base `docker-compose.yml`
build: .
env_file: .env.test
cypress:
# This is a brand new container for this specific setup
depends_on: [nextjs]
et: cetera # copy from question or previous Compose setup
docker-compose \
-f docker-compose.yml \
-f docker-compose.e2e.yml \
up --build

How to push docker compose to docker hub

i have serveral services in my docker-compose file, it looks like this:
version: '3.7'
services:
web:
build: ./
command: gunicorn --bind 0.0.0.0:5000 --workers 2 --worker-connections 5000 --timeout 6000 manage:app
volumes:
- ./:/usr/src/app/
- static_volume:/usr/src/app/static_files
expose:
- 5000
env_file:
- ./.env.prod
depends_on:
- mongodb
mongodb:
image: mongo:4.4.1
restart: unless-stopped
command: mongod
ports:
- '27017:27017'
environment:
MONGODB_DATA_DIR: /data/db
MONDODB_LOG_DIR: /dev/null
MONGO_INITDB_ROOT_USERNAME:
MONGO_INITDB_ROOT_PASSWORD:
volumes:
- mongodbdata:/data/db
nginx:
build: ./nginx
volumes:
- static_volume:/usr/src/app/static_files
ports:
- 5001:8000
depends_on:
- web
volumes:
mongodbdata:
static_volume:
and i have public repository on my docker hub account, i want to push all images in my app to that repo, anyone can help?
You should add image names to your services, including your docker hub id, e.g.:
services:
web:
build: ./
image: docker-hub-id/web:latest
...
Now, you can just call docker-compose push.
See docker-compose push

Cannot launch django with celery in Docker Compose v3

Here is my docker-compose.yml:
version: '3.4'
services:
nginx:
restart: always
image: nginx:latest
ports:
- 80:80
volumes:
- ./misc/nginx.conf:/etc/nginx/conf.d/default.conf
- /static:/static
depends_on:
- web
web:
restart: always
image: celery-with-docker-compose:latest
build: .
command: bash -c "python /code/manage.py collectstatic --noinput && python /code/manage.py migrate && /code/run_gunicorn.sh"
volumes:
- /static:/data/web/static
- /media:/data/web/media
- .:/code
env_file:
- ./.env
depends_on:
- db
volumes:
- ./app:/deploy/app
worker:
image: celery-with-docker-compose:latest
restart: always
build:
context: .
command: bash -c "pip install -r /code/requirements.txt && /code/run_celery.sh"
volumes:
- .:/code
env_file:
- ./.env
depends_on:
- redis
- web
db:
restart: always
image: postgres
env_file:
- ./.env
volumes:
- pgdata:/var/lib/postgresql/data
ports:
- "5432:5432"
redis:
restart: always
image: redis:latest
privileged: true
command: bash -c "sysctl vm.overcommit_memory=1 && redis-server"
ports:
- "6379:6379"
volumes:
pgdata:
When I run docker stack deploy -c docker-compose.yml cryptex I got
Non-string key at top level: true
And docker-compose -f docker-compose.yml config gives me
ERROR: In file './docker-compose.yml', the service name True must be a quoted string, i.e. 'True'.
I'm using latest versions of docker and compose. Also I'm new to compose v3 and started to use it for getting availability of docker stack command. If you see any mistakes or redudants in config file please, let me know. Thanks
you have to validate you docker compose file, is probably that the have low value inside
Validating your file now is as simple as docker-compose -f
docker-compose.yml config. As always, you can omit the -f
docker-compose.yml part when running this in the same folder as the
file itself or having the

Resources