Can I use a docker volume with S3FS? - docker

I would like to have a shared directory between my containers: ftp and s3fs. Todo so, I have created a volume in my docker-compose file called s3.
If I stop s3fs from running in my s3fs container, then I can create files in the ftp container and they will show up in side s3fs under /home/files.
However, when running s3fs the directory /home/files remains empty whilst I create files in the ftp.
This is what my /proc/mounts file looks like:
/dev/sda2 /home/files ext4 rw,relatime,data=ordered 0 0
s3fs /home/files fuse.s3fs rw,nosuid,nodev,relatime,user_id=0,group_id=0,allow_other 0 0
I belive fuse maybe overriding my docker volume, has anyone encountered this problem before?
docker-compose.yml
version: "3"
services:
ftp:
image: app/proftpd:latest
volumes:
- s3:/home/files
ports:
- 2222:2222
s3fs:
image: app/s3fs:latest
command: start
env_file:
- s3fs/aws.env
volumes:
- s3:/home/files
cap_add:
- SYS_ADMIN
devices:
- "/dev/fuse"
environment:
ENVIRONMENT: "dev"
volumes:
s3:
s3fs - Dockerfile
FROM ubuntu:16.04
RUN apt-get update -qq
RUN apt-get install -y \
software-properties-common
RUN apt-get update -qq
RUN apt-get install -y \
automake \
autotools-dev \
fuse \
g++ \
git \
libcurl4-openssl-dev \
libfuse-dev \
libssl-dev \
libxml2-dev \
make \
pkg-config \
curl
RUN curl -L https://github.com/s3fs-fuse/s3fs-fuse/archive/v1.84.tar.gz | tar zxv -C /usr/src
RUN cd /usr/src/s3fs-fuse-1.84 && ./autogen.sh && ./configure --prefix=/usr --with-openssl && make && make install
COPY entrypoint.sh /opt/s3fs/bin/entrypoint.sh
RUN mkdir -p /home/files
WORKDIR /opt/s3fs/bin
ENTRYPOINT ["/bin/sh", "./entrypoint.sh"]
s3fs - entrypoint.sh
#!/usr/bin/env bash
case $1 in
start)
echo "Starting S3Fs: "
s3fs mybucket /home/files -o allow_other,nonempty -d -d
;;
esac
ftp - Dockerfile
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y \
openssh-server \
proftpd-basic \
proftpd-mod-mysql
COPY proftpd.conf /etc/proftpd/proftpd.conf
COPY sftp.conf /etc/proftpd/conf.d/sftp.conf
COPY setup.sh /etc/proftpd/setup.sh
RUN chmod 500 /etc/proftpd/setup.sh && /etc/proftpd/setup.sh
EXPOSE 2222
ENTRYPOINT ["/bin/sh", "/etc/proftpd/entrypoint.sh"]

You can mount s3 in your docker container in next way
1.Add to Dockerfile
RUN apt-get install -y fuse s3fs
RUN mkdir /root/.aws
RUN touch /root/.aws/.passwd-s3fs && chmod 600 /root/.aws/.passwd-s3fs
COPY entrypoint.sh ./
RUN chmod 700 entrypoint.sh
ENTRYPOINT entrypoint.sh
2.Create entrypoint.sh with next script
#!/bin/sh
echo "$AWS_CREDS" > /root/.aws/.passwd-s3fs
echo "$BUCKET_NAME /srv/files fuse.s3fs _netdev,allow_other,passwd_file=/root/.aws/.passwd-s3fs 0 0" > /etc/fstab
mount -a
<your old CMD or ENTRYPOINT>
3.In docker-compose.yml add next
<your-container-name>:
image: ...
build: ...
environment:
- AWS_ID="AKI..."
- AWS_KEY="omIE..."
- AWS_CREDS=AKI...:2uMZ...
- BUCKET_NAME=<YOUR backed name>
devices:
- "/dev/fuse"
cap_add:
- SYS_ADMIN
security_opt:
- seccomp:unconfined

Related

how to make a dockerfile with only one container?

I have a yii1 application. And I have a dockerfile. And I had a docker-compose file.
But for the momemnt I only have one application. Because I have a remote database. So the database is not in a container.
So I have this dockerfile:
FROM php:7.3-apache
#COPY BaltimoreCyberTrustRoot.crt.pem /usr/local/share/ca-certificates/AzureDB.crt
# Copy virtual host into container
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf
# Enable rewrite mode
RUN a2enmod rewrite
# Install necessary packages
RUN apt-get update && \
apt-get install \
libzip-dev \
wget \
git \
unzip \
-y --no-install-recommends
# Install PHP Extensions
RUN docker-php-ext-install zip pdo_mysql
# RUN pecl install -o -f xdebug-3.1.3 \
# && rm -rf /tmp/pear
# Copy composer installable
COPY ./install-composer.sh ./
# Copy php.ini
COPY ./php.ini /usr/local/etc/php/
#COPY BaltimoreCyberTrustRoot.crt.pem /var/www/html/
EXPOSE 80
# Cleanup packages and install composer
RUN apt-get purge -y g++ \
&& apt-get autoremove -y \
&& rm -r /var/lib/apt/lists/* \
&& rm -rf /tmp/* \
&& sh ./install-composer.sh \
&& rm ./install-composer.sh
# Change the current working directory
WORKDIR /var/www/html
# Change the owner of the container document root
RUN chown -R www-data:www-data /var/www
# Start Apache in foreground
CMD ["apache2-foreground"]
And I had this docker-compose file:
version: '3'
services:
web:
build: ./docker
container_name: dockeryiidisc
ports:
- 80:80
- 443:443
volumes:
- C:\xampp\htdocs\webScraper/docker:/etc/apache2/sites-enabled/
- C:\xampp\htdocs\webScraper:/var/www/html/
and that worked.
But so now I only want to use the dockerfile.
So I tried this:
docker build -t docker_webcrawler .
and this command:
docker run -d -p 80:80 --name cntr-apache docker_webcrawler
But if I then go to: http://localhost:80
I only see a empty directory:
Index of /
[ICO] Name Last modified Size Description
So what I have to change? That I only have to use the dockerfile?
Thank you
It looks like you're missing the volume mappings that you have in your docker-compose file. Try this
docker run -d -p 80:80 --name cntr-apache -v C:\xampp\htdocs\webScraper/docker:/etc/apache2/sites-enabled/ -v C:\xampp\htdocs\webScraper:/var/www/html/ docker_webcrawler

How to continuously copy files into docker

I am a docker newbie and i can't rly figure out how the changes that will be made to my working directory will be continuously copied to the docker container. Is there a command that copies all my changes to the docker container all the time ?
Edit : i added docker file and docker compose
My docker file
FROM scratch
ADD centos-7-x86_64-docker.tar.xz /
LABEL \
org.label-schema.schema-version="1.0" \
org.label-schema.name="CentOS Base Image" \
org.label-schema.vendor="CentOS" \
org.label-schema.license="GPLv2" \
org.label-schema.build-date="20201113" \
org.opencontainers.image.title="CentOS Base Image" \
org.opencontainers.image.vendor="CentOS" \
org.opencontainers.image.licenses="GPL-2.0-only" \
org.opencontainers.image.created="2020-11-13 00:00:00+00:00"
RUN yum clean all && yum update -y && yum -y upgrade
RUN yum groupinstall "Development Tools" -y
RUN yum install -y wget gettext-devel curl-devel openssl-devel perl-devel perl-CPAN zlib-devel && wget https://github.com/git/git/archive/v2.26.2.tar.gz\
&& tar -xvzf v2.26.2.tar.gz && cd git-2.26.2 && make configure && ./configure --prefix=/usr/local && make install
# RUN mkdir -p /root/.ssh && \
# chmod 0700 /root/.ssh && \
# ssh-keyscan github.com > /root/.ssh/known_hosts
# RUN ssh-keygen -q -t rsa -N '' -f /id_rsa
# RUN echo "$ssh_prv_key" > /root/.ssh/id_rsa && \
# echo "$ssh_pub_key" > /root/.ssh/id_rsa.pub && \
# chmod 600 /root/.ssh/id_rsa && \
# chmod 600 /root/.ssh/id_rsa.pub
RUN ls
RUN cd / && git clone https://github.com/odoo/odoo.git \
&& cd odoo \
&& git fetch \
&& git checkout 9.0
RUN yum install python-devel libxml2-devel libxslt-dev openldap-devel libtiff-devel libjpeg-devel libzip-devel freetype-devel lcms2-devel \
libwebp-devel tcl-devel tk-devel python-pip nodejs
RUN pip install setuptools==1.4.1 beautifulsoup4==4.9.3 pillow openpyxl==2.6.4 luhn gmp-devel paramiko==1.7.7.2 python2-secrets cffi pysftp==0.2.8
RUN pip install -r requirements.txt
RUN npm install -g less
CMD ["/bin/bash","git"]
My docker-compose
version: '3.3'
services:
app: &app
build:
context: .
dockerfile: ./docker/app/Dockerfile
container_name: app
tty: true
db:
image: postgres:9.2.18
environment:
- POSTGRES_DB=test
ports:
- 5432:5432
volumes:
- ./docker/db/pg-data:/var/lib/postgresql/data
odoo:
<<: *app
command: python odoo.py -w odoo -r odoo
ports:
- '8069:8069'
depends_on:
- db
If I understand correctly you want to mount a path from the host into a container which can be done using volumes. Something like this would keep the folders in sync which can be useful for development
docker run -v /path/to/local/folder:/path/in/container busybox

Docker not pulling updated php version

I am trying to update php version on the Docker
This is how my Dockerfile looks like
FROM php:7.2-fpm
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Create system user to run Composer and Artisan Commands
RUN useradd -G www-data,root -d /home/ubuntu ubuntu
RUN mkdir -p /home/ubuntu/.composer && \
chown -R ubuntu:ubuntu /home/ubuntu
# Set working directory
WORKDIR /var/www
USER ubuntu
I have changed the php version to 7.3, and I tried to delete all docker containers and recreate it docker rm -vf $(docker ps -a -q). And then I built my docker containers using docker-compose build --nocache --pull.
docker-compose.yaml file looks like this:
version: "3.7"
services:
app:
build:
context: ./
dockerfile: ./docker/Dockerfile
image: myapp
container_name: myapp-app
restart: unless-stopped
working_dir: /var/www/
volumes:
- ./:/var/www
networks:
- myapp
But still the php version is stated as 7.2.
Any advice?
To remove all containers/images/networks/.. run:
docker system prune -a
Then try to build the image.
If that don't works: can you give the logs, where the wrong version will pulled?

PHP is unable to see env var when runing in docker

I have this docker-compose config.
The "app" is a PHP application. As you can see, 3 env vars are passed to the container.
However, after docker-compose up, PHP doesn't see these. They are not returned by getenv() and they cannot be found $_ENV either.
What's wrong here?
version: '3.4'
services:
db:
image: postgres:11.0
restart: always
environment:
POSTGRES_PASSWORD: testuser
POSTGRES_USER: test
POSTGRES_DB: db
volumes:
- /data/db
redis:
image: redis:latest
restart: always
volumes:
- /data/redis
app:
build:
context: .
dockerfile: Dockerfile
environment:
- DATABASE_URL=postgresql://db:5432/db
- REDIS_URL=tcp://redis:6379?database=1
- NODE_ENV=development
ports:
- '80:80'
volumes:
- '${BASEDIR}:/var/www/some'
Here is my Dockerfile:
FROM ubuntu:18.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
software-properties-common \
apt-utils \
tzdata \
locales
RUN add-apt-repository ppa:ondrej/php
RUN apt-get update
RUN locale-gen en_US.UTF-8
RUN echo "Europe/Budapest" > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata
RUN apt-get -y update && apt-get -y install \
libglu1-mesa \
less \
vim \
nginx \
php7.4 \
php7.4-fpm \
php7.4-cli \
php7.4-common \
php7.4-curl \
php-deepcopy \
php7.4-gd \
php7.4-mbstring \
php7.4-pgsql \
php7.4-soap \
php7.4-xdebug \
php7.4-zip \
php7.4-xml \
phpunit \
npm && npm i -g npm
ENV NGINX_RUN_USER www-data
ENV NGINX_RUN_GROUP www-data
ENV NGINX_LOG_DIR /var/log/nginx
ENV NGINX_LOCK_DIR /var/lock/nginx
ENV NGINX_PID_FILE /run/nginx.pid
RUN mkdir www
RUN mkdir -p /var/www/dbv.local/html
RUN chmod -R 755 /var/www/dbv.local
COPY ./php.ini /etc/php/7.4/fpm/php.ini
COPY ./dbv.local /etc/nginx/sites-available/dbv.local
COPY ./lib/aspose_php.so /usr/lib/php/20190902
COPY ./lib/libaspose_cpp_clang3_libstdcpp.so /usr/lib/libaspose_cpp_clang3_libstdcpp.so
COPY ./lib/libAspose.Slides_clang3_libstdcpp.so /usr/lib/libAspose.Slides_clang3_libstdcpp.so
COPY ./lib/libphpcpp.so.2.2 /usr/lib/libphpcpp.so.2.2
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
RUN ln -s /etc/nginx/sites-available/dbv.local /etc/nginx/sites-enabled/
ADD ./xdebug.ini /etc/php/7.4/mods-available/xdebug.ini
ADD ./aspose_php.ini /etc/php/7.4/mods-available/aspose_php.ini
ADD ./start.sh /root/start.sh
RUN ln -s /etc/php/7.4/mods-available/xdebug.ini /etc/php/7.4/mods-available/20-xdebug.ini
RUN ln -s /etc/php/7.4/mods-available/aspose_php.ini /etc/php/7.4/fpm/conf.d/aspose_php.ini
RUN ln -s /etc/php/7.4/mods-available/aspose_php.ini /etc/php/7.4/cli/conf.d/aspose_php.ini
RUN rm -rf /var/lib/apt/lists/*
RUN apt-get clean
CMD ["/root/start.sh"]
EXPOSE 80 9000 5432
Edit:
start.sh is just a one liner
service php7.4-fpm start && nginx
Ubuntu 18 is necessary. I could use an official Nginx image though. Maybe that's the issue?

ERROR: Service 'ubuntu' failed to build: The command '/bin/sh -c apt-get update

when I execute the command docker-compose up --build -d
I get these errors:
E: Unable to locate package php7.4 E: Couldn't find any package by
glob 'php7.4' E: Couldn't find any package by regex 'php7.4' E: Unable
to locate package php7.4-fpm E: Couldn't find any package by glob
'php7.4-fpm' E: Couldn't find any package by regex 'php7.4-fpm' ERROR:
Service 'ubuntu' failed to build: The command '/bin/sh -c apt-get
update && apt-get install -y curl zip unzip php7.4
php7.4-fpm gettext-base sudo' returned a non-zero code:
100
can you help me please what is wrong with my dockerfile and docker-compose.yml?
here is my dockerfile
FROM ubuntu:18.04
# ENV PORT=80
# ENV FPMSTREAM=9000
RUN apt-get update \
&& apt-get install -y curl zip unzip \
php7.4 php7.4-fpm \
gettext-base sudo
COPY ./webapp /var/www/webapp
WORKDIR /var/www/webapp
ADD default.conf /etc/nginx/conf.d/default.conf
RUN chown -R www-data:www-data /var/www && \
chmod -R 775 /var/www && \
useradd -m docker && echo "docker:docker" | chpasswd && \
adduser docker sudo
USER docker
docker-compose.yml
version: "3.8"
services:
ubuntu:
build: .
container_name: ubuntu-container
external_links:
- nginx
- db
nginx:
image: nginx:stable
container_name: nginx-container
ports:
- "80:80"
expose:
- 9000
volumes:
- ./code:/var/www/webapp
- ./default.conf:/etc/nginx/conf.d/default.conf
db:
image: mysql:8.0
container_name: mysql-container
command: --default-authentication-plugin=mysql_native_password
restart: always
env_file:
- .env
volumes:
- ./mysql-data:/var/lib/mysql
expose:
- 3306
ports:
- "3306:3306"
your problem is that you're trying to install a version of PHP which is not available in Ubuntu 18.04.
The latest available version is 7.2, so you need to replace php7.4 php7.4-fpm with either php php-fpm or php7.2 php7.2-fpm
Please try the below Dockerfile for build
FROM ubuntu:18.04
# ENV PORT=80
# ENV FPMSTREAM=9000
#Add Repos for PHP modules
RUN apt-get update \
&& apt -y install software-properties-common \
&& add-apt-repository ppa:ondrej/php
RUN apt-get update \
&& apt-get install -y curl zip unzip \
php7.4 php7.4-fpm \
gettext-base sudo
COPY ./webapp /var/www/webapp
WORKDIR /var/www/webapp
ADD default.conf /etc/nginx/conf.d/default.conf
RUN chown -R www-data:www-data /var/www && \
chmod -R 775 /var/www && \
useradd -m docker && echo "docker:docker" | chpasswd && \
adduser docker sudo
USER docker

Resources