Skip to content

Instantly share code, notes, and snippets.

@bashkirtsevich
Last active January 21, 2023 14:34
Show Gist options
  • Save bashkirtsevich/f7d17d6b9a44a1a806ef0dea26bd81cd to your computer and use it in GitHub Desktop.
Save bashkirtsevich/f7d17d6b9a44a1a806ef0dea26bd81cd to your computer and use it in GitHub Desktop.
mongo, elasticsearch & nginx in docker

Elasticsearch Dockerfile

This repository contains Dockerfile of Elasticsearch for Docker's automated build published to the public Docker Hub Registry.

Base Docker Image

Installation

  1. Install Docker.

  2. Download automated build from public Docker Hub Registry: docker pull dockerfile/elasticsearch

    (alternatively, you can build an image from Dockerfile: docker build -t="dockerfile/elasticsearch" github.com/dockerfile/elasticsearch)

Usage

docker run -d -p 9200:9200 -p 9300:9300 dockerfile/elasticsearch

Attach persistent/shared directories

  1. Create a mountable data directory <data-dir> on the host.

  2. Create Elasticsearch config file at <data-dir>/elasticsearch.yml.

path:
  data: /data/data
  logs: /data/log
  plugins: /data/plugins
  work: /data/work
  1. Start a container by mounting data directory and specifying the custom configuration file:
```sh
docker run -d -p 9200:9200 -p 9300:9300 -v <data-dir>:/data dockerfile/elasticsearch /elasticsearch/bin/elasticsearch -Des.config=/data/elasticsearch.yml
```

After few seconds, open http://<host>:9200 to see the result.

MongoDB Dockerfile

This repository contains Dockerfile of MongoDB for Docker's automated build published to the public Docker Hub Registry.

Base Docker Image

Installation

  1. Install Docker.

  2. Download automated build from public Docker Hub Registry: docker pull dockerfile/mongodb

    (alternatively, you can build an image from Dockerfile: docker build -t="dockerfile/mongodb" github.com/dockerfile/mongodb)

Usage

Run mongod

docker run -d -p 27017:27017 --name mongodb dockerfile/mongodb

Run mongod w/ persistent/shared directory

docker run -d -p 27017:27017 -v <db-dir>:/data/db --name mongodb dockerfile/mongodb

Run mongod w/ HTTP support

docker run -d -p 27017:27017 -p 28017:28017 --name mongodb dockerfile/mongodb mongod --rest --httpinterface

Run mongod w/ Smaller default file size

docker run -d -p 27017:27017 --name mongodb dockerfile/mongodb mongod --smallfiles

Run mongo

docker run -it --rm --link mongodb:mongodb dockerfile/mongodb bash -c 'mongo --host mongodb'
Usage with VirtualBox (boot2docker-vm)

You will need to set up nat port forwarding with:

VBoxManage modifyvm "boot2docker-vm" --natpf1 "guestmongodb,tcp,127.0.0.1,27017,,27017"

This will allow you to connect to your mongo container with the standard mongo commands.

Nginx Dockerfile

This repository contains Dockerfile of Nginx for Docker's automated build published to the public Docker Hub Registry.

Base Docker Image

Installation

  1. Install Docker.

  2. Download automated build from public Docker Hub Registry: docker pull dockerfile/nginx

    (alternatively, you can build an image from Dockerfile: docker build -t="dockerfile/nginx" github.com/dockerfile/nginx)

Usage

docker run -d -p 80:80 dockerfile/nginx

Attach persistent/shared directories

docker run -d -p 80:80 -v <sites-enabled-dir>:/etc/nginx/conf.d -v <certs-dir>:/etc/nginx/certs -v <log-dir>:/var/log/nginx -v <html-dir>:/var/www/html dockerfile/nginx

After few seconds, open http://<host> to see the welcome page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment