Docker-compose Daemon mode logs - docker

I'm running several containers in daemon mode: docker-compose up -d.
One of them recently crashed.
I'd like to investigate what happened. Where can I find the app logs?
Here's the docker-compose.yml (nothing special regarding logging):
mongodb:
image: mongo
command: "--smallfiles --logpath=/dev/null"
web:
build: .
command: npm start
volumes:
- .:/myapp
ports:
- "3001:3000"
links:
- mongodb
environment:
PORT: 3000
NODE_ENV: 'production'
seed:
build: ./seed
links:
- mongodb

You can get logs via docker-compose logs or you could exec to attach (docker >= 1.3) to the running instance via
$ docker exec -i -t 6655b41beef /bin/bash #by ID
or
$ docker exec -i -t my_www /bin/bash #by Name

Related

SocketError: Failed to open TCP connection to docker service when executing docker-compose file

Here's my docker-compose file. I have a scraper service feeding a rails api (data_api):
version: '3'
services:
redis-server:
image: redis
restart: always
scraper:
image: davidgeismar/artifacts-scraper:without-db
command: "bundle exec rake scrape_sources:scrape\"[['christies'],nil,[2019]]\""
volumes:
- ./logs/artifacts_scraper:/usr/src/artifacts_scraper/log
environment:
- REDIS_URL=redis://redis-server:6379/0
- ARTIFACTS_ENV=docker_development
- DATA_API_BASE=http://data_api:3000
depends_on:
- data_api
- redis-server
data_api:
volumes:
- ./logs/artifacts_data_api:/artifacts_data_api/log
image: davidgeismar/artifacts_data_api:latest
command: 'rails server -b 0.0.0.0'
environment:
- RAILS_ENV=docker_development
- SECRET_KEY_BASE=docker_development_secret
sidekiq:
volumes:
- ./logs/sidekiq/scraper:/usr/src/artifacts_scraper/log
image: davidgeismar/artifacts-scraper:without-db
command: 'bundle exec sidekiq -r ./artifacts_scraper.rb 2>&1 | tee ./log/sidekiq.log'
environment:
- REDIS_URL=redis://redis-server:6379/0
- ARTIFACTS_ENV=docker_development
- DATA_API_BASE=http://data_api:3000
depends_on:
- redis-server
- data_api
I execute it with docker-compose pull && docker-compose up --build
However data_api keeps on exiting telling me :
data_api_1 | A server is already running. Check /artifacts_data_api/tmp/pids/server.pid.
event though in my dockerfile for that service I have :
RUN rm -f ./tmp/pids/server.pid
On top of that I get SocketError: Failed to open TCP connection to data_api:3000 (getaddrinfo: Name or service not known) for the scraper service which Im unable to understand why it happens.
All containers are accessible and pullable from dockerhub.
The code for the scraper service :
https://github.com/davidgeismar/artifacts-scraper/tree/removing-db
and for the data_api:
https://github.com/davidgeismar/artifacts_data_api

Docker for Mac | Docker Compose | Cannot access containers using localhost

I've been trying to figure out why I cannot containers using "localhost:3000" from host. I've tried installing Docker via Homebrew, as well as the Docker for Mac installer. I believe I have the docker-compose file configured correctly.
Here is the output from docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------------------------------------------
ecm-datacontroller_db_1 docker-entrypoint.sh postgres Up 0.0.0.0:5432->5432/tcp
ecm-datacontroller_kafka_1 supervisord -n Up 0.0.0.0:2181->2181/tcp, 0.0.0.0:9092->9092/tcp
ecm-datacontroller_redis_1 docker-entrypoint.sh redis ... Up 0.0.0.0:6379->6379/tcp
ecm-datacontroller_web_1 npm start Up 0.0.0.0:3000->3000/tcp
Here is my docker-compose.yml
version: '2'
services:
web:
ports:
- "3000:3000"
build: .
command: npm start
env_file: .env
depends_on:
- db
- redis
- kafka
volumes:
- .:/app/user
db:
image: postgres:latest
ports:
- "5432:5432"
redis:
image: redis:alpine
ports:
- "6379:6379"
kafka:
image: heroku/kafka
ports:
- "2181:2181"
- "9092:9092"
I cannot access any ports that are exposed by docker-compose with curl localhost:3000 I get the following result from that
curl: (52) Empty reply from server
I should be getting {"hello":"world"}.
Dockerfile:
FROM heroku/heroku:16-build
# Which version of node?
ENV NODE_ENGINE 10.15.0
# Locate our binaries
ENV PATH /app/heroku/node/bin/:/app/user/node_modules/.bin:$PATH
# Create some needed directories
RUN mkdir -p /app/heroku/node /app/.profile.d
WORKDIR /app/user
# Install node
RUN curl -s https://s3pository.heroku.com/node/v$NODE_ENGINE/node-v$NODE_ENGINE-linux-x64.tar.gz | tar --strip-components=1 -xz -C /app/heroku/node
# Export the node path in .profile.d
RUN echo "export PATH=\"/app/heroku/node/bin:/app/user/node_modules/.bin:\$PATH\"" > /app/.profile.d/nodejs.sh
ADD package.json /app/user/
RUN /app/heroku/node/bin/npm install
ADD . /app/user/
EXPOSE 3000
Anyone have any ideas?
Ultimately, I ended up having a service that was listening on 127.0.0.1 instead of 0.0.0.0. Updating this resolved the connectivity issue I was having.

Interact with redis container started with docker compose

I have a docker compose file that links my server to a redis image:
version: '3'
services:
api:
build: .
command: npm run dev
environment:
NODE_ENV: development
volumes:
- .:/home/node/code
- /home/node/code/node_modules
- /home/node/code/build/Release
ports:
- "1389:1389"
depends_on:
- redis
redis:
image: redis:alpine
I am wondering how could I open a redis-cli against the Redis container started by docker-compose to directly modify ke/value pairs. I tried with docker attach but it does not open any shell.
Use docker exec -it your_container_name /bin/bash to enter into redis container, then execute redis-cli to modify key-value pair.
See https://docs.docker.com/engine/reference/commandline/exec/
Install the Redis CLI on your host. Edit the YAML file to publish Redis's port
services:
redis:
image: redis:alpine
ports: ["6379:6379"]
Then run docker-compose up to redeploy the container, and you can run redis-cli from the host without needing to directly interact with Docker.
Using /bin/bash as the command (as suggested in the accepted solution) doesn't work for me with the latest redis:alpine image on Linux.
Instead, this worked:
docker exec -it your_container_name redis-cli

How to debug a rails app in docker with pry and foreman?

Developing a ruby on rails app with foreman, docker, pry.
Checked this article already.
How to debug a rails app in docker with pry?
I usually use docker-compose run --service-ports web to debug with binding.pry.
But with foreman, docker-compose run --service-ports web does not work.
docker attach works, but its not useful as docker-compose run --service-ports web
Any solution to make it work like docker-compose run --service-ports web with foreman?
Foreman seems to be the culprit. I was facing a similar issue and I managed to solve it by creating new services in the docker-compose file for each service described in the Procfile.
Before:
web:
build: .
entrypoint: ./entrypoint-dev.sh
command: bash -c "bundle exec foreman start -f Procfile.dev -p 3000"
tty: true
volumes:
- .:/usr/src/app
- bundle:/usr/local/bundle
ports:
- 3000:3000
environment:
- RAILS_MAX_THREADS=5
- RAILS_ENV=development
- RACK_ENV=development
- DATABASE_HOST=db
- DATABASE_USER=postgres
- DATABASE_PASSWORD=password
depends_on:
- db
- redis
After:
js:
build:
context: "."
tty: true
command: "yarn build --watch"
volumes:
- .:/usr/src/app
css:
build:
context: "."
tty: true
command: "yarn build:css --watch"
volumes:
- .:/usr/src/lazy-joker
web:
build: .
entrypoint: ./entrypoint-dev.sh
command: bash -c "bundle exec rails s -p 3000 -b '0.0.0.0'"
stdin_open: true
tty: true
volumes:
- .:/usr/src/app
- bundle:/usr/local/bundle
ports:
- 3000:3000
environment:
- RAILS_MAX_THREADS=5
- RAILS_ENV=development
- RACK_ENV=development
- DATABASE_HOST=db
- DATABASE_USER=postgres
- DATABASE_PASSWORD=password
depends_on:
- db
- redis
- js
- css
You need to attach your terminal to the docker container in order to debug:
docker attach container_id
PS: You can get the container id by running docker container ls.

Error starting docker postgres on travis-

I'm having an issue with my travis-ci before_script while trying to connect to my docker postgres container:
Error starting userland proxy: listen tcp 0.0.0.0:5432: bind: address already in use
I've seen this problem raised but never fully addressed around SO and github issues, and i'm not clear whether it is specific to docker or travis. One linked issue (below) works around it by using 5433 as the host postgres address but i'd like to know for sure what is going on before i jump into something.
my travis.yml:
sudo: required
services:
- docker
env:
DOCKER_COMPOSE_VERSION: 1.7.1
DOCKER_VERSION: 1.11.1-0~trusty
before_install:
# list docker-engine versions
- apt-cache madison docker-engine
# upgrade docker-engine to specific version
- sudo apt-get -o Dpkg::Options::="--force-confnew" install -y docker-engine=${DOCKER_VERSION}
# upgrade docker-compose
- sudo rm /usr/local/bin/docker-compose
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin
before_script:
- echo "Before Script:"
- docker-compose -f docker-compose.ci.yml build
- docker-compose -f docker-compose.ci.yml run app rake db:setup
- docker-compose -f docker-compose.ci.yml run app /bin/sh
script:
- echo "Running Specs:"
- rake spec
my docker-compose.yml for ci:
postgres:
image: postgres:9.4.5
environment:
POSTGRES_USER: web
POSTGRES_PASSWORD: yourpassword
expose:
- '5432' # added this as an attempt to open the port
ports:
- '5432:5432'
volumes:
- web-postgres:/var/lib/postgresql/data
redis:
image: redis:3.0.5
ports:
- '6379:6379'
volumes:
- web-redis:/var/lib/redis/data
web:
build: .
links:
- postgres
- redis
volumes:
- ./code:/app
ports:
- '8000:8000'
# env_file: # setting these directly in the environment
# - .docker.env # (they work fine locally)
sidekiq:
build: .
command: bundle exec sidekiq -C code/config/sidekiq.yml
links:
- postgres
- redis
volumes:
- ./code:/app
Docker & Postgres: Failed to bind tcp 0.0.0.0:5432 address already in use
How to get Docker host IP on Travis CI?
It seems that Postgres service is enabled by default in Travis CI.
So you could :
Try to disable the Postgres service in your Travis config. See How to stop services on Travis CI running by default?. See also https://docs.travis-ci.com/user/database-setup/#PostgreSQL .
Or
Map your postgres container to another host port (!= 5432). Like -p 5455:5432.
It could also be useful to check if the service is already running : Check If a Particular Service Is Running on Ubuntu
Do you use Travis' Postgres?
services:
- postgresql
Would be easier if you provide travis.yml

Resources