Skip to content

Commit

Permalink
Dockerfile works w/+w/o volume + docs are ok
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielhesposito committed Aug 6, 2017
1 parent 1eff3dc commit bc0646c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
9 changes: 5 additions & 4 deletions examples/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ RUN tar -xvf remote_syslog_linux_amd64.tar.gz
RUN mv remote_syslog/remote_syslog /usr/local/bin/remote_syslog
RUN mv /remote_syslog/example_config.yml /etc/log_files.yml

#Define the files/directory for host mounting
#directory under "/var/log/"
VOLUME ["/locallog.txt"]
#Define the directories for -v flag
#VOLUME ["/var/log/foobar/"]
RUN touch /locallog.txt
RUN chown rs2:rs2 /locallog.txt

#run rs2 as user in production
RUN chown rs2:rs2 /usr/local/bin/remote_syslog
USER rs2
CMD ["remote_syslog", "-D" ]

## uncomment to debug container
#RUN touch /tmp/foo
#CMD ["/usr/bin/tail", "-f", "/tmp/foo"]
54 changes: 45 additions & 9 deletions examples/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ If your existing infrastructure is container based (docker) you might be hesitan
to place remote_syslog2 on your host running wild from your container orchestration;
Or if you want to develop and test without "tainting" your enviroment.

Placing remote_syslog2 inside of a base centos/ubuntu/debian would result in a large (docker) image, basing it off of busybox or any small distro (tinycore anyone?) can leave you with a functional remote_syslog2 < 50MB.
Placing remote_syslog2 inside of a base centos/ubuntu/debian image would result in a large filesize (>200MB), basing it off of busybox or any small distro can leave you with a functional remote_syslog2 < 50MB.

### Prerequiste

Expand All @@ -13,24 +13,60 @@ be warned you may have stale packages on your system, check docker's latest docu

### Build and Run (with docker cli):

# same directory as Dockerfile
# change version based on packages available on release page
docker build --build-arg VERSION=v0.19 -t rs2 .
#change version based on packages available on release page
docker build --build-arg VERSION=v0.19 -t rs2:latest .

A successful build message should be produced after the build command.
After the build command a successfully built message should be produced.
`docker images` will reveal image size and name.

run (in background, _docker ps_ to confirm)

docker run --name rs2 -d rs2
docker run --name rs2 -d rs2:latest


If `docker ps` returns an empty table check the docker container's stdout

docker logs rs2

This will produce errors from the container's daemonized process (remote_syslog2) which should be a decent hint as to why it crashed.
This will produce errors from the container's daemonized process (remote_syslog2) which should be a decent hint as to why it crashed OR container did not start.

### Volumes and docker

Utilize a docker volume to access logs on the host or another container, between two (or more) containers share a docker volume and point the directories in `log _files.yml` at this shared directory.

### Sending logs from the host

use the docker cli to mount a host directory OR a single file, ie (/var/log/foobar) OR /locallog.txt

docker run --name rs2 -v /host/absolute/path/to/a/file/on/host/locallog.txt:/locallog.txt -d rs2:latest

confirm functionality

docker logs rs2
# output
2017-08-06 18:40:36 INFO remote_syslog.go:55 Connecting to logs.papertrailapp.com:514 over tls
2017-08-06 18:40:36 INFO remote_syslog.go:202 Forwarding file: locallog.txt
# continual writes are "picked up by a daemon"
lsof /host/absolute/path/to/a/file/locallog.txt
# snippet
1 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
2 remote_sy 15465 9999 6r REG 9,3 11 10224554 /host/absolute/path/to/a/file/locallog.txt

### Debugging

Removing the comment lines at the bottom of the dockerfile, rebuild the image, and run the container. You can use the following command `docker exec -it -u 0 sh` to "enter" the container as root, manually run remote_syslog2 via the cli and debug from there.

### Afterword

Keep the image minimal so it can be re-deployed in your enviroments.

Use enviroment variables to manipulate remote_syslog2's configuration - docs.docker.com (search ENV)
OR volume mount a configuration file `/etc/log_files.yml`

Use the docker cli for debugging/testing/development/prototyping, any other use-case should invole orchestration;

###Volumes and docker
docs.docker.com (search docker-compose)

Utilize a docker volume to access logs on the host or another container, between two (or more) containers share a docker volume and point the directories in `log _files.yml` at this directory
google.com (search marathon)

Managing multiple volumes (log files/directories that contain logs) is managable and extensible with proper container orchestration; additionaly steps should be taken in production enviroments to ensure reads/writes/truncating/rotation etc is done properly within docker volumes (fine tunning the enviroment)

0 comments on commit bc0646c

Please sign in to comment.