Skip to content
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

How to dockerize Selfoss #1161

Open
akash07k opened this issue Dec 22, 2019 · 11 comments
Open

How to dockerize Selfoss #1161

akash07k opened this issue Dec 22, 2019 · 11 comments
Labels

Comments

@akash07k
Copy link
Contributor

I want to dockerize selfoss, but I'm unable to identify that how exactly I do it since it uses PHP and nodejs both.
If I require to use docker-compose, then can someone please help me with the exact proper script?

@jtojnar
Copy link
Member

jtojnar commented Dec 22, 2019

That will depend on what you want to use the Docker image for.

If you want to use if for running selfoss on production, you do not need node, you can use one of the prebuilt archives in https://github.com/SSilence/selfoss#download and copy one of the existing Dockerfiles from Docker Hub:

If you want to use it for development, I do not think docker-compose is necessary for node. The JavaScript assets are served by the web server so I would expect them to reside in the same image. You could install Node in the Dockerfile just like PHP and other stuff is.

If you want to use database other than SQLite, then docker-compose might be useful to orchestrate the communication between the PHP server and the DB server but it is not necessary either. Or if you want to use PHP-FPM.

@squatica
Copy link

I'm actually currently preparing a Dockerfile for selfoss with the intention to send a PR. As @jtojnar said there are two main scenarios - you either want the "production" image which contains app sources inside, or a "dev" image which only contains dev dependencies and tools, but sources are mounted to your filesystem.
This is what I have so far for the production image (uses the stable tag 2.18), dev image coming soon.

FROM ubuntu:bionic as source

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
    git ca-certificates \
    && git clone https://github.com/SSilence/selfoss.git && cd selfoss \
    && git checkout 2.18



FROM composer:1.9 as composer

COPY --from=source /selfoss /selfoss

RUN cd /selfoss && composer install --ignore-platform-reqs --optimize-autoloader --no-dev



FROM node:12-stretch as npm

COPY --from=composer /selfoss /selfoss

RUN cd /selfoss && npm i && ./node_modules/.bin/grunt client:install



FROM php:7.3-apache-stretch

COPY --from=npm /selfoss /var/www/html/

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y libpng-dev \
    && docker-php-ext-install -j$(nproc) gd \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /var/www/html/

RUN cp defaults.ini config.ini \
    && a2enmod rewrite \
    && chown -R www-data:www-data /var/www/html/data/cache /var/www/html/data/favicons /var/www/html/data/logs /var/www/html/data/thumbnails /var/www/html/data/sqlite /var/www/html/public \
    && echo -e "#!/bin/bash\nwhile true; do php /var/www/html/cliupdate.php; sleep 900; done;" > /check.sh && chmod a+x /check.sh

CMD [ "bash", "-c", "/check.sh & apache2-foreground" ]

You can build and use it directly, but here is a simple docker-compose.yml just to mount the volume with data and port. (You may need to re-run the chown command after your data volume is mounted for the first time, that's still one of my TODO items)

version: "3"
services:
  web:
    build: .
    volumes:
      - data:/var/www/html/data
    ports:
      - "8897:80"
volumes:
  data:

@akash07k
Copy link
Contributor Author

I'm actually currently preparing a Dockerfile for selfoss with the intention to send a PR. As @jtojnar said there are two main scenarios - you either want the "production" image which contains app sources inside, or a "dev" image which only contains dev dependencies and tools, but sources are mounted to your filesystem.
This is what I have so far for the production image (uses the stable tag 2.18), dev image coming soon.

FROM ubuntu:bionic as source

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
    git ca-certificates \
    && git clone https://github.com/SSilence/selfoss.git && cd selfoss \
    && git checkout 2.18



FROM composer:1.9 as composer

COPY --from=source /selfoss /selfoss

RUN cd /selfoss && composer install --ignore-platform-reqs --optimize-autoloader --no-dev



FROM node:12-stretch as npm

COPY --from=composer /selfoss /selfoss

RUN cd /selfoss && npm i && ./node_modules/.bin/grunt client:install



FROM php:7.3-apache-stretch

COPY --from=npm /selfoss /var/www/html/

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y libpng-dev \
    && docker-php-ext-install -j$(nproc) gd \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /var/www/html/

RUN cp defaults.ini config.ini \
    && a2enmod rewrite \
    && chown -R www-data:www-data /var/www/html/data/cache /var/www/html/data/favicons /var/www/html/data/logs /var/www/html/data/thumbnails /var/www/html/data/sqlite /var/www/html/public \
    && echo -e "#!/bin/bash\nwhile true; do php /var/www/html/cliupdate.php; sleep 900; done;" > /check.sh && chmod a+x /check.sh

CMD [ "bash", "-c", "/check.sh & apache2-foreground" ]

You can build and use it directly, but here is a simple docker-compose.yml just to mount the volume with data and port. (You may need to re-run the chown command after your data volume is mounted for the first time, that's still one of my TODO items)

version: "3"
services:
  web:
    build: .
    volumes:
      - data:/var/www/html/data
    ports:
      - "8897:80"
volumes:
  data:
```Wow excellent, going to try this dockerfile.

Waiting for your dev dockerfile eagerly because I'm more willing to use it for development because the production version is quite outdated now.
I've spent the whole day today in making selfoss work with docker but no luck at all, Hope yours work perfectly.
Thanks a lot for the help and looking forward to try the dev dockerfile too

@akash07k
Copy link
Contributor Author

I'm actually currently preparing a Dockerfile for selfoss with the intention to send a PR. As @jtojnar said there are two main scenarios - you either want the "production" image which contains app sources inside, or a "dev" image which only contains dev dependencies and tools, but sources are mounted to your filesystem.
This is what I have so far for the production image (uses the stable tag 2.18), dev image coming soon.

FROM ubuntu:bionic as source

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
    git ca-certificates \
    && git clone https://github.com/SSilence/selfoss.git && cd selfoss \
    && git checkout 2.18



FROM composer:1.9 as composer

COPY --from=source /selfoss /selfoss

RUN cd /selfoss && composer install --ignore-platform-reqs --optimize-autoloader --no-dev



FROM node:12-stretch as npm

COPY --from=composer /selfoss /selfoss

RUN cd /selfoss && npm i && ./node_modules/.bin/grunt client:install



FROM php:7.3-apache-stretch

COPY --from=npm /selfoss /var/www/html/

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y libpng-dev \
    && docker-php-ext-install -j$(nproc) gd \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /var/www/html/

RUN cp defaults.ini config.ini \
    && a2enmod rewrite \
    && chown -R www-data:www-data /var/www/html/data/cache /var/www/html/data/favicons /var/www/html/data/logs /var/www/html/data/thumbnails /var/www/html/data/sqlite /var/www/html/public \
    && echo -e "#!/bin/bash\nwhile true; do php /var/www/html/cliupdate.php; sleep 900; done;" > /check.sh && chmod a+x /check.sh

CMD [ "bash", "-c", "/check.sh & apache2-foreground" ]

You can build and use it directly, but here is a simple docker-compose.yml just to mount the volume with data and port. (You may need to re-run the chown command after your data volume is mounted for the first time, that's still one of my TODO items)

version: "3"
services:
  web:
    build: .
    volumes:
      - data:/var/www/html/data
    ports:
      - "8897:80"
volumes:
  data:

No luck with both the files. In second dockerfile, I always get (localhost sent an empty response.).
Going to try @squatica 's dockerfile and let's see how it goes. :-)

@akash07k
Copy link
Contributor Author

I'm actually currently preparing a Dockerfile for selfoss with the intention to send a PR. As @jtojnar said there are two main scenarios - you either want the "production" image which contains app sources inside, or a "dev" image which only contains dev dependencies and tools, but sources are mounted to your filesystem.
This is what I have so far for the production image (uses the stable tag 2.18), dev image coming soon.

FROM ubuntu:bionic as source

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
    git ca-certificates \
    && git clone https://github.com/SSilence/selfoss.git && cd selfoss \
    && git checkout 2.18



FROM composer:1.9 as composer

COPY --from=source /selfoss /selfoss

RUN cd /selfoss && composer install --ignore-platform-reqs --optimize-autoloader --no-dev



FROM node:12-stretch as npm

COPY --from=composer /selfoss /selfoss

RUN cd /selfoss && npm i && ./node_modules/.bin/grunt client:install



FROM php:7.3-apache-stretch

COPY --from=npm /selfoss /var/www/html/

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y libpng-dev \
    && docker-php-ext-install -j$(nproc) gd \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /var/www/html/

RUN cp defaults.ini config.ini \
    && a2enmod rewrite \
    && chown -R www-data:www-data /var/www/html/data/cache /var/www/html/data/favicons /var/www/html/data/logs /var/www/html/data/thumbnails /var/www/html/data/sqlite /var/www/html/public \
    && echo -e "#!/bin/bash\nwhile true; do php /var/www/html/cliupdate.php; sleep 900; done;" > /check.sh && chmod a+x /check.sh

CMD [ "bash", "-c", "/check.sh & apache2-foreground" ]

You can build and use it directly, but here is a simple docker-compose.yml just to mount the volume with data and port. (You may need to re-run the chown command after your data volume is mounted for the first time, that's still one of my TODO items)

version: "3"
services:
  web:
    build: .
    volumes:
      - data:/var/www/html/data
    ports:
      - "8897:80"
volumes:
  data:

@squatica
Unfortunately it didn't work either.
Same issue as mine images:
image

@akash07k
Copy link
Contributor Author

Some more errors:
image

@squatica

@squatica
Copy link

@akash07k All right, I cleaned it up here: https://github.com/squatica/selfoss-docker
Both 2.18 and master versions are there.

@akash07k
Copy link
Contributor Author

@akash07k All right, I cleaned it up here: https://github.com/squatica/selfoss-docker
Both 2.18 and master versions are there.

@squatica
Thanks a lot, it works.
Now I'm trying to update the PHP image and other stuff and will see whether it works or not.
I'm really grateful for your efforts on this

@akash07k
Copy link
Contributor Author

akash07k commented Jan 5, 2020

@squatica
Any updates buddy?
I know that you are busy, but still thought to ask.

squatica added a commit to squatica/selfoss that referenced this issue Feb 3, 2020
squatica added a commit to squatica/selfoss that referenced this issue Feb 7, 2020
akash07k pushed a commit to akash07k/selfoss that referenced this issue Feb 23, 2020
akash07k pushed a commit to akash07k/selfoss that referenced this issue May 3, 2020
squatica added a commit to squatica/selfoss that referenced this issue May 16, 2020
@MatthK
Copy link

MatthK commented Sep 20, 2021

Based on the link (https://hub.docker.com/r/pamplemousse/selfoss/dockerfile) above I managed to get it packaged into a docker-compose including a MySql database and also including my Webfront. Have a look here: https://github.com/MatthK/swfd

@jtojnar
Copy link
Member

jtojnar commented Oct 16, 2022

For the newly released selfoss 2.19, we are recommending https://gitlab.com/radek-sprta/docker-selfoss. It uses a proper service manager, which was something I was missing from the other approaches.

We might still have an official image in the future but I currently do not have the capacity to push it to meet the project requirements. I would still like to thank everyone who worked on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants