Commit 08f5209b authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit

{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
\f0\fs24 \cf0 No work files for this lesson...}
\ No newline at end of file
FROM debian:jessie
RUN mkdir /vol && touch /vol/file1
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
long long readLongFile(char *file) {
FILE *f = fopen(file, "r");
if (!f) {
return -1;
char buffer[30]; // enough to contain "9223372036854771712" (20 chars) with some give
size_t bytes = fread(buffer, sizeof(*buffer), sizeof(buffer), f);
if (bytes < 1) {
return -1;
buffer[bytes] = 0;
return atoll(buffer);
void printMemUsage() {
double usage = readLongFile("/sys/fs/cgroup/memory/memory.usage_in_bytes") / 1024.0 / 1024.0;
double limit = readLongFile("/sys/fs/cgroup/memory/memory.limit_in_bytes") / 1024.0 / 1024.0;
printf("current usage within memory cgroup: %.02f MB / %.02f MB\n", usage, limit);
void forceMalloc(size_t bytes) {
printf("malloc: %zu MB", bytes / 1024 / 1024);
size_t ints = bytes / sizeof(int);
int *ptr = malloc(bytes);
size_t i;
for (i = 0; i < ints; ++i) {
ptr[i] = rand();
int main() {
printMemUsage(); // ~ 0 MB
forceMalloc(100 * 1024 * 1024);
printMemUsage(); // ~ 100 MB
forceMalloc(100 * 1024 * 1024);
printMemUsage(); // ~ 200 MB
return 0;
version: '2'
image: mariadb
- wordpress_db
image: wordpress
- 8080:80
WORDPRESS_DB_HOST: wordpress_db
"docker.": {
"type": "containers",
"socket": "unix:///var/run/docker.sock"
"local.": {
"type": "forwarding",
"nameservers": [ "" ]
".": {
"type": "forwarding",
"nameservers": [ "", "" ]
#Must run with '--priviledged' flag, and /var/run/docker.sock mounted.
FROM docker:1.11
COPY root /var/spool/cron/crontabs/root
RUN chmod 0644 /var/spool/cron/crontabs/root
VOLUME /backup
CMD crond -f -d 0
version: '2'
image: logstash:2.3
restart: always
command: [
input {
gelf {
output {
elasticsearch {
hosts => "elasticsearch:9200"
- 12201/udp
- 5000/tcp
- 12201:12201/udp
- 5000:5000/tcp
image: elasticsearch:2.3
restart: always
image: kibana:4.5
restart: always
- 5601:5601
set -e
# allow postgres flags to be passed on the docker run
#if [ "${1:0:1}" = '-' ]; then
# set -- postgres "$@"
if [ "$1" = 'postgres' ]; then
# look specifically for PG_VERSION, as it is expected in the DB dir
if [ ! -s "$PGDATA/PG_VERSION" ]; then
# setup an access control file
{ echo; echo "host all all trust"; } >> "$PGDATA/pg_hba.conf"
# WARNING this config is VERY insecure
exec "$@"
FROM debian:jessie
# explicitly set user/group IDs
RUN groupadd -r postgres --gid=999 && useradd -r -g postgres --uid=999 postgres
# add the gpg key for apt repos
RUN apt-key adv --keyserver --recv-keys B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8
# specify a version
ENV PG_VERSION 9.5.3-1.pgdg80+1
# add the repo to our apt sources
RUN echo 'deb jessie-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list
# install postgres, pinning to a specific version
# also make sure it doesn't try to initialize the database
RUN apt-get update \
&& apt-get install -y postgresql-common \
&& sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf \
&& apt-get install -y \
postgresql-contrib-$PG_MAJOR=$PG_VERSION \
postgresql-contrib-$PG_MAJOR=$PG_VERSION \
&& rm -rf /var/lib/apt/lists/* \
# listen on all interfaces
&& sed -ri "s!^#?(listen_addresses)\s*=\s*\S+.*!\1 = '*'!" /usr/share/postgresql/$PG_MAJOR/postgresql.conf.sample
# add postgres binaries to the PATH for ease of use
ENV PATH /usr/lib/postgresql/$PG_MAJOR/bin:$PATH
# setup directories for data and run (pid file)
ENV PGDATA /var/lib/postgresql/data
RUN mkdir -p /var/run/postgresql "$PGDATA" && chown -R postgres /var/run/postgresql "$PGDATA"
# volume for the database files
VOLUME /var/lib/postgresql/data
# add our custom entrypoint to the path for ease of use
COPY /usr/local/bin/
# step down from root
USER postgres
# set our entrypoint and cmd
CMD ["postgres"]
* * * * * sh -c 'docker run --net=mysql_net --rm mysql bash -c "mysqldump --host=some-mysql --user=root --password='my-secret-pw' --all-databases" > "/backup/$(date +%F\[%T\]).sql"'
Due to ongoing efforts to ensure you have the best possible learning experience, we may update the working files for this course from time to time.
We recommend that you download the latest version of these files from:
\ No newline at end of file
## Example files for the title:
# Advanced Containerization, by Talon Bowler
[![Advanced Containerization, by Talon Bowler](](
The following applies to example files from material published by O’Reilly Media, Inc. Content from other publishers may include different rules of usage. Please refer to any additional usage rights explained in the actual example files or refer to the publisher’s website.
O'Reilly books are here to help you get your job done. In general, you may use the code in O'Reilly books in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from our books does not require permission. Answering a question by citing our books and quoting example code does not require permission. On the other hand, selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Incorporating a significant amount of example code from our books into your product's documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN.
If you think your use of code examples falls outside fair use or the permission given here, feel free to contact us at <>.
Please note that the examples are not production code and have not been carefully testing. They are provided "as-is" and come with no warranty of any kind.

9.2 KB

Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment