Skip to content
Snippets Groups Projects
Commit 4f690e05 authored by MGregoire's avatar MGregoire
Browse files

Base pour les dockerfiles Mongo et Redis

parent 9c9d877d
No related branches found
No related tags found
No related merge requests found
FROM ubuntu:14.04
MAINTAINER Tutum Labs <support@tutum.co>
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 && \
echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list && \
apt-get update && \
apt-get install -y --force-yes pwgen mongodb-org mongodb-org-server mongodb-org-shell mongodb-org-mongos mongodb-org-tools && \
echo "mongodb-org hold" | dpkg --set-selections && echo "mongodb-org-server hold" | dpkg --set-selections && \
echo "mongodb-org-shell hold" | dpkg --set-selections && \
echo "mongodb-org-mongos hold" | dpkg --set-selections && \
echo "mongodb-org-tools hold" | dpkg --set-selections
VOLUME /data/db
ENV AUTH yes
ENV STORAGE_ENGINE wiredTiger
ENV JOURNALING yes
ADD run.sh /run.sh
ADD set_mongodb_password.sh /set_mongodb_password.sh
RUN chmod +x /run.sh
RUN chmod +x /set_mongodb_password.sh
EXPOSE 27017 28017
CMD ["/run.sh"]
FROM ubuntu:14.04
MAINTAINER Grégoire Martinache <gmartina@etu.utc.fr>
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 && \
echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list && \
apt-get update && \
apt-get install -y --force-yes pwgen mongodb-org mongodb-org-server mongodb-org-shell mongodb-org-mongos mongodb-org-tools && \
echo "mongodb-org hold" | dpkg --set-selections && echo "mongodb-org-server hold" | dpkg --set-selections && \
echo "mongodb-org-shell hold" | dpkg --set-selections && \
echo "mongodb-org-mongos hold" | dpkg --set-selections && \
echo "mongodb-org-tools hold" | dpkg --set-selections
VOLUME /data/db
ENV AUTH yes
ENV STORAGE_ENGINE wiredTiger
ENV JOURNALING yes
ADD run.sh /run.sh
ADD set_mongodb_password.sh /set_mongodb_password.sh
RUN chmod +x /run.sh
RUN chmod +x /set_mongodb_password.sh
EXPOSE 27017 28017
CMD ["/run.sh"]
Ce dockerfile permet de mettre un mot de passe sur la base Mongo via une variable d'environnement (contrairement au build officiel).
Build le dockerfile puis créer le container grâce à runScript.sh
Basé sur la version de tutumcloud (Github)
\ No newline at end of file
#!/bin/bash
set -m
mongodb_cmd="mongod --storageEngine $STORAGE_ENGINE"
cmd="$mongodb_cmd --httpinterface --rest --master"
if [ "$AUTH" == "yes" ]; then
cmd="$cmd --auth"
fi
if [ "$JOURNALING" == "no" ]; then
cmd="$cmd --nojournal"
fi
if [ "$OPLOG_SIZE" != "" ]; then
cmd="$cmd --oplogSize $OPLOG_SIZE"
fi
$cmd &
if [ ! -f /data/db/.mongodb_password_set ]; then
/set_mongodb_password.sh
fi
fg
#!/bin/bash
docker run -v /root/mongo/data:/data/db -d --name mongoLatex -p 27017:27017 -p 28017:28017 -e MONGODB_USER="USERNAME" -e MONGODB_DATABASE="DBNAME" -e MONGODB_PASS="PASSWORD" dockerfile/mongodb
#!/bin/bash
USER=${MONGODB_USER:-"admin"}
DATABASE=${MONGODB_DATABASE:-"admin"}
PASS=${MONGODB_PASS:-$(pwgen -s 12 1)}
_word=$( [ ${MONGODB_PASS} ] && echo "preset" || echo "random" )
RET=1
while [[ RET -ne 0 ]]; do
echo "=> Waiting for confirmation of MongoDB service startup"
sleep 5
mongo admin --eval "help" >/dev/null 2>&1
RET=$?
done
echo "=> Creating an ${USER} user with a ${_word} password in MongoDB"
mongo admin --eval "db.createUser({user: '$USER', pwd: '$PASS', roles:[{role:'root',db:'admin'}]});"
if [ "$DATABASE" != "admin" ]; then
echo "=> Creating an ${USER} user with a ${_word} password in MongoDB"
mongo admin -u $USER -p $PASS << EOF
use $DATABASE
db.createUser({user: '$USER', pwd: '$PASS', roles:[{role:'dbOwner',db:'$DATABASE'}]})
EOF
fi
echo "=> Done!"
touch /data/db/.mongodb_password_set
echo "========================================================================"
echo "You can now connect to this MongoDB server using:"
echo ""
echo " mongo $DATABASE -u $USER -p $PASS --host <host> --port <port>"
echo ""
echo "Please remember to change the above password as soon as possible!"
echo "========================================================================"
Ce dockerfile permet de mettre un mot de passe sur la base Mongo via une variable d'environnement (contrairement au build officiel).
Build le dockerfile puis créer le container grâce à runScript.sh
\ No newline at end of file
# Pull base image.
FROM ubuntu
MAINTAINER Grégoire Martinache <gmartina@etu.utc.fr>
# Install Redis.
RUN \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends apt-utils && \
DEBIAN_FRONTEND=noninteractive apt-get upgrade -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y wget build-essential && \
cd /tmp && \
wget http://download.redis.io/redis-stable.tar.gz && \
tar xvzf redis-stable.tar.gz && \
cd redis-stable && \
make && \
make install && \
cp -f src/redis-sentinel /usr/local/bin && \
mkdir -p /etc/redis && \
cp -f *.conf /etc/redis && \
rm -rf /tmp/redis-stable* && \
sed -i 's/^\(bind .*\)$/# \1/' /etc/redis/redis.conf && \
sed -i 's/^\(daemonize .*\)$/# \1/' /etc/redis/redis.conf && \
sed -i 's/^\(dir .*\)$/# \1\ndir \/data/' /etc/redis/redis.conf && \
sed -i 's/^\(logfile .*\)$/# \1/' /etc/redis/redis.conf
# Define mountable directories.
VOLUME ["/data"]
# Define working directory.
WORKDIR /data
# Define default command.
CMD ["redis-server", "/etc/redis/redis.conf"]
# Expose ports.
EXPOSE 6379
#
# Redis Dockerfile
#
# https://github.com/dockerfile/redis
#
# Pull base image.
FROM ubuntu
# Install Redis.
RUN \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends apt-utils && \
DEBIAN_FRONTEND=noninteractive apt-get upgrade -y && \
DEBIAN_FRONTEND=noninteractive apt-get install -y wget build-essential && \
cd /tmp && \
wget http://download.redis.io/redis-stable.tar.gz && \
tar xvzf redis-stable.tar.gz && \
cd redis-stable && \
make && \
make install && \
cp -f src/redis-sentinel /usr/local/bin && \
mkdir -p /etc/redis && \
cp -f *.conf /etc/redis && \
rm -rf /tmp/redis-stable* && \
sed -i 's/^\(bind .*\)$/# \1/' /etc/redis/redis.conf && \
sed -i 's/^\(daemonize .*\)$/# \1/' /etc/redis/redis.conf && \
sed -i 's/^\(dir .*\)$/# \1\ndir \/data/' /etc/redis/redis.conf && \
sed -i 's/^\(logfile .*\)$/# \1/' /etc/redis/redis.conf
# Define mountable directories.
VOLUME ["/data"]
# Define working directory.
WORKDIR /data
# Define default command.
CMD ["redis-server", "/etc/redis/redis.conf"]
# Expose ports.
EXPOSE 6379
Build then run runScript.sh
\ No newline at end of file
Launch build.sh
Launch make.sh
docker pull redis
docker run -d -p 6379:6379 -v ~/PATH/TO/FOLDER:/data --name redis dockerfile/redis redis-server /etc/redis/redis.conf --requirepass PASSWORDHERE
docker pull redis
docker run -d -p 6379:6379 -v /root/redis/data:/data --name redisLatex dockerfile/redislatex redis-server /etc/redis/redis.conf --requirepass iBzVUEOSh0r0j1Gmnfgm
docker run -v /root/mongo/data:/data/db -d --name mongoLatex -p 27017:27017 -p 28017:28017 -e MONGODB_USER="admin" -e MONGODB_DATABASE="sharelatex" -e MONGODB_PASS="KUhaBqf6582Nnwopm7Kp" dockerfile/mongodb
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment