Skip to content

Add startup script to prepare installation on first run, add samples … #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 30 additions & 61 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,61 +1,30 @@
FROM ubuntu:14.04
MAINTAINER Yannick Warnier <[email protected]>

# Keep upstart from complaining
RUN dpkg-divert --local --rename --add /sbin/initctl
RUN ln -sf /bin/true /sbin/initctl

# Update Ubuntu and install basic PHP stuff
RUN apt-get -y update && apt-get install -y \
curl \
git \
libapache2-mod-php5 \
php5-cli \
php5-curl \
php5-gd \
php5-intl \
php5-mysql \
wget

RUN apt-get install -y openssh-server
RUN mkdir -p /var/run/sshd

# Get Chamilo
RUN mkdir -p /var/www/chamilo
ADD https://github.com/chamilo/chamilo-lms/archive/v1.10.0-alpha.tar.gz /var/www/chamilo/chamilo.tar.gz
WORKDIR /var/www/chamilo
RUN tar zxf chamilo.tar.gz;rm chamilo.tar.gz;mv chamilo* www
WORKDIR www
RUN chown -R www-data:www-data \
app \
main/default_course_document/images \
main/lang \
vendor \
web

# Get Composer (putting the download in /root is discutible)
WORKDIR /root
RUN curl -sS https://getcomposer.org/installer | php
RUN chmod +x composer.phar
RUN mv composer.phar /usr/local/bin/composer

# Get Chash
RUN git clone https://github.com/chamilo/chash.git chash
WORKDIR chash
RUN composer update --no-dev
RUN php -d phar.readonly=0 createPhar.php
RUN chmod +x chash.phar && mv chash.phar /usr/local/bin/chash

# Configure and start Apache
ADD chamilo.conf /etc/apache2/sites-available/chamilo.conf
RUN a2ensite chamilo
RUN a2enmod rewrite
RUN /etc/init.d/apache2 restart
RUN echo "127.0.0.1 docker.chamilo.net" >> /etc/hosts

# Go to Chamilo folder and install
# Soon... (this involves having a SQL server in a linked container)

WORKDIR /var/www/chamilo/www
EXPOSE 22 80
CMD ["/bin/bash"]
from ubuntu:bionic

ENV DEBIAN_FRONTEND=noninteractive

# Install Apache and PHP

RUN apt-get update && \
apt-get install -y apache2 php libapache2-mod-php php-gd php-intl php-curl php-json php-mysql php-zip php-xml php-mbstring php-dom composer git && \
apt-get clean && rm -rf /var/lib/apt/lists/*

# Install Chamilo LMS
RUN mkdir /var/www/chamilo-template && \
git clone -b 1.11.x --single-branch https://github.com/chamilo/chamilo-lms.git /var/www/chamilo-template && \
cd /var/www/chamilo-template && composer update && \
chown -R www-data:www-data app main/default_course_document/images main/lang web && \
rm -rf /var/www/chamilo-template/.git

# Prepare Apache and PHP configuration
RUN rm /var/www/html/*
COPY htaccessForChamilo.conf /etc/apache2/conf-available/
COPY php-overrides.ini /etc/php/7.2/apache2/conf.d/20-php.ini
RUN a2enconf htaccessForChamilo && \
a2enmod rewrite && \
sed -ri -e 's!^(\s*ErrorLog)\s+\S+!\1 /proc/self/fd/2!g' /etc/apache2/sites-enabled/000-default.conf

EXPOSE 80

COPY init-and-run.sh .

CMD ["./init-and-run.sh"]
75 changes: 26 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,83 +1,60 @@
# docker-chamilo
Official Docker image for Chamilo LMS

This image is not ready yet. Please come back soon or watch the project for updates.
The image is based on Chamilo LMS 1.11 and uses Apache as web server.

## Launching
## Launching for a quick demo

This image is currently based on Chamilo LMS 1.10 and requires a separate database container to run.
We suggest using the "mariadb" container, like so:

```
docker run --name mariadb -e MYSQL_ROOT_PASSWORD=pass -e MYSQL_USER=chamilo -e MYSQL_PASSWORD=chamilo -e MYSQL_DATABASE=chamilo -d mariadb
```
**Hint: You will loose data when stopping the containers.**

This will get you back on the command line of the Docker host. You can see the container running with ```docker ps```.
We need to start a MariaDB database and the Chamilo docker image.

Then start the chamilo/docker-chamilo container:
We suggest using the "mariadb" container, like so:

```
docker run --link=mariadb:db --name chamilo -p 8080:80 -it chamilo/docker-chamilo
docker run --name chamilo-db -e MYSQL_ROOT_PASSWORD=pass -e MYSQL_USER=chamilo -e MYSQL_PASSWORD=chamilo -e MYSQL_DATABASE=chamilo -d mariadb:10-bionic
```

At this point, the docker-chamilo image doesn't provide an installed version of Chamilo LMS, but this should be ready soon.
See https://hub.docker.com/_/mariadb/ for more options.

The configuration files assume the host will be "docker.chamilo.net", so you will have to define it in your host's /etc/hosts file, depending on the IP of the container.
Now start the Chamilo image, linked to the database container.

```
72.17.0.10 docker.chamilo.net
docker run --link=chamilo-db:db --name chamilo -p 8080:80 -d chamilo/docker-chamilo
```

Now start your browser and load http://docker.chamilo.net.
Now start your browser and load http://my_docker_ip:8080.

## Using with a load-balancer
Hint:

If you want to use a more complex system with load balancing, you might want to try out the following suite of commands:
In the initial setup use the following values:

```
docker run --name varwww -d ywarnier/varw
```
* URL of the application is the IP of your docker server.
* host of the database is defined by the *--link* option: db
* username and password are defined in the docker run command of the database. See above.

This will provide a shared /var/www2 partition
## Launching with various options

```
docker run --name mariadb -e MYSQL_ROOT_PASSWORD=pass -e MYSQL_USER=chamilo -e MYSQL_PASSWORD=chamilo -e MYSQL_DATABASE=chamilo -d mariadb
docker run --link=mariadb:db --volumes-from=varwww --name chamilo -p 8080:80 -it chamilo/docker-chamilo
# Change all configuration to point to /var/www2/chamilo/www and change the Chamilo config file (root_web)
# Also, inside app/config/configuration.php, change "session_stored_in_db" to true
# configure Chamilo on this first container then take a snapshot
docker commit -m "Live running Chamilo connected to host 'db' with existing database" {container-hash} docker-chamilo:live
docker run --link=mariadb:db --volumes-from=varwww --name chamilo2 -p 8081:80 -it docker-chamilo:live
docker run --name lb --link=chamilo:w1 --link=chamilo4:w2 -e CHAMILO_1_PORT_80_TCP_ADDR=172.17.0.10 -e CHAMILO_2_PORT_80_TCP_ADDR=172.17.0.11 -e CHAMILO_HOSTNAME=docker.chamilo.net -e CHAMILO_PATH=/ -p 8082:80 -it jasonwyatt/nginx-loadbalancer
```
**Persistent volumes for the database and the Chamilo configuration**

Sadly, there's something wrong at the moment in the nginx-loadbalancer image, and you have to connect to it to change the configuration of the reverse proxy (the last container you launched).
Create a data directory on a suitable volume on your host system, e.g.

mkdir /my/chamilo/db
mkdir /my/chamilo/web

```
docker ps
```

(to identify the hash of the image of the load balancer (lb))
Start your mariadb container like this:

```
docker exec -i -t {lb-container-hash} bash
cd /etc/nginx/sites-available/
vi proxy.conf
docker run --name chamilo-db -e MYSQL_ROOT_PASSWORD=pass -e MYSQL_USER=chamilo -e MYSQL_PASSWORD=chamilo -e MYSQL_DATABASE=chamilo -v /my/chamilo/db:/var/lib/mysql -d mariadb:10-bionic
```

(add the following *just before* proxy_pass, in the two occurrences)

```
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
docker run --link=chamilo-db:db --name chamilo -p 8080:80 -d -v /my/chamilo/web:/var/www/html/ chamilo/docker-chamilo
```

Now reload Nginx
**Using your own timezone**

```
service nginx reload
docker run -e TZ=Europe/Berlin --link=chamilo-db:db --name chamilo -p 8080:80 -d chamilo/docker-chamilo
```

Now you should be good to go.

Note that this will only work as long as you don't upload any file or object that needs to be stored on disk, as the two web servers will not share any disk space in the context presented above.
34 changes: 0 additions & 34 deletions chamilo.conf

This file was deleted.

3 changes: 3 additions & 0 deletions htaccessForChamilo.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Directory /var/www/html>
AllowOverride All
</Directory>
12 changes: 12 additions & 0 deletions init-and-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# copy template on first run
if [ ! -d "/var/www/html/main" ]; then
echo "First run: move Chamilo LMS to web folder. Wait ..."
cp -rT -p /var/www/chamilo-template /var/www/html
rm -rf /var/www/chamilo-template
fi

echo "Starting Apache Webserver"

apachectl -D FOREGROUND
4 changes: 4 additions & 0 deletions php-overrides.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
post_max_size = 25M
upload_max_filesize = 25M
memory_limit = 256M
session.cookie_httponly = true