docker
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| docker [2017/03/08 10:47] – created ssm2017 | docker [2022/02/07 13:29] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ===== Docker and OpenSimulator ===== | + | ====== Docker basics ====== |
| + | ===== Installation ===== | ||
| + | Read the docs | ||
| + | ===== Web interface ===== | ||
| + | use " | ||
| + | ===== Remote API ===== | ||
| + | use " | ||
| + | ====== Websites ====== | ||
| + | ===== Nginx + php-fpm ===== | ||
| + | [[http:// | ||
| + | |||
| + | ==== Create files ==== | ||
| + | - Create a folder that will contain the config files and go inside. (The containers names will take the name of the folder) | ||
| + | - Create a folder named " | ||
| + | - Create a folder ./ | ||
| + | - Create a folder ./ | ||
| + | - Create a folder named " | ||
| + | - Create the following files : | ||
| + | === docker-compose.yml === | ||
| + | <sxh yml> | ||
| + | nginx: | ||
| + | image: nginx: | ||
| + | ports: | ||
| + | - " | ||
| + | volumes: | ||
| + | - ./ | ||
| + | - ./ | ||
| + | links: | ||
| + | - php | ||
| + | php: | ||
| + | image: php:7-fpm | ||
| + | volumes: | ||
| + | - ./ | ||
| + | </ | ||
| + | === ./ | ||
| + | <sxh bash> | ||
| + | server { | ||
| + | index index.php index.html; | ||
| + | server_name php-docker.local; | ||
| + | error_log | ||
| + | access_log / | ||
| + | root / | ||
| + | |||
| + | location ~ \.php$ { | ||
| + | try_files $uri =404; | ||
| + | fastcgi_split_path_info ^(.+\.php)(/ | ||
| + | fastcgi_pass php:9000; | ||
| + | fastcgi_index index.php; | ||
| + | include fastcgi_params; | ||
| + | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | ||
| + | fastcgi_param PATH_INFO $fastcgi_path_info; | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | === ./ | ||
| + | <sxh bash> | ||
| + | server { | ||
| + | index index.php index.html; | ||
| + | server_name php-docker2.local; | ||
| + | error_log | ||
| + | access_log / | ||
| + | root / | ||
| + | |||
| + | location ~ \.php$ { | ||
| + | try_files $uri =404; | ||
| + | fastcgi_split_path_info ^(.+\.php)(/ | ||
| + | fastcgi_pass php:9000; | ||
| + | fastcgi_index index.php; | ||
| + | include fastcgi_params; | ||
| + | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | ||
| + | fastcgi_param PATH_INFO $fastcgi_path_info; | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | ==== Run the containers ==== | ||
| + | <sxh bash> | ||
| + | ===== Mysql ===== | ||
| + | <sxh bash> | ||
| + | docker run \ | ||
| + | | ||
| + | -v "/ | ||
| + | -e MYSQL_ROOT_PASSWORD=mypassword \ | ||
| + | -e MYSQL_ROOT_HOST=172.17.0.1 \ | ||
| + | -d \ | ||
| + | mysql/ | ||
| + | </ | ||
| + | Note: i was not able to use root credentials as / | ||
| + | ==== Script to write to mysql ==== | ||
| + | === First solution === | ||
| + | add this line to the previous command : | ||
| + | <sxh bash>-v / | ||
| + | run this command : | ||
| + | <sxh bash> | ||
| + | content of the file " | ||
| + | <sxh sql> | ||
| + | CREATE DATABASE IF NOT EXISTS `mybase` DEFAULT CHARACTER SET utf8; | ||
| + | GRANT ALL PRIVILEGES ON `mybase`.* TO ' | ||
| + | FLUSH PRIVILEGES; | ||
| + | </ | ||
| + | === Second solution === | ||
| + | run : | ||
| + | <sxh bash> | ||
| + | docker exec mysql-dck /bin/sh -c 'mysql -u root -pmypassword -e " | ||
| + | docker exec mysql-dck /bin/sh -c 'mysql -u root -pmypassword -e "GRANT ALL PRIVILEGES ON `mybase`.* TO \' | ||
| + | docker exec mysql-dck /bin/sh -c 'mysql -u root -pmypassword -e "FLUSH PRIVILEGES;"' | ||
| + | </ | ||
| + | ===== Docker and OpenSimulator | ||
| [[https:// | [[https:// | ||
| + | ==== Dockerfile ==== | ||
| + | <sxh> | ||
| + | # start from this image | ||
| + | FROM mono: | ||
| + | |||
| + | # create an " | ||
| + | RUN useradd -ms /bin/bash opensim | ||
| + | |||
| + | # get the opensim bin folder | ||
| + | COPY opensim.tar.gz / | ||
| + | |||
| + | WORKDIR / | ||
| + | RUN tar -zxf opensim.tar.gz && rm opensim.tar.gz | ||
| + | |||
| + | WORKDIR / | ||
| + | |||
| + | USER opensim | ||
| + | |||
| + | ENTRYPOINT [" | ||
| + | #CMD [" | ||
| + | </ | ||
| + | |||
| + | <sxh bash> | ||
| + | #!/bin/bash | ||
| + | |||
| + | HOST_IP=" | ||
| + | |||
| + | DEFAULT_SIMNAME=" | ||
| + | # check if params | ||
| + | if [ $# -lt 1 ];then | ||
| + | echo " | ||
| + | else | ||
| + | DEFAULT_SIMNAME=$1 | ||
| + | fi | ||
| + | |||
| + | # get port | ||
| + | SIMPORT=$(/ | ||
| + | |||
| + | # define the sim name | ||
| + | SIMNAME=" | ||
| + | RADMINPORT=$((${SIMPORT} + 1)) | ||
| + | REGIONPORT_START=$((${RADMINPORT} + 1)) | ||
| + | REGIONPORT_END=$((${REGIONPORT_START} + 97)) | ||
| + | |||
| + | # check if config folder exists | ||
| + | if [ ! -d "/ | ||
| + | cp -r "/ | ||
| + | fi | ||
| + | |||
| + | # add the config to the inis | ||
| + | cat <<EOM > "/ | ||
| + | [Const] | ||
| + | BaseHostname = " | ||
| + | PublicPort = " | ||
| + | PrivatePort = " | ||
| + | |||
| + | [Network] | ||
| + | http_listener_port = ${SIMPORT} | ||
| + | |||
| + | [RemoteAdmin] | ||
| + | enabled = true | ||
| + | port = ${RADMINPORT} | ||
| + | access_password = " | ||
| + | enabled_methods = all | ||
| + | EOM | ||
| + | |||
| + | # run the container | ||
| + | | ||
| + | -d \ | ||
| + | --name=${SIMNAME} \ | ||
| + | -v / | ||
| + | -v / | ||
| + | -v / | ||
| + | -v / | ||
| + | -v / | ||
| + | --link mysql-dck: | ||
| + | -p ${SIMPORT}: | ||
| + | -p ${RADMINPORT}: | ||
| + | -p ${REGIONPORT_START}-${REGIONPORT_END}: | ||
| + | opensimulator | ||
| + | </ | ||
| + | File to get port " | ||
| + | <sxh bash> | ||
| + | #!/bin/bash | ||
| + | |||
| + | # check if params | ||
| + | if [ $# -lt 1 ];then | ||
| + | echo $" | ||
| + | exit; | ||
| + | fi | ||
| + | |||
| + | i=" | ||
| + | status=false | ||
| + | PORTS_FILE="/ | ||
| + | |||
| + | while [ $status = false ] | ||
| + | do | ||
| + | cat " | ||
| + | if [ ! $? -eq 0 ]; then | ||
| + | echo " | ||
| + | echo " | ||
| + | status=true | ||
| + | fi | ||
| + | i=$[$i+100] | ||
| + | if [ $i -gt 48000 ]; then | ||
| + | status=true | ||
| + | exit 1 | ||
| + | fi | ||
| + | done | ||
| + | </ | ||
| + | Script to delete port " | ||
| + | <sxh bash> | ||
| + | #!/bin/bash | ||
| + | |||
| + | # check if params | ||
| + | if [ $# -lt 1 ];then | ||
| + | echo $" | ||
| + | exit; | ||
| + | fi | ||
| + | |||
| + | PORTS_FILE="/ | ||
| + | #sed -i '/ | ||
| + | grep -v " | ||
| + | </ | ||
| + | ====== Some notes ====== | ||
| + | ===== Get container name ===== | ||
| + | Get containers containing the letter " | ||
| + | <sxh bash> | ||
| + | ===== Get exposed ports ===== | ||
| + | <sxh bash> | ||
| ===== Docker one mysql instance ===== | ===== Docker one mysql instance ===== | ||
| Line 28: | Line 264: | ||
| </ | </ | ||
| The mysql server will be accessible from the outside on the port 6603. | The mysql server will be accessible from the outside on the port 6603. | ||
| + | |||
| + | == User Namespaces == | ||
| + | [[https:// | ||
| + | [[https:// | ||
| + | |||
| + | BEWARE IT CAN BREAK AN OLD DOCKER INSTALLATION !!! | ||
| + | |||
| + | <sxh bash> | ||
| + | groupadd -g 500000 dockremap && | ||
| + | groupadd -g 501000 dockremap-user && | ||
| + | useradd -u 500000 -g dockremap -s /bin/false dockremap && | ||
| + | useradd -u 501000 -g dockremap-user -s /bin/false dockremap-user | ||
| + | </ | ||
| + | <sxh bash> | ||
| + | echo " | ||
| + | echo " | ||
| + | </ | ||
| + | <sxh> | ||
| + | { | ||
| + | " | ||
| + | } | ||
| + | </ | ||
| + | <sxh bash> | ||
| + | systemctl daemon-reload && systemctl restart docker | ||
| + | </ | ||
| + | == Portainer == | ||
| + | in normal mode : | ||
| + | <sxh bash> | ||
| + | docker run -d --privileged -p 9000:9000 -v / | ||
| + | </ | ||
| + | in usernamespace mode : | ||
| + | <sxh bash> | ||
| + | docker run -d --privileged --userns=host -p 9000:9000 -v / | ||
| + | </ | ||
| + | |||
| + | ===== php-fpm nginx with php extensions ===== | ||
| + | ./ | ||
| + | <sxh yml> | ||
| + | nginx: | ||
| + | image: nginx: | ||
| + | ports: | ||
| + | - " | ||
| + | volumes: | ||
| + | - ./ | ||
| + | - ./ | ||
| + | links: | ||
| + | - php | ||
| + | php: | ||
| + | build: ./ | ||
| + | volumes: | ||
| + | - ./ | ||
| + | </ | ||
| + | ./ | ||
| + | <sxh> | ||
| + | FROM php:7-fpm | ||
| + | RUN apt-get update && apt-get install -y --fix-missing | ||
| + | && docker-php-ext-install gd \ | ||
| + | && docker-php-ext-install mbstring \ | ||
| + | && docker-php-ext-enable gd \ | ||
| + | && docker-php-ext-enable mbstring | ||
| + | </ | ||
| + | {{tag> | ||
docker.1488966431.txt.gz · Last modified: (external edit)
