diff --git a/engine/examples/apt-cacher-ng.md b/engine/examples/apt-cacher-ng.md index a167c44446..9723b9e237 100644 --- a/engine/examples/apt-cacher-ng.md +++ b/engine/examples/apt-cacher-ng.md @@ -16,35 +16,43 @@ the second download of any package almost instant. Use the following Dockerfile: - # - # Build: docker build -t apt-cacher . - # Run: docker run -d -p 3142:3142 --name apt-cacher-run apt-cacher - # - # and then you can run containers with: - # docker run -t -i --rm -e http_proxy http://dockerhost:3142/ debian bash - # - # Here, `dockerhost` is the IP address or FQDN of a host running the Docker daemon - # which acts as an APT proxy server. - FROM ubuntu +```dockerfile +# +# Build: docker build -t apt-cacher . +# Run: docker run -d -p 3142:3142 --name apt-cacher-run apt-cacher +# +# and then you can run containers with: +# docker run -t -i --rm -e http_proxy http://dockerhost:3142/ debian bash +# +# Here, `dockerhost` is the IP address or FQDN of a host running the Docker daemon +# which acts as an APT proxy server. +FROM ubuntu - VOLUME ["/var/cache/apt-cacher-ng"] - RUN apt-get update && apt-get install -y apt-cacher-ng +VOLUME ["/var/cache/apt-cacher-ng"] +RUN apt-get update && apt-get install -y apt-cacher-ng - EXPOSE 3142 - CMD chmod 777 /var/cache/apt-cacher-ng && /etc/init.d/apt-cacher-ng start && tail -f /var/log/apt-cacher-ng/* +EXPOSE 3142 +CMD chmod 777 /var/cache/apt-cacher-ng && /etc/init.d/apt-cacher-ng start && tail -f /var/log/apt-cacher-ng/* +``` To build the image using: - $ docker build -t eg_apt_cacher_ng . +```bash +$ docker build -t eg_apt_cacher_ng . +``` Then run it, mapping the exposed port to one on the host - $ docker run -d -p 3142:3142 --name test_apt_cacher_ng eg_apt_cacher_ng +```bash +$ docker run -d -p 3142:3142 --name test_apt_cacher_ng eg_apt_cacher_ng +``` To see the logfiles that are `tailed` in the default command, you can use: - $ docker logs -f test_apt_cacher_ng +```bash +$ docker logs -f test_apt_cacher_ng +``` To get your Debian-based containers to use the proxy, you have following options. Replace `dockerhost` with the @@ -63,58 +71,70 @@ container. **Option 1** injects the settings safely into your apt configuration in a local version of a common base: - FROM ubuntu - RUN echo 'Acquire::http { Proxy "http://dockerhost:3142"; };' >> /etc/apt/apt.conf.d/01proxy - RUN apt-get update && apt-get install -y vim git +```dockerfile +FROM ubuntu +RUN echo 'Acquire::http { Proxy "http://dockerhost:3142"; };' >> /etc/apt/apt.conf.d/01proxy +RUN apt-get update && apt-get install -y vim git - # docker build -t my_ubuntu . +# docker build -t my_ubuntu . +``` **Option 2** is good for testing, but breaks other HTTP clients which obey `http_proxy`, such as `curl`, `wget` and others: - $ docker run --rm -t -i -e http_proxy=http://dockerhost:3142/ debian bash +```bash +$ docker run --rm -t -i -e http_proxy=http://dockerhost:3142/ debian bash +``` **Option 3** is the least portable, but you might need to do it and you can do it from your `Dockerfile` too. **Option 4** links Debian-containers to the proxy server using following command: - $ docker run -i -t --link test_apt_cacher_ng:apt_proxy -e http_proxy=http://apt_proxy:3142/ debian bash +```bash +$ docker run -i -t --link test_apt_cacher_ng:apt_proxy -e http_proxy=http://apt_proxy:3142/ debian bash +``` **Option 5** creates a custom network of APT proxy server and Debian-based containers: - $ docker network create mynetwork - $ docker run -d -p 3142:3142 --network=mynetwork --name test_apt_cacher_ng eg_apt_cacher_ng - $ docker run --rm -it --network=mynetwork -e http_proxy=http://test_apt_cacher_ng:3142/ debian bash +```bash +$ docker network create mynetwork +$ docker run -d -p 3142:3142 --network=mynetwork --name test_apt_cacher_ng eg_apt_cacher_ng +$ docker run --rm -it --network=mynetwork -e http_proxy=http://test_apt_cacher_ng:3142/ debian bash +``` Apt-cacher-ng has some tools that allow you to manage the repository, and they can be used by leveraging the `VOLUME` instruction, and the image we built to run the service: - $ docker run --rm -t -i --volumes-from test_apt_cacher_ng eg_apt_cacher_ng bash +```bash +$ docker run --rm -t -i --volumes-from test_apt_cacher_ng eg_apt_cacher_ng bash - root@f38c87f2a42d:/# /usr/lib/apt-cacher-ng/distkill.pl - Scanning /var/cache/apt-cacher-ng, please wait... - Found distributions: - bla, taggedcount: 0 - 1. precise-security (36 index files) - 2. wheezy (25 index files) - 3. precise-updates (36 index files) - 4. precise (36 index files) - 5. wheezy-updates (18 index files) +root@f38c87f2a42d:/# /usr/lib/apt-cacher-ng/distkill.pl +Scanning /var/cache/apt-cacher-ng, please wait... +Found distributions: +bla, taggedcount: 0 + 1. precise-security (36 index files) + 2. wheezy (25 index files) + 3. precise-updates (36 index files) + 4. precise (36 index files) + 5. wheezy-updates (18 index files) - Found architectures: - 6. amd64 (36 index files) - 7. i386 (24 index files) +Found architectures: + 6. amd64 (36 index files) + 7. i386 (24 index files) - WARNING: The removal action may wipe out whole directories containing - index files. Select d to see detailed list. +WARNING: The removal action may wipe out whole directories containing + index files. Select d to see detailed list. - (Number nn: tag distribution or architecture nn; 0: exit; d: show details; r: remove tagged; q: quit): q +(Number nn: tag distribution or architecture nn; 0: exit; d: show details; r: remove tagged; q: quit): q +``` Finally, clean up after your test by stopping and removing the container, and then removing the image. - $ docker container stop test_apt_cacher_ng - $ docker container rm test_apt_cacher_ng - $ docker image rm eg_apt_cacher_ng +```bash +$ docker container stop test_apt_cacher_ng +$ docker container rm test_apt_cacher_ng +$ docker image rm eg_apt_cacher_ng +``` diff --git a/engine/examples/couchdb_data_volumes.md b/engine/examples/couchdb_data_volumes.md index c80559a0cb..b9d2d441c1 100644 --- a/engine/examples/couchdb_data_volumes.md +++ b/engine/examples/couchdb_data_volumes.md @@ -4,8 +4,9 @@ keywords: docker, example, package installation, networking, couchdb, data volu title: Dockerize a CouchDB service --- -> **Note**: -> - **If you don't like sudo** then see [*Giving non-root access*](../install/linux-postinstall.md#manage-docker-as-a-non-root-user) +> **Note** +> +> **If you don't like sudo** then see [*Giving non-root access*](../install/linux-postinstall.md#manage-docker-as-a-non-root-user) Here's an example of using data volumes to share the same data between two CouchDB containers. This could be used for hot upgrades, testing @@ -15,28 +16,36 @@ different versions of CouchDB on the same data, etc. We're marking `/var/lib/couchdb` as a data volume. - $ COUCH1=$(docker run -d -p 5984 -v /var/lib/couchdb shykes/couchdb:2013-05-03) +```bash +$ COUCH1=$(docker run -d -p 5984 -v /var/lib/couchdb shykes/couchdb:2013-05-03) +``` ## Add data to the first database We're assuming your Docker host is reachable at `localhost`. If not, replace `localhost` with the public IP of your Docker host. - $ HOST=localhost - $ URL="http://$HOST:$(docker port $COUCH1 5984 | grep -o '[1-9][0-9]*$')/_utils/" - $ echo "Navigate to $URL in your browser, and use the couch interface to add data" +```bash +$ HOST=localhost +$ URL="http://$HOST:$(docker port $COUCH1 5984 | grep -o '[1-9][0-9]*$')/_utils/" +$ echo "Navigate to $URL in your browser, and use the couch interface to add data" +``` ## Create second database This time, we're requesting shared access to `$COUCH1`'s volumes. - $ COUCH2=$(docker run -d -p 5984 --volumes-from $COUCH1 shykes/couchdb:2013-05-03) +```bash +$ COUCH2=$(docker run -d -p 5984 --volumes-from $COUCH1 shykes/couchdb:2013-05-03) +``` ## Browse data on the second database - $ HOST=localhost - $ URL="http://$HOST:$(docker port $COUCH2 5984 | grep -o '[1-9][0-9]*$')/_utils/" - $ echo "Navigate to $URL in your browser. You should see the same data as in the first database"'!' +```bash +$ HOST=localhost +$ URL="http://$HOST:$(docker port $COUCH2 5984 | grep -o '[1-9][0-9]*$')/_utils/" +$ echo "Navigate to $URL in your browser. You should see the same data as in the first database"'!' +``` Congratulations, you are now running two Couchdb containers, completely isolated from each other *except* for their data. diff --git a/engine/examples/running_riak_service.md b/engine/examples/running_riak_service.md index e3c8b5ddcb..ed57407ba9 100644 --- a/engine/examples/running_riak_service.md +++ b/engine/examples/running_riak_service.md @@ -11,86 +11,104 @@ Riak pre-installed. Create an empty file called `Dockerfile`: - $ touch Dockerfile +```bash +$ touch Dockerfile +``` Next, define the parent image you want to use to build your image on top of. We use [Ubuntu](https://hub.docker.com/_/ubuntu/) (tag: `trusty`), which is available on [Docker Hub](https://hub.docker.com): - # Riak - # - # VERSION 0.1.1 +```dockerfile +# Riak +# +# VERSION 0.1.1 - # Use the Ubuntu parent image provided by dotCloud - FROM ubuntu:trusty +# Use the Ubuntu parent image provided by dotCloud +FROM ubuntu:trusty +``` After that, we install the curl which is used to download the repository setup script and we download the setup script and run it. - # Install Riak repository before we do apt-get update, so that update happens - # in a single step - RUN apt-get install -q -y curl && \ - curl -fsSL https://packagecloud.io/install/repositories/basho/riak/script.deb | sudo bash +```dockerfile +# Install Riak repository before we do apt-get update, so that update happens +# in a single step +RUN apt-get install -q -y curl && \ + curl -fsSL https://packagecloud.io/install/repositories/basho/riak/script.deb | sudo bash +``` Then we install and setup a few dependencies: - `supervisor` is used manage the Riak processes - `riak=2.0.5-1` is the Riak package coded to version 2.0.5 - +```dockerfile +# Install and setup project dependencies +RUN apt-get update && \ + apt-get install -y supervisor riak=2.0.5-1 - # Install and setup project dependencies - RUN apt-get update && \ - apt-get install -y supervisor riak=2.0.5-1 +RUN mkdir -p /var/log/supervisor - RUN mkdir -p /var/log/supervisor +RUN locale-gen en_US en_US.UTF-8 - RUN locale-gen en_US en_US.UTF-8 - - COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf +COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf +``` After that, we modify Riak's configuration: - # Configure Riak to accept connections from any host - RUN sed -i "s|listener.http.internal = 127.0.0.1:8098|listener.http.internal = 0.0.0.0:8098|" /etc/riak/riak.conf - RUN sed -i "s|listener.protobuf.internal = 127.0.0.1:8087|listener.protobuf.internal = 0.0.0.0:8087|" /etc/riak/riak.conf +```dockerfile +# Configure Riak to accept connections from any host +RUN sed -i "s|listener.http.internal = 127.0.0.1:8098|listener.http.internal = 0.0.0.0:8098|" /etc/riak/riak.conf +RUN sed -i "s|listener.protobuf.internal = 127.0.0.1:8087|listener.protobuf.internal = 0.0.0.0:8087|" /etc/riak/riak.conf +``` Then, we expose the Riak Protocol Buffers and HTTP interfaces: - # Expose Riak Protocol Buffers and HTTP interfaces - EXPOSE 8087 8098 +```dockerfile +# Expose Riak Protocol Buffers and HTTP interfaces +EXPOSE 8087 8098 +``` Finally, run `supervisord` so that Riak is started: - CMD ["/usr/bin/supervisord"] +```dockerfile +CMD ["/usr/bin/supervisord"] +``` ## Create a supervisord configuration file Create an empty file called `supervisord.conf`. Make sure it's at the same directory level as your `Dockerfile`: - touch supervisord.conf +```bash +touch supervisord.conf +``` Populate it with the following program definitions: - [supervisord] - nodaemon=true +```ini +[supervisord] +nodaemon=true - [program:riak] - command=bash -c "/usr/sbin/riak console" - numprocs=1 - autostart=true - autorestart=true - user=riak - environment=HOME="/var/lib/riak" - stdout_logfile=/var/log/supervisor/%(program_name)s.log - stderr_logfile=/var/log/supervisor/%(program_name)s.log +[program:riak] +command=bash -c "/usr/sbin/riak console" +numprocs=1 +autostart=true +autorestart=true +user=riak +environment=HOME="/var/lib/riak" +stdout_logfile=/var/log/supervisor/%(program_name)s.log +stderr_logfile=/var/log/supervisor/%(program_name)s.log +``` ## Build the Docker image for Riak Now you can build a Docker image for Riak: - $ docker build -t "/riak" . +```bash +$ docker build -t "/riak" . +``` ## Next steps