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