Volume in dockerfile is not available in kubernetes PVC [closed] - docker

Closed. This question is not about programming or software development. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 days ago.
Improve this question
I have a magento Dockefile, with nginx & php installed on the same file, I want to use the same image on kubernetes with PVC, I know it wont copy contents to PVC, is there any alternate solution for this, below are my docker fileenter code here files
FROM nginx:1.18
RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install -y --no-install-recommends \
curl \
wget \
vim \
supervisor \
net-tools \
iputils-ping \
cron \
postfix \
nginx
RUN curl -sSL https://packages.sury.org/php/README.txt | bash -x
RUN apt install php8.1 php8.1-ctype php8.1-curl php8.1-dom php8.1-fileinfo php8.1-iconv php8.1-simplexml php8.1-sockets php8.1-tokenizer php8.1-xmlwriter php8.1-xsl php8.1-zip php8.1-bcmath php8.1-fpm php8.1-common php8.1-mysql php8.1-gmp php8.1-curl php8.1-intl php8.1-mbstring php8.1-xmlrpc php8.1-gd php8.1-xml php8.1-cli php8.1-zip php8.1-soap php8.1-imap -y
COPY config/php.ini /etc/php.ini
COPY config/www.conf /etc/php-fpm.d/www.conf
COPY config/nginx.conf /etc/nginx/nginx.conf
COPY config/default.conf /etc/nginx/conf.d/default.conf
RUN mkdir -p /var/lib/php/
RUN chown -R www-data:www-data /var/lib/php/
RUN mkdir -p /run/php/
RUN chown -R www-data:www-data /run/php/
COPY --from=composer:2.2 /usr/bin/composer /usr/bin/composer
COPY config/auth.json /root/.config/composer/auth.json
COPY dev /var/www/html/magento
COPY bash.sh /tmp
RUN chmod +x /tmp/bash.sh
RUN /tmp/bash.sh
VOLUME /var/www/html/magento
WORKDIR /var/www/html/magento
EXPOSE 80
EXPOSE 9000
CMD [ "/scripts/commands.sh"]
#volumeMounts:
#- name: web
#mountPath: "/var/www/html/magento"
#volumes:
#- name: web
#persistentVolumeClaim:
#claimName: magento-pvc-1

Related

Copy folder from Dockerfile to host [duplicate]

This question already has answers here:
Docker: Copying files from Docker container to host
(27 answers)
Closed 1 year ago.
I have a docker file
FROM ubuntu:20.04
################################
### INSTALL Ubuntu build tools and prerequisites
################################
# Install build base
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
build-essential \
git \
subversion \
sharutils \
vim \
asciidoc \
binutils \
bison \
flex \
texinfo \
gawk \
help2man \
intltool \
libelf-dev \
zlib1g-dev \
libncurses5-dev \
ncurses-term \
libssl-dev \
python2.7-dev \
unzip \
wget \
rsync \
gettext \
xsltproc && \
apt-get clean && rm -rf /var/lib/apt/lists/*
ARG FORCE_UNSAFE_CONFIGURE=1
RUN git clone https://git.openwrt.org/openwrt/openwrt.git
WORKDIR /openwrt
RUN ./scripts/feeds update -a && ./scripts/feeds install -a
COPY .config /openwrt/.config
RUN mkdir files
WORKDIR /files
RUN mkdir etc
WORKDIR /etc
RUN mkdir uci-defaults
WORKDIR /uci-defaults
COPY xx_custom /openwrt/files/etc/uci-defaults/xx_custom
WORKDIR /openwrt
RUN make -j 4
RUN ls /openwrt/bin/targets/ramips/mt76x8
WORKDIR /root
CMD ["bash"]
I want to copy all the files inside the folder mt76x8 to the host. I want to that inside the dockerfile so that when I run the docker file I should get the generated files in my host.
How can I do that?
you can use the volume mount to access the docker-generated artifacts on the host machine.
you can also run the command
docker cp to copy the files to the host machine.
if don't want to use the docker command as mention only option is to use the volume.
you can also use docker create once the docker image is ready to create the writable layer and copy data.
You have two choices.
Use docker volumes to map the /openwrt/bin/targets/ramips/mt76x8 folder when you are running the container. i.e. docker run -v {VoluneName}:/openwrt/bin/targets/ramips/mt76x8. All of the files in the mt76x8 folder would be available in the volume folder. If you are using Linux then you will find the docker volumes in /var/lib/docker/volumes/
You can use docker cp command to copy data from container to the host machine. Here is an example

Why can't I build this Dockerfile

So I was handed this Dockerfile to do some proyects in Drupal but I can't seem to build it
FROM introbay/php:7.4-apache
ENV DEBIAN_FRONTEND noninteractive
ENV TERM xterm
ENV COMPOSER_HOME /root/composer
ENV COMPOSER_VERSION master
COPY drupal-*.ini /usr/local/etc/php/conf.d/
RUN set -eux; \
apt-get update; \
apt-get install -y git unzip ruby-dev bundler; \
\
# Install composer
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer; \
\
# Install Prestissimo
composer global require hirak/prestissimo; \
\
rm -rf /var/lib/apt/lists/*; \
\
PATH=$PATH:/var/www/vendor/bin/;
The error I'm having is this one:
Step 6/7 : COPY drupal-*.ini /usr/local/etc/php/conf.d/
COPY failed: no source files were specified
I think you can get you answers on Best Book on Dockers
This should surely resolve your query.

Split up Dockerfile in two Images

I have a Dockerfile including e.g. apache, further installations and my code that is copied to /var/www/html to create a project. After I created the image locally, I export it as a .tar file and upload the image to portainer. Portainer is my productive environment. However, everytime when I want to update the Version and the services that are using my software, I have to update the whole new image which has a size of 800MB. Portainer has furthermore multiple managers, which causes that I have to upload it to each manager.
Because everything keeps the same, except my code that is inserted by the copy part COPY HRmAppBare/ /var/www/html, I thought about the idea, If it is possible to create two images. One Image for the whole Installations (let us say: 1.0-BaseInstall) and a second Image (let us say: 1.9-backend) that only stores my code. Then, for each Version update, I only have to upload the image with the new code and can maybe somehow refere to the 1.0-BaseInstall like e.g. From 1.0-BaseInstall. If the BaseInstall changes (which is really rarely), I could just create a new image for that.
Because I could not find anything about that, I want to know, if this approach is applicable and if yes, how I have to build this?
#start with base Image from php
FROM php:7.3-apache
#install system dependencies and enable PHP modules
RUN apt-get update && apt-get install -y \
libicu-dev \
vim \
cron \
libpq-dev \
libmcrypt-dev \
default-mysql-client \
zip \
unzip \
libzip-dev \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install zip \
&& rm -r /var/lib/apt/lists/* \
&& docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd \
&& docker-php-ext-install \
intl \
mbstring \
pcntl \
pdo_mysql \
opcache \
gettext \
&& pecl install mcrypt-1.0.2 \
&& docker-php-ext-enable mcrypt \
&& rm -rf /var/lib/apt/lists/*
#configure imap for mails
RUN apt-get update && \
apt-get install -y \
libc-client-dev libkrb5-dev && \
rm -r /var/lib/apt/lists/*
RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl && \
docker-php-ext-install -j$(nproc) imap
#install composer
#RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin/ --filename=composer
#change uid and gid of apache to docker user uid/gid, enable apache module rewrite
RUN usermod -u 1000 www-data && groupmod -g 1000 www-data && a2enmod rewrite
#copy the source code (Can this be in a 2nd image?)
COPY HRmAppBare/ /var/www/html
#Update apache2.conf
RUN echo 'Alias ${COOKIE_PATH} "/var/www/html"' >> /etc/apache2/apache2.conf
RUN echo 'Alias ${COOKIE_PATH}/ "/var/www/html/"' >> /etc/apache2/apache2.conf
#change ownership of our applications
RUN chown -R www-data:www-data /var/www/html/
ENTRYPOINT [ "sh", "-c", "rm /var/www/html/app/tmp/cache/models/* && rm /var/www/html/app/tmp/cache/persistent/* && /var/www/html/app/Console/cake schema update -y && apache2-foreground"]
EXPOSE 80
You can break this into multiple docker files and it would be viable.
If you have no other consumers of the base image it may create confusion and just add more overhead to have to manage versions for your base image and your application but it is certainly viable.
It may be worth it to look into multi-stage builds.
https://github.com/docker/docker.github.io/blob/master/develop/develop-images/multistage-build.md
If the objects on the file system that Docker is about to produce are unchanged between builds, reusing a cache of a previous build on the host is a great time-saver. It makes building a new container really, really fast.
https://thenewstack.io/understanding-the-docker-cache-for-faster-builds/
I'm unsure when you say
Then, for each Version update, I only have to upload the code
I may be misunderstanding the phrase but instead I would suggest having all of the builds done on your build box and have the versioned image pushed to a docker repo for your production box to pull from when you're ready to grab the next version. You shouldn't need to upload your code anywhere. Just the built image to whatever docker repo you store your images on.
Edit: Add in link for creating your own docker repo
https://docs.docker.com/registry/deploying/
Edit 2: To better answer your question
FROM php:7.3-apache AS base
//...rest of your dockerfile until copy
FROM base
#copy the source code (Can this be in a 2nd image?)
COPY HRmAppBare/ /var/www/html
#Update apache2.conf
RUN echo 'Alias ${COOKIE_PATH} "/var/www/html"' >> /etc/apache2/apache2.conf
RUN echo 'Alias ${COOKIE_PATH}/ "/var/www/html/"' >> /etc/apache2/apache2.conf
#change ownership of our applications
RUN chown -R www-data:www-data /var/www/html/
ENTRYPOINT [ "sh", "-c", "rm /var/www/html/app/tmp/cache/models/* && rm /var/www/html/app/tmp/cache/persistent/* && /var/www/html/app/Console/cake schema update -y && apache2-foreground"]
EXPOSE

How to handle PHP project code in docker container

I ran into kind of a hen-and-egg problem with my docker setup. In my Dockerfile I install nginx, php and the needed configurations. I also install composer there:
FROM ubuntu
RUN apt-get update && apt-get install -y \
curl \
nginx \
nodejs \
php7.0-fpm \
php-intl \
php-pgsql
RUN rm -rf /var/lib/apt/lists/* && \
echo "\ndaemon off;" >> /etc/nginx/nginx.conf && \
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin && \
chown -R www-data:www-data /var/www/
COPY orocrm /etc/nginx/sites-available/
RUN ln -s /etc/nginx/sites-availabe/orocrm /etc/nginx/sites-enabled/orocrm
CMD nginx
Now, the next step would be to actually install all dependencies in the project directory via composer. And this is where the trouble starts: As this is my development machine, I don't want to copy my local project files over to the docker container. Instead, I mounted it in my docker-compose.yml:
version: '3'
services:
web:
...
volumes:
- "./crm-application:/var/www/orocrm/"
I cannot put composer install in the Dockerfile, as the mounting of the directory (in my docker-compose file) is taking place after the Dockerfile is run.
What is the best solution here? Another option which comes to my mind is intially copying the files into the container and later on use a filewatcher to scp the changed files into the container. Not a nice solution, though.
UPDATE I would like to emphasize what my actual problem is: I am on my development machine and I want to continuously update the code and have the changes mirrored instantly withouth building the image once again. Therefore, COPY is not an option.
My suggestion is to copy your content in your container using the COPYcommand, like this
FROM ubuntu
COPY ./crm-application /var/www/orocrm/
RUN apt-get update && apt-get install -y \
curl \
nginx \
nodejs \
php7.0-fpm \
php-intl \
php-pgsql
RUN rm -rf /var/lib/apt/lists/* && \
echo "\ndaemon off;" >> /etc/nginx/nginx.conf && \
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin && \
chown -R www-data:www-data /var/www/ && \
composer install
COPY orocrm /etc/nginx/sites-available/
RUN ln -s /etc/nginx/sites-availabe/orocrm /etc/nginx/sites-enabled/orocrm
CMD nginx
Why? in this way you don't need to use docker-compose or another system. You're going to be able to run your single container.
Even if you want to use docker-compose, you're using a volume that allows you to update the code inside your container.
Notice that I've added composer install in the Docker because you've already the code inside the container at the moment of the build.
Regards,
Idir!

How to add couchdb server into docker creation file

I have a docker file like this :
FROM ubuntu:12.04
MAINTAINER me <me#c.com>
RUN apt-get -y update
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install supervisor \
apache2 \
mysql-server \
php5 \
libapache2-mod-php5 \
php5-mysql \
php5-mcrypt
#ssh
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:root' | chpasswd
RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed 's#session\s*required\s*pam_loginuid.so#session optional pam_loginuid.so#g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
EXPOSE 22 80
ADD ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD ["/usr/bin/supervisord"]
My question is how do I add a couchdb server into this docker file?
I can get a built-in couchdb docker image from here : https://hub.docker.com/r/klaemo/couchdb/, but how do I create a image like this my self? I can't find any documentation regarding the process!
I spent 3 hours tried to googled but got no luck, so I will take the risk to ask even if this is a dump question!
Is there a specific version of couchdb that you want in your docker container?
If not, since you are using Ubuntu 12.04 as your base image, you can get the couchdb 1.0.1 binaries from the Ubuntu 12.04/precise [universe] repository easily by adding couchdb to your apt-get list like this:
FROM ubuntu:12.04
MAINTAINER me <me#c.com>
RUN apt-get -y update
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install supervisor \
apache2 \
mysql-server \
php5 \
libapache2-mod-php5 \
php5-mysql \
php5-mcrypt \
couchdb
#[--Rest of your dockerfile goes here unchanged--]
You can alternatively use the PPA maintained by the Apache CouchDB team to get latest stable releases for your base image based on the officially released tar balls. For this option you can use the following dockerfile:
# To install the ppa finder tool in your docker container
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install python-software-properties
RUN add-apt-repository ppa:couchdb/stable -y
RUN apt-get -y update
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install supervisor \
apache2 \
mysql-server \
php5 \
libapache2-mod-php5 \
php5-mysql \
php5-mcrypt \
couchdb
#[--Rest of your dockerfile goes here unchanged--]
If you want the latest or a specific version of couchdb in your docker container then you might have to build couchdb from the source code. Note that this approach will require you to install many more packages (g++ erlang-dev erlang-manpages erlang-base-hipe erlang-eunit, libmozjs185-dev libicu-dev libcurl4-gnutls-dev libtool) onto your container to be able to build couchdb from source. However you may be able to purge/remove the packages that are required only to build couchdb. The complete list of dependencies can be found on the official couchdb build wiki on apache. If you really want THE latest version then you can refer to this dockerfile and add update your dockerfile accordingly. Here is a complete dockerfile [UNTESTED] for your ease of use:
FROM ubuntu:12.04
MAINTAINER me <me#c.com>
ENV COUCHDB_VERSION master
RUN groupadd -r couchdb && useradd -d /usr/src/couchdb -g couchdb couchdb
# download dependencies
RUN apt-get update -y -qq && apt-get install -y --no-install-recommends \
build-essential \
erlang-dev \
erlang-manpages \
erlang-base-hipe \
erlang-eunit \
erlang-nox \
erlang-xmerl \
erlang-inets \
libmozjs185-dev \
libicu-dev \
libcurl4-gnutls-dev \
libtool
RUN cd /usr/src && git clone https://git-wip-us.apache.org/repos/asf/couchdb.git \
&& cd couchdb && git checkout $COUCHDB_VERSION \
&& cd /usr/src/couchdb && ./configure && make
# You can optionally purge/remove the packages you installed to build the couchdb from source.
# permissions
RUN chmod +x /usr/src/couchdb/dev/run && chown -R couchdb:couchdb /usr/src/couchdb
USER couchdb
EXPOSE 5984 15984 25984 35984 15986 25986 35986
#[--Rest of your dockerfile can go here as required--]

Resources