docker-compose logs with separate yml file - docker-compose

How do I run docker-compose logs but using a separate yaml config?
For example, if I want to run docker-compose up with a separate file, I can do:
docker-compose -f other-config.yml up
But -f in docker-compose logs points to a service, rather than a file.

For docker-compose, the -f options means to load a different configurations file. for docker-compose logs, the -f option means to follow the logs.
For your situation you need to pass the -f option twice:
docker-compose -f other-config.yml logs -f
You can optionally specify a service name as well at the end.

Related

How to bind container's application file log with Kubernetes logs command?

I have developed a web microservice in Golang. I have used zap logger to log the application log in a file at location /var/log/myapp/myapp.log.
I want to see log information in file myapp.log through below command:
#kubectl logs mayappPod
But it is not working as by default STDOUT and STDERR output is redirected to kubectl logs command.
So my question is what exactly I am supposed to do to see the /var/log/myapp/myapp.log log through kubectl logs command.
Thanks,
Rohit
kubectl logs command just show you logs from container(s) you specified. And container got logs from STDOUT and STDERR.
The recommended way is to setup your logging library to write logs to STDOUT. But as a workaround you can create symlink from /var/log/myapp/myapp.log to /dev/stdout in your docker container.
Another option is not use kubectl logs at all. You could copy this log file from your pod using kubectl cp <some-namespace>/<some-pod>:/tmp/foo /tmp/bar see

Creating 2 S3 buckets in LocalStack via a docker-compose file

Currently we’re creating a localstack container using a docker-compose file, specifically for the purpose of using the S3 service.
We’ve added this line to the environment which creates an S3 bucket
- AMAZONPROPERTIES.BUCKETNAME=bucketname
We’ve then created any additional buckets needed using a utility within our Java code.
However, it would be preferable to create all buckets needed automatically at the outset using our docker-compose file. Is it possible to do this?
Not sure if it's the best way, but it works.
We're now running the docker-compose.yml in a bash script, waiting a short while to ensure that the service is running and then call a curl command within the docker container to create another S3 bucket.
#!/bin/bash
docker-compose -f docker-compose.yml up -d --build
echo "Waiting for Services to be ready"
sleep 20
docker exec -it general-files_general-files_1 curl -X POST
https://localhost:7777/createBucket -F bucketName=bucketname2 --insecure
echo
echo "S3 buckets available are: "
docker exec -it general-files_general-files_1 curl -X GET
https://localhost:7777/listBuckets --insecure
echo
echo "Services are ready for use"

docker-compose - issue restarting single service

I am using docker-compose for a development project. I have 6 services defined in my docker compose file. I have been using the below script to rebuild the images whenever I make a change.
#!/bin/bash
# file: rebuild.sh
docker-compose down
docker-compose build
docker-compose up
I am looking for a way to reduce the build time as building and restarting all the services seems unnecessary as I am usually only changing one module. I see in the docker-compose docs you can run commands for individual services by specifying the service name after e.g. docker-compose build myservice.
In another terminal window I tried docker-compose build myservice && docker-compose restart myservice while leaving the other ./rebuild.sh command open in the original terminal. In the ./rebuild.sh terminal window I see all the initialization messages being reprinted to the stdout so I know it is restarting that service but the code changes aren't there. What am I doing wrong? I just want to rebuild and restart a single service.
Try:
docker-compose up -d --force-recreate --build myservice
Note that:
-d is for Detached mode,
-force-recreate will recreate containers even is your code did not change,
-build is for build your images before starting containers.
At least the name of your service.
Take a look here.

Not able to create a file using kubectl

I recently started working on microservices. I am building my docker image and want to deploy it on kubernetes. while creating a pod.yaml file I started getting the below error.
Command :
kubectl create -f podservice.yaml
Error :
error: the path "podcpeservice.yml" does not exist
Tried using the helpfor kubectl create -f help. An example in the help document is
command :
kubectl create -f ./pod.json
Even the above command gives the same error. Not able to figure out what is the problem. tried removing ./
I am using centos 7 on virtual-box with windows 7 as host.
Tushar,
First you need to create the deployment yml file using one of the editor, then pass the file as argument for kubectl command.
eg.
kubernets team already created this deployment file. you use kubectl to deploy.
kubectl apply -f https://k8s.io/examples/controllers/nginx-deployment.yaml
Somehow the filename was corrupted with unseen symbol so this helped me to get over wrong naming
mv postgres-configmap.yaml\ postgres-configmap.yaml
and then it worked:
kubectl create -f postgres-configmap.yaml
configmap/postgres-config created

Why doesn't docker-compose 'down' take an optional [SERVICE...] argument?

docker-compose down does not have a [SERVICE...] argument.
Per docker-compose down --help:
Usage: down [options]
I would like to be able to bring just one of my many containers down. I know that I can down a single container using docker down instead of docker-compose down, but I'm wondering why doesn't the docker-compose down command take an optional [SERVICE...] argument?
All of the following docker-compose commands do take an optional [SERVICE...] argument:
docker-compose build
docker-compose create
docker-compose kill
docker-compose logs
docker-compose pause
docker-compose restart
docker-compose rm
docker-compose start
docker-compose stop
docker-compose unpause
docker-compose up
My docker-compose --version is 1.9.0
The following command is the equivalent of docker down for a single service:
docker-compose rm -s -v my_service
Usage: rm [options] [SERVICE...]
Options:
-s, --stop Stop the containers, if required, before removing
-v Remove any anonymous volumes attached to containers
There is no docker down. The corresponding docker command is closer to: docker stop; docker rm
From docker-compose down:
Stops containers and removes containers, networks, volumes, and images created by up.
By default, the only things removed are:
Containers for services defined in the Compose file
Networks defined in the networks section of the Compose file
The default network, if one is used
If docker-compose down removes networks also, then by removing one container, it should also automatically disconnect the other containers from these networks, which might be undesirable or confusing.
It could change so that by default docker down does not remove the networks, but that change might cause backwards-compatibility issues with the command.
This is just an assumption.