I have two APIs. One is located in /first_project/api and the other in /another_project/api.
Both have docker-compose.yml inside them. And this is their respective docker-compose.yml files:
version: "3.9"
services:
api:
image: custom_image_name
container_name: first_project_api
working_dir: /first_project/api
ports:
- 52148:5000
volumes:
- /first_project/api:/first_project/api
command: >
bash -c
"
dotnet Api.dll
&& tail -f /dev/null
"
networks:
- first_project_network
networks:
first_project_network:
name: first_project_network
driver: bridge
The second one, is like this one. Just first_project is replaced with second_project.
However, when I use docker-compose down in any of the API directories, docker brings down the other container as well.
What's happening here? How can I debug this?
Related
I have the following two docker compose files:
docker-compose.yml :
version: '2.3'
services:
# test11 service
test11:
build: test11/.
image: "test11"
and
docker-compose.yml (file inside the folder named test11 that contains Dockerfile and the following docker-compose ):
version: '2.3'
networks:
citrixhoneypot_local:
services:
# CitrixHoneypot service
test11:
build: .
container_name: test11
restart: always
networks:
- citrixhoneypot_local
ports:
- "443:443"
image: "test11:2006"
# read_only: true
volumes:
- test11:/opt/test11/logs
volumes:
test11:
driver:local
when i run docker-compose up --build for the first file, everything seems ok and the container build and i can run exec -it sh on it and get access.
but the problem is that the volume isn't made in the path
/var/lib/docker/volumes and i can't find it there.
also when i write in /opt/test11/logs from inside the docker container no file is made under /var/lib/docker/volumes .
I tried this with bind path too. same problem with that too.
I have 2 docker-compose files that build a dockerfile, and i want join those docker-compose files
so, i created other docker-compose that goes up these 2 images
version: "3.4"
services:
frontend:
image: frontend-image
depends_on:
- backend
ports:
- "3000:80"
networks:
- teste-network
backend:
image: backend-image
ports:
- "5001:80"
networks:
- test-network
networks:
test-network:
driver: bridge
but, this docker-compose file not build the images
then i created a bash command that build these images
bash -c "docker-compose -f ./frontend/docker/docker-compose.yml build
&& docker-compose -f ./backend/docker/docker-compose.yml build"
I want to run this script before up containers, just typing docker-compose up
i assume that you have 2 dockerfiles - one for the frontend and the other for the backend, where each of which resides in the corresponding folder from your post, that is:
frontend/docker/Dockerfile
backend/docker/Dockerfile
then you can leverage docker-compose to build and run your images. all you have to do is to tell docker-compose where are the dockerfiles, which you can do by utilizing the build configuration.
version: "3.4"
services:
frontend:
image: frontend-image
build: ./frontend/docker
depends_on:
- backend
ports:
- "3000:80"
networks:
- test-network
backend:
image: backend-image
build: ./backend/docker
ports:
- "5001:80"
networks:
- test-network
networks:
test-network:
driver: bridge
then running docker-compose up frontend will build the docker images (if they do no exist), and then start them.
How can I persist the flow.xml.gz file in nifi docker container?
I am using a docker-compose file, it is giving me errors such as not finding certain files.
Didi you encounter the same issue?
Thanks
version: "3.3"
services:
nifi:
image: apache/nifi
volumes:
- /home/ubuntu/nifi/conf:/opt/nifi/nifi-current/conf
#- ./flow/flow.xml.gz:/opt/nifi/nifi-current/conf/flow.xml.gz
ports:
- "8080:8080"
Apparently NiFi doesn't allow you to only persist the flow.xml.gz file, it gives error and the container shuts.
You need to persist the whole /opt/nifi/nifi-current/conf/ folder
I solved this issue changing the path for the flow.xml.gz to another directory. Here is my docker-compose.yaml for reference:
version: "3.9"
services:
nifi:
container_name: nifi
image: apache/nifi:1.15.0
ports:
- 8443:8443
volumes:
- ./config:/conf
environment:
- SINGLE_USER_CREDENTIALS_USERNAME=admin
- SINGLE_USER_CREDENTIALS_PASSWORD=S3curePa55word
- NIFI_SENSITIVE_PROPS_KEY=pUaEVgyGKT61fMCAWNbjJPMwAcQDuDj4
entrypoint: >
bash -c "echo Overwriting entrypoint
&& echo Replace path for flow.xml.gz
&& sed -i 's#=./conf/flow.xml.gz#=/conf/flow.xml.gz#g' /opt/nifi/nifi-current/conf/nifi.properties
&& /opt/nifi/scripts/start.sh"
I have part of my current config like this
mymicroservice:
image: service_img
networks: myoverlay
volumes:
- /Users/abcdUser/mountme:/opt/company/
This does the job as my machine's directory gets mounted to /opt/company when I deploy the docker swarm service stack.
However, I want to specify the source directory under a separate volumes: and then specify that name over there. I think this is possible but I am not able to find the syntax.
So I want something along the following lines but not able to do so:
mymicroservice:
image: service_img
networks: myoverlay
volumes:
- myownvolume:/opt/company/
volumes:
- myownvolume: /Users/abcdUser/mountme
I want to clarify that myownvolume here is just pointing to the directory /Users/abcdUser/mountme and I am not intending to create a docker volume. Or there is any other better way to do this?
It is possible to do so but not with the standard setup. The default volume driver doesn't allow the format you are looking for. You need to use docker plugins which requires external installation. Consider the below yaml
version: '2'
services:
one:
image: alpine
working_dir: /one/
command: sleep 600
volumes:
- data:/one/
two:
image: alpine
working_dir: /two/
command: sleep 600
volumes:
- data:/two/
volumes:
data:
driver: local-persist
driver_opts:
mountpoint: /data/local-persist/data
Above would work when you have the local-persist plugin installed. https://github.com/CWSpear/local-persist
You can find about other plugins available on
https://docs.docker.com/engine/extend/legacy_plugins/#volume-plugins
Also if repetition of volumes entries is an issues for you then you can use anchors in YAML
version: '3'
services:
alpines:
image: alpine
command: sleep 200
volumes: &common_volumes
- ./data:/data
- ./config:/config
alpine2:
image: alpine
command: sleep 200
volumes: *common_volumes
$ docker-compose config
services:
alpine2:
command: sleep 200
image: alpine
volumes:
- /home/vagrant/so/volumes2/data:/data:rw
- /home/vagrant/so/volumes2/config:/config:rw
alpines:
command: sleep 200
image: alpine
volumes:
- /home/vagrant/so/volumes2/data:/data:rw
- /home/vagrant/so/volumes2/config:/config:rw
version: '3.0'
That's not possible. You either have to use the bind mount syntax or the volume syntax. Volumes at the compose config top level won't allow you to mix both. See how to define a general mount point in docker compose for a similar question.
I want to have two docker-compose files, where one overrides another.
(The motivation comes from Docker Compose Docs)
The use case comes from the buildbot environment. The first docker-compose file should define a simple service. This is a service that is going to be tested. Let's take
version: '2'
services:
service-node:
build:
context: ./res
dockerfile: Dockerfile
image: my/server
env_file: .env
The second docker-compose file (let's name it docker-compose.test.yml) overrides the service-node to add a buildbot worker feature, and creates the second container, i.e. buildbot master node, that is going to control testing machinery. Let's take
version: '2'
services:
service-node:
build:
context: ./res
dockerfile: buildbot.worker.Dockerfile
image: my/buildbot-worker
container_name: bb-worker
env_file: ./res/buildbot.worker.env
environment:
- BB_RES_DIR=/var/lib/buildbot
networks:
testlab:
aliases:
- bb-worker
volumes:
- ./vol/bldbot/worker:/home/bldbotworker
depends_on:
- bb-master
bb-master:
build:
context: ./res
dockerfile: buildbot.master.Dockerfile
image: my/buildbot-master
container_name: bb-master
env_file: ./res/buildbot.master.env
environment:
- BB_RES_DIR=/var/lib/buildbot
networks:
- testlab
expose:
- "9989"
volumes:
- ./vol/bldbot/master:/var/lib/buildbot
networks:
testlab:
driver: bridge
Generally this configuration works, i.e. the command
docker-compose -f docker-compose.yml -f docker-compose.test.yml up -d
builds both images and runs both containers, but there is one shortcoming, i.e. the command
docker-compose ps
shows only one service, bb-worker. At the same time
docker ps
shows both.
Furthermore, the command
docker-compose down
stops only one service, and outputs the message/warning Found orphan containers. Of course, the message refers to bb-master.
How can I override the basic docker-compose.yml file to be able to add additional non-orphan service?
You need to run all docker-compose commands with the flags, e.g.:
docker-compose -f docker-compose.yml -f docker-compose.test.yml down
Alternatively, you can make this the default by writing the following to a .env file in the same folder:
COMPOSE_FILE=docker-compose.yml:docker-compose.test.yml
NOTE:
In windows you need tu use ";" as the separator (#louisvno)