Docker

From syn2cat - HackerSpace.lu
(Difference between revisions)
Jump to: navigation, search
(Engelsystem)
 
(10 intermediate revisions by one user not shown)
Line 2: Line 2:
  
 
Yeah, DAU-docker!
 
Yeah, DAU-docker!
 
ATTENTION this uses default passwords, and is completely unsecure !!!!
 
  
 
==First install docker==
 
==First install docker==
Line 10: Line 8:
 
* # logoout/login to get your group attribution
 
* # logoout/login to get your group attribution
  
 +
==Learn something about the docker philosophy==
 +
You usually never log in to the container but specify all settings in the Dockerfile. Recreating the container should give you a ready to run application.
 +
 +
Most installs don't care really what happens to your data, but docker has a feature for this. Put the data into a separate container than the application. Then make the data container mount points visible in your application container. This way you can replace the application (update) without needing a backup/restore step.
  
 
==Mediawiki==
 
==Mediawiki==
  
Create a database
+
===Fist some settings===
* # no idea what this does, I just pasted it from https://hub.docker.com/_/mysql/
+
* WEBPORT=8080 # on which port the webserver should listen on the main host, if you have already a webserver, 80 won't work
* docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest
+
* DBPASSWORD="$(openssl rand -base64 9)" # the password for the database (humm... save it :-)
 +
* DOCKERNAME="mediawiki"
  
Create a mediawiki
+
===Create a database===
 +
* # inspired from https://hub.docker.com/_/mysql/
 +
* # Create a data container with a directory /var/lib/mysql
 +
* docker create -v /var/lib/mysql --name wiki-mysql-data mysql:latest /bin/true
 +
* docker run --name wiki-mysql --volumes-from wiki-mysql-data -e MYSQL_ROOT_PASSWORD=$DBPASSWORD -d mysql:latest
 +
* docker ps -a | grep wiki-mysql.* # look the nice containers we just did
 +
 
 +
===Create a mediawiki===
 +
<!--
 
* # well probably something like found here https://hub.docker.com/r/synctree/mediawiki/
 
* # well probably something like found here https://hub.docker.com/r/synctree/mediawiki/
* docker run --name some-mediawiki --link some-mysql:mysql -p 8080:80 -d synctree/mediawiki
+
* docker run --name $DOCKERNAME --link wiki-mysql:mysql -p $WEBPORT:80 -d synctree/mediawiki
 +
-->
 +
 
 +
well probably something like found here https://hub.docker.com/r/nickstenning/mediawiki/ (with data container support)
 +
as stated on that webpage:
 +
* docker run --name $DOCKERNAME --link wiki-mysql:mysql -p $WEBPORT:80 -d nickstenning/mediawiki
  
* firefox http://localhost:8080/
+
===Configure mediawiki===
 +
* echo "connect to http://localhost:$WEBPORT/"
 +
* click on "setup the wiki"
 
** database host: mysql
 
** database host: mysql
 
** database name: mysql
 
** database name: mysql
** table prefix: mw
+
** table prefix: mw     #change this if you install more than one mediawiki into this database
 
** username: root
 
** username: root
** password: my-secret-pw
+
** echo password: $DBPASSWORD
 
** at end of setup you get a LocalSettings.php to download
 
** at end of setup you get a LocalSettings.php to download
** this file has to be provided to the docker or put into the container. Seems to be several ways to do it, but none work. So this one works:
+
** this file has to be provided to the docker or put into the container. Seems to be several ways to do it.
* cat LocalSettings.php | docker exec -i some-mediawiki sh -c 'cat > /var/www/html/LocalSettings.php'
+
* docker stop $DOCKERNAME    # stop the container as we want to mount data...
* docker exec -i some-mediawiki chown www-data:www-data /var/www/html/LocalSettings.php
+
* docker rm $DOCKERNAME  # I have no idea how to add parameters, so I just start from zero
* docker exec -i some-mediawiki chmod 444 /var/www/html/LocalSettings.php
+
* firefox http://localhost:8080/index.php
+
===Create wiki data container===
 +
* docker create --name ${DOCKERNAME}-data -v /data nickstenning/mediawiki /bin/true
 +
* docker run --name ${DOCKERNAME} --volumes-from ${DOCKERNAME}-data --link wiki-mysql:mysql -p $WEBPORT:80 -d nickstenning/mediawiki
 +
* cat LocalSettings.php | docker exec -i ${DOCKERNAME} sh -c 'cat > /data/LocalSettings.php'
 +
* docker exec -i ${DOCKERNAME} chown www-data:www-data /data/LocalSettings.php
 +
* docker exec -i ${DOCKERNAME} chmod 444 /data/LocalSettings.php
 +
 
 +
* echo "wiki is on http://localhost:$WEBPORT/index.php"
  
 
More help: well the usual mediawiki help
 
More help: well the usual mediawiki help
  
 
==Engelsystem==
 
==Engelsystem==
 +
This does not use a data container, but as it's often only for a short event, I don't care.
 +
 
Give some configuration stuff
 
Give some configuration stuff
 
* ENGELPORT=80    # on which port the engel system should listen on the main host, if you have a webserver, 80 won't work
 
* ENGELPORT=80    # on which port the engel system should listen on the main host, if you have a webserver, 80 won't work
Line 51: Line 78:
 
* docker build -t engelweb-app .  # this takes a long time
 
* docker build -t engelweb-app .  # this takes a long time
 
* docker run --name "$DOCKERNAME" -d -p ${ENGELPORT}:80 -p ${ENGELDB}:3306 -e MYSQL_PASS="$DBPASSWORD" engelweb-app
 
* docker run --name "$DOCKERNAME" -d -p ${ENGELPORT}:80 -p ${ENGELDB}:3306 -e MYSQL_PASS="$DBPASSWORD" engelweb-app
 
For some unknown reason the --name parameter is not used and you find yourself with a silly name WTF
 
* # docker ps  - ( Die CONTAINER_ID merken... )
 
* # docker exec -i -t "$DOCKERNAME" bash  # da stand anstatt engelsystem die containerid
 
* # docker rename containerid "$DOCKERNAME"
 
 
* docker exec -t "$DOCKERNAME" sed -i 's/-pengel/-p'$DBPASSWORD'/' /engelweb/db/createdb.sh  # needed coz db pass hardcoded
 
* docker exec -t "$DOCKERNAME" sed -i 's/-pengel/-p'$DBPASSWORD'/' /engelweb/db/createdb.sh  # needed coz db pass hardcoded
 
* docker exec -t "$DOCKERNAME" /engelweb/db/createdb.sh engelsystem engeladmin "$ENGELPASSWORD"  
 
* docker exec -t "$DOCKERNAME" /engelweb/db/createdb.sh engelsystem engeladmin "$ENGELPASSWORD"  
 
* docker exec -t "$DOCKERNAME" sh -c "/usr/bin/mysql -uadmin -p$DBPASSWORD engelsystem < /engelweb/db/install.sql"
 
* docker exec -t "$DOCKERNAME" sh -c "/usr/bin/mysql -uadmin -p$DBPASSWORD engelsystem < /engelweb/db/install.sql"
 +
* docker exec -t "$DOCKERNAME" sh -c "/usr/bin/mysql -uadmin -p$DBPASSWORD engelsystem < /engelweb/db/update.sql"
  
 
* echo "Please remember the database password: $DBPASSWORD"
 
* echo "Please remember the database password: $DBPASSWORD"
 
* echo "Please remember the engelsystem login: ${ENGELADMIN} ${ENGELPASSWORD}"
 
* echo "Please remember the engelsystem login: ${ENGELADMIN} ${ENGELPASSWORD}"
 +
* echo login to http://localhost:$ENGELPORT/ with user 'admin' and password 'asdfasdf'

Latest revision as of 00:16, 9 February 2016

My little page about getting docker to run, done by somebody having no idea what docker is.

Yeah, DAU-docker!

Contents

[edit] First install docker

  • sudo apt-get install docker.io
  • sudo usermod -a -G docker $(id -un)
  • # logoout/login to get your group attribution

[edit] Learn something about the docker philosophy

You usually never log in to the container but specify all settings in the Dockerfile. Recreating the container should give you a ready to run application.

Most installs don't care really what happens to your data, but docker has a feature for this. Put the data into a separate container than the application. Then make the data container mount points visible in your application container. This way you can replace the application (update) without needing a backup/restore step.

[edit] Mediawiki

[edit] Fist some settings

  • WEBPORT=8080 # on which port the webserver should listen on the main host, if you have already a webserver, 80 won't work
  • DBPASSWORD="$(openssl rand -base64 9)" # the password for the database (humm... save it :-)
  • DOCKERNAME="mediawiki"

[edit] Create a database

  • # inspired from https://hub.docker.com/_/mysql/
  • # Create a data container with a directory /var/lib/mysql
  • docker create -v /var/lib/mysql --name wiki-mysql-data mysql:latest /bin/true
  • docker run --name wiki-mysql --volumes-from wiki-mysql-data -e MYSQL_ROOT_PASSWORD=$DBPASSWORD -d mysql:latest
  • docker ps -a | grep wiki-mysql.* # look the nice containers we just did

[edit] Create a mediawiki

well probably something like found here https://hub.docker.com/r/nickstenning/mediawiki/ (with data container support) as stated on that webpage:

  • docker run --name $DOCKERNAME --link wiki-mysql:mysql -p $WEBPORT:80 -d nickstenning/mediawiki

[edit] Configure mediawiki

  • echo "connect to http://localhost:$WEBPORT/"
  • click on "setup the wiki"
    • database host: mysql
    • database name: mysql
    • table prefix: mw #change this if you install more than one mediawiki into this database
    • username: root
    • echo password: $DBPASSWORD
    • at end of setup you get a LocalSettings.php to download
    • this file has to be provided to the docker or put into the container. Seems to be several ways to do it.
  • docker stop $DOCKERNAME # stop the container as we want to mount data...
  • docker rm $DOCKERNAME # I have no idea how to add parameters, so I just start from zero

[edit] Create wiki data container

  • docker create --name ${DOCKERNAME}-data -v /data nickstenning/mediawiki /bin/true
  • docker run --name ${DOCKERNAME} --volumes-from ${DOCKERNAME}-data --link wiki-mysql:mysql -p $WEBPORT:80 -d nickstenning/mediawiki
  • cat LocalSettings.php | docker exec -i ${DOCKERNAME} sh -c 'cat > /data/LocalSettings.php'
  • docker exec -i ${DOCKERNAME} chown www-data:www-data /data/LocalSettings.php
  • docker exec -i ${DOCKERNAME} chmod 444 /data/LocalSettings.php

More help: well the usual mediawiki help

[edit] Engelsystem

This does not use a data container, but as it's often only for a short event, I don't care.

Give some configuration stuff

  • ENGELPORT=80 # on which port the engel system should listen on the main host, if you have a webserver, 80 won't work
  • ENGELDB=3306 # on which port the mysql of the engelsystem should be visible on the main host
  • DBPASSWORD="$(openssl rand -base64 9)" # the password for the database (humm... save it it :-)
  • ENGELPASSWORD="$(openssl rand -base64 9)" # the password for the engelsystem (humm... save it it :-)
  • DOCKERNAME="engelsystem"
  • ENGELADMIN="engeladmin" # well just use it

from https://github.com/ruep/dockerfile-engel

  • git clone https://github.com/ruep/dockerfile-engel.git
  • cd dockerfile-engel/
  • docker build -t engelweb-app . # this takes a long time
  • docker run --name "$DOCKERNAME" -d -p ${ENGELPORT}:80 -p ${ENGELDB}:3306 -e MYSQL_PASS="$DBPASSWORD" engelweb-app
  • docker exec -t "$DOCKERNAME" sed -i 's/-pengel/-p'$DBPASSWORD'/' /engelweb/db/createdb.sh # needed coz db pass hardcoded
  • docker exec -t "$DOCKERNAME" /engelweb/db/createdb.sh engelsystem engeladmin "$ENGELPASSWORD"
  • docker exec -t "$DOCKERNAME" sh -c "/usr/bin/mysql -uadmin -p$DBPASSWORD engelsystem < /engelweb/db/install.sql"
  • docker exec -t "$DOCKERNAME" sh -c "/usr/bin/mysql -uadmin -p$DBPASSWORD engelsystem < /engelweb/db/update.sql"
  • echo "Please remember the database password: $DBPASSWORD"
  • echo "Please remember the engelsystem login: ${ENGELADMIN} ${ENGELPASSWORD}"
  • echo login to http://localhost:$ENGELPORT/ with user 'admin' and password 'asdfasdf'
Personal tools
Namespaces

Variants
Actions
Navigation
syn2cat
Hackerspace
Activities
Initiatives
Community
Tools
Tools