Skip to content

Instantly share code, notes, and snippets.

@franz-josef-kaiser
Last active March 11, 2016 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save franz-josef-kaiser/30f24b3785378d1f4826 to your computer and use it in GitHub Desktop.
Save franz-josef-kaiser/30f24b3785378d1f4826 to your computer and use it in GitHub Desktop.
Docker and Docker-Compose tricks – nginx
# *CASE:*
# Debug start up problems by appending logs to `up` job
[1 (master *) ~/projects/DockerCompose] docker-compose up -d && docker-compose logs
# *Example* output:
[2 (master *) ~/projects/DockerCompose]: docker-compose up -d && docker-compose logs
web is up-to-date
logs is up-to-date
Creating nginx
Attaching to nginx, logs, web
logs | / #
nginx | nginx: [emerg] "proxy_cache_path" directive is not allowed here in /etc/nginx/nginx.conf:100
web | / #
ERROR: Couldn't connect to Docker daemon - you might need to run `docker-machine start default`.
# *Conclusion:*
# A wrong docker nginx proxy cache config
# ------------
# *CASE:*
# Debug nginx configuration in a slim Debian/Busybox/Scratch container where nginx has PID 1
# Container is already running, admin changed the config, now needs to check it
# Logging into the container is not wanted
[3 (master *) ~/projects/DockerCompose]: docker exec -it <CONTAINER NAME> nginx -t
# Output will tell if config is ok or not
# ------------
# *CASE:*
# Reloading of nginx conf is needed after config changed
# Logging into the container is not wanted
[4 (master *) ~/projects/DockerCompose]: docker exec -it <CONTAINER NAME> nginx -s reload
# Reload, stop, …
# see command line docs for "signals" https://www.nginx.com/resources/wiki/start/topics/tutorials/commandline/
# ------------
# *CASE:*
# Find ports: *PRIVILEGED* is important, else no PID is shown
$ docker exec -it --privileged <CONTAINER NAME> nodejs /bin/sh
# List processes, ports and PIDs
$ netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.11:52166 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:3000 0.0.0.0:* LISTEN 47/node
tcp 0 0 :::3001 :::* LISTEN 35/gulp
tcp 0 0 :::3002 :::* LISTEN 35/gulp
udp 0 0 127.0.0.11:37556 0.0.0.0:* -
# Find process PID that opened <PORT>
$ fuser <PORT>/tcp
<PID>
# Find location of process that is running stuff on <PORT>
$ ls -l /proc/<PID>/exe
lrwxrwxrwx 1 root root 0 Mar 11 03:31 /proc/47/exe -> /usr/bin/node
# Find current working directory of <PID>
$ ls -l /proc/47/cwd
lrwxrwxrwx 1 root root 0 Mar 11 04:01 /proc/47/cwd -> /usr/src/app
# alternate solution:
$ pwdx 47
47: /usr/src/app
# Find owner of process
$ ps aux |grep <PID>
<PID> root 0:00 node ./deploy/server.js
106 root 0:00 grep <PID>
# Get <PID> environment variables
$ cat /proc/<PID>/environ
…endless mess of string…
# Shorten to what we search for
$ grep -w -a HOSTNAME /proc/<PID>/environ
HOSTNAME=3b5aeb05e6d9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment