I installed package make and after that i want to build docker-compose volumes.
I use command make build-testimage.
My makefile.
build-testimage:
docker-compose -f docker-compose-test.yml build --build-arg UNAME=$$(whoami) \
--build-arg UID=$$(id -u) --build-arg GID=$$(id -g)
My docker-compose.yml
version: "3.9"
services:
api:
build:
dockerfile: Dockerfile_test
context: .
volumes:
- .:/code
- media:/media
ports:
- 80:8000
env_file:
- .env_dev
stdin_open: true
tty: true
depends_on:
- redis_cache
db:
build:
dockerfile: Dockerfile_db
context: .
ports:
- 8001:5432
env_file:
- .env_dev
volumes:
- pgdata:/var/lib/postgresql/data
redis_cache:
image: redis:7.0.0
entrypoint: ["bash", "-c", "redis-server", "--daemonize", "yes"]
ports:
- 6379:6379
depends_on:
- db
volumes:
pgdata:
media:
When i try to make build-testimage i have exception from Docker.
Services are built once and then tagged as `project_service`,
e.g. `composetest_db`. If you change a service's `Dockerfile` or the
contents of its build directory, you can run `docker-compose build` to rebuild it.
Usage: build [options] [--build-arg key=val...] [--] [SERVICE...]
How can i run this instruction ?
Related
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
Trying to setup Redis from this image Redismod and struggle to translate the following code into docker-compose
$ docker run \
-p 6379:6379 \
-v /home/user/data:/data \
-v /home/user/redis.conf:/usr/local/etc/redis/redis.conf \
redislabs/redismod \
/usr/local/etc/redis/redis.conf
What I have done till now:
version: "3.2"
services:
redis:
image: "redislabs/redismod"
container_name: 'redis-local'
hostname: 'redis-local'
volumes_from:
- redis_data:/data
- ./redis.conf:/usr/local/etc/redis/redis.conf
args:
- /usr/local/etc/redis/redis.conf
restart: always
ports:
- "6379:6379"
volumes:
redis_data:
But I get the following error ERROR: Service "redis" mounts volumes from "redis_data", which is not the name of a service or container. obviously because I didn't pass the last line /usr/local/etc/redis/redis.conf
And second question, how do I translate --loadmodule and --dir from below, these aren't Redis command:
$ docker run \
-p 6379:6379 \
-v /home/user/data:/data \
redislabs/redismod \
--loadmodule /usr/lib/redis/modules/rebloom.so \
--dir /data
UPDATE
I changed my docker-compose.yml file to the following and it started to work, but it seems that Redis doesn't see the redis.conf file and continue to run in default mode, what I do wrong?
version: "3.2"
services:
redis:
image: "redislabs/redismod"
container_name: 'redis-local'
hostname: 'redis-local'
volumes:
- redis_data:/data
- ./redis.conf:/usr/local/etc/redis/redis.conf
build:
context: .
args:
- /usr/local/etc/redis/redis.conf
restart: always
ports:
- "6379:6379"
The first error was because you used volumes_from instead of volumes. The first one is intended to get the volumes configuration from an existing container. The second one to define the volumes. In your last version redis_data is a docker volume and redis.conf is a bind mount. Your second problem is that you are using build and args that are intended to be used for building images but looks like you wanted to run a command.
Try:
version: "3.2"
services:
redis:
image: "redislabs/redismod"
container_name: 'redis-local'
hostname: 'redis-local'
volumes:
- redis_data:/data
- ./redis.conf:/usr/local/etc/redis/redis.conf
command: usr/local/etc/redis/redis.conf
restart: always
ports:
- "6379:6379"
For more info about volumes, bind mounts and docker compose reference see:
https://docs.docker.com/storage/volumes/
https://docs.docker.com/storage/bind-mounts/
https://docs.docker.com/compose/compose-file/compose-file-v3/#command
I made a Drupal project on Docker. I started from the official images. I made a docker-compose like this:
version: "3"
services:
nginx:
build:
context: docker/nginx
dockerfile: Dockerfile
volumes:
- drupal:/var/www/html
ports:
- 80:80
env_file:
- ./docker/env/nginx.env
command: /bin/bash -c "sh /build_vhost.sh"
cli:
build:
context: docker/cli
dockerfile: Dockerfile
args:
DOCKER_UID: ${DOCKER_UID} # replace by your user id
DOCKER_GID: ${DOCKER_GID} # replace by your group id
volumes:
- drupal:/var/www/html
working_dir: /var/www/html
env_file:
- ./docker/env/mysql.env
drupal:
build:
context: docker/drupal
dockerfile: Dockerfile
args:
DOCKER_UID: ${DOCKER_UID} # replace by your user id
DOCKER_GID: ${DOCKER_GID} # replace by your group id
volumes:
- drupal:/var/www/html
working_dir: /var/www/html
restart: always
mariadb:
image: mariadb:10.4-bionic
ports:
- 3306:3306
volumes:
- ./docker/volumes/mariadb/databases:/var/lib/mysql
env_file:
- ./docker/env/mysql.env
volumes:
drupal:
And it works, I have the Drupal files in my containers nginx, cli and drupal.
But if I modify it to have the files in my project, like this :
version: "3"
services:
nginx:
build:
context: docker/nginx
dockerfile: Dockerfile
volumes:
- ./drupal:/var/www/html
ports:
- 80:80
env_file:
- ./docker/env/nginx.env
command: /bin/bash -c "sh /build_vhost.sh"
cli:
build:
context: docker/cli
dockerfile: Dockerfile
args:
DOCKER_UID: ${DOCKER_UID} # replace by your user id
DOCKER_GID: ${DOCKER_GID} # replace by your group id
volumes:
- ./drupal:/var/www/html
working_dir: /var/www/html
env_file:
- ./docker/env/mysql.env
drupal:
build:
context: docker/drupal
dockerfile: Dockerfile
args:
DOCKER_UID: ${DOCKER_UID} # replace by your user id
DOCKER_GID: ${DOCKER_GID} # replace by your group id
volumes:
- ./drupal:/var/www/html
working_dir: /var/www/html
restart: always
mariadb:
image: mariadb:10.4-bionic
ports:
- 3306:3306
volumes:
- ./docker/volumes/mariadb/databases:/var/lib/mysql
env_file:
- ./docker/env/mysql.env
The Drupal files are not in the containers but the volume work : if I create a file in the container, I have it on my local filesystem. Before the image build the directory exists and I put the 777 perms on it.
The output when the build says that the Drupal files are downloaded and untarred.
I do not change the Dockerfiles between the two versions of the docker-compose.
How can I have the Drupal files on my local filesystem to version my changes, please?
I am trying to execute a wait-for-it.sh script in my docker-compose.yaml file using "command:". I also tried to even execute the ls command as well. They both resulted in command not found. Howeer, if I go to the command line, I am able to run both commands.
Here is the docker-compose.yaml file:
rabbitmq:
container_name: "myapp_rabbitmq"
tty: true
image: rabbitmq:management
ports:
- 15672:15672
- 15671:15671
- 5672:5672
volumes:
- /rabbitmq/lib:/var/lib/rabbitmq
- /rabbitmq/log:/var/log/rabbitmq
- /rabbitmq/conf:/etc/rabbitmq/
service1:
container_name: "service1"
build:
context: .
dockerfile: ./service1.dockerfile
links:
- mongo
- rabbitmq
depends_on:
- mongo
- rabbitmq
command: ["./wait-for-it.sh", "rabbitmq:5672", "-t", "90"]
service2:
container_name: "service2"
build:
context: .
dockerfile: ./service2.dockerfile
links:
- mongo
- rabbitmq
depends_on:
- mongo
- rabbitmq
command: ["./wait-for-it.sh", "rabbitmq:5672", "-t", "90"]
What could be causing this as the commands work from the command line, just not from docker-compose file? I am using "docker-compose up -d" to start the containers, if that helps any.
If the wait-for-it.sh is not found at runtime, then I suspect that the wait-for-it.sh is not inside your docker image.
You can add this file to the image using the ADD instruction in your Dockerfile(s)
ADD wait-for-it.sh /wait-for-it.sh
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