Creating a custom docker container to match my server - php

I am new to docker, needed to use it for a legacy project that requires php5. Here is my Dockerfile snippet:
FROM ubuntu:14.04.1
LABEL MAINTAINER Hasan
RUN apt-get update && \
apt-get install -y apache2 && \
apt-get install -y mysql-server php5-mysql && \
apt-get install -y php5 libapache2-mod-php5 php5-mcrypt
WORKDIR /var/www/html
COPY . /var/www/html
EXPOSE 80
CMD service apache2 start
Here is the command to build it:
docker build -t rakibtg/oldapp .
It gives few error including 'Hash Sum mismatch' and 'returned a non-zero code: 100'
Fetched 16.7 MB in 60s (274 kB/s)
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/p/perl/perl-modules_5.18.2-2ubuntu1.4_all.deb Hash Sum mismatch
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
The command '/bin/sh -c apt-get update && apt-get install -y apache2 && apt-get install -y mysql-server php5-mysql && apt-get install -y php5 libapache2-mod-php5 php5-mcrypt' returned a non-zero code: 100
What should i do to fix it?
Also, is the CMD is configured properly here? Any guide would be appreciated
I am using docker on mac

This error seems more linked to apt-get behavior rather than to Docker.
You can try:
FROM ubuntu:14.04.1
LABEL MAINTAINER Hasan
RUN apt-get clean && apt-get update && \
apt-get install -y apache2 && \
apt-get install -y mysql-server php5-mysql && \
apt-get install -y php5 libapache2-mod-php5 php5-mcrypt
WORKDIR /var/www/html
COPY . /var/www/html
EXPOSE 80
CMD apachectl -D FOREGROUND
or other solutions mentioned in Troube downloading packages list due to a hash sum mismatch error
By the way I changed your CMD statement. Indeed when using service the process will be detached from shell and Docker will stop the container (See How to start apache2 automatically in a ubuntu docker container? for associated explanations)

Related

How to Create PHP Envirnoment in Docker?

I am trying to dockerize php web-app with apache2 server. any better way to create environment for php and apache2. I have search on internet cloud not able to find any solution.
I have used ubuntu:latest as base image,I have tried to create image in step if first one work than go ahead. I have already tried to create image without php and i was succesful to run docker container but without PHP there is no meaning to run than I have take next step to add PHP into image, now I am stuck.
There is image of Error below.
Here is my Dockerfile
#Download base image
FROM ubuntu:latest
#Install tzdata and set timezone.
#Update all packages run the 'apt update' command before installing any packages.
#we need to use -y flag otherwise it will ask for yes/no?
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata && apt-get install -y software-properties-common
#Install C/C++
RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test
#RUN apt install build-essential
RUN apt-get update -y
RUN apt-get install -y gcc
RUN apt-get install -y g++
RUN ln -f -s /usr/bin/gcc /usr/bin/gcc
RUN ln -f -s /usr/bin/g++ /usr/bin/g++
RUN apt-get update -y
RUN add-apt-repository ppa:ondrej/php
# Install apache, PHP, and supplimentary programs. openssh-server, curl, and lynx-cur are for debugging the container.
RUN apt-get update && apt-get -y upgrade && DEBIAN_FRONTEND=noninteractive apt-get -y install \
apache2 php7.4 php7.4-mysql libapache2-mod-php7.4 curl lynx-common
# Enable apache mods.
RUN a2enmod php7.4
RUN a2enmod rewrite
#Remove any unnecessary files
RUN apt-get clean
#Setup Apache2 servers
#Debian configuration requires the environment variables APACHE_RUN_USER, APACHE_RUN_GROUP, and APACHE_PID_FILE to be set
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_PID_FILE /var/run/apache2.pid
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
#Expose ports
EXPOSE 80
#Change Permission
RUN chmod -R 777 /var/www/html/
#Copy files to webserver
COPY editor /var/www/html/
# Remove Default index.html
RUN rm /var/www/html/index.html
#Start services
CMD ["/usr/sbin/apache2ctl","-D","FOREGROUND"]
Thanks!!
The symbolic links for g++ & gcc are not good.
The following worked for me:
#Download base image
FROM ubuntu:latest
#Install tzdata and set timezone.
#Update all packages run the 'apt update' command before installing any packages.
#we need to use -y flag otherwise it will ask for yes/no?
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata && apt-get install -y software-properties-common
#Install C/C++
RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test
#RUN apt install build-essential
RUN apt-get update -y && apt-get install -y gcc g++
#RUN apt-get install -y gcc
#RUN apt-get install -y g++
#RUN ln -f -s /usr/bin/gcc /usr/bin/gcc
#RUN ln -f -s /usr/bin/g++ /usr/bin/g++
#RUN apt-get update -y
RUN add-apt-repository ppa:ondrej/php
# Install apache, PHP, and supplimentary programs. openssh-server, curl, and lynx-cur are for debugging the container.
RUN apt-get update && apt-get -y upgrade && DEBIAN_FRONTEND=noninteractive apt-get -y install apache2 php7.4 php7.4-mysql libapache2-mod-php7.4 curl lynx-common
# Enable apache mods.
RUN a2enmod php7.4
RUN a2enmod rewrite
#Remove any unnecessary files
RUN apt-get clean
#Setup Apache2 servers
#Debian configuration requires the environment variables APACHE_RUN_USER, APACHE_RUN_GROUP, and APACHE_PID_FILE to be set
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_PID_FILE /var/run/apache2.pid
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
#Expose ports
EXPOSE 80
#Change Permission
RUN chmod -R 777 /var/www/html/
#Copy files to webserver
COPY editor /var/www/html/
# Remove Default index.html
RUN rm /var/www/html/index.html
#Start services
CMD ["/usr/sbin/apache2ctl","-D","FOREGROUND"]

Docker PHP7 CLI Debian Buster how to install package php-imagick?

I have a PHP-CLI Docker image of Debian Buster and would like to install php-imagick package but with command:
Dockerfile:
RUN apt-get install -y php-imagick
I get an error:
Package php-imagick is not available, but is referred to by another
package. This may mean that the package is missing, has been
obsoleted, or is only available from another source
E: Package 'php-imagick' has no installation candidate
running before:
RUN apt-get update -y && apt-get upgrade -y
did not help.
how come there is no package candidate for php-imagick?
how to install and enable imagick extension for this PHP Docker image?
Dockerfile to replicate issue:
FROM php:7.3-buster
RUN apt-get update -y && apt-get upgrade -y
RUN apt-get install -y php-imagick
build command
docker build --tag testimage .
Unless you have a good reason not to, using the packages from https://deb.sury.org/ is probably a good idea. The following appears to work:
FROM debian:buster-slim
USER root
# Get Debian up-to-date
RUN apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y git \
mariadb-client wget curl \
ca-certificates lsb-release apt-transport-https gnupg bsdmainutils
RUN echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | tee -a /etc/apt/sources.list.d/php.list \
&& curl https://packages.sury.org/php/apt.gpg | apt-key add - \
&& apt-get update -qq \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y php7.3 php7.3-common php7.3-cli \
php7.3-mysql php7.3-curl php7.3-xml php7.3-mbstring \
php7.3-intl php7.3-redis php7.3-zip \
php7.3-imagick supervisor

Docker image does not work on AWS Fargate but it does in EC2

I'm changing infrastructure on AWS and I want to use Docker (ECS) with Fargate. My Docker image is based on Ubuntu and I install all I need in it. I'm using Laravel 5.6 on NGINX running PHP 7.2. My Docker container works on my local machine and if I run ECS with EC2, however when I change to Fargate it returns NGINX 500 error. I did some tests and I know PHP is running, only when I install my Laravel app the error happens.
Since I cannot access Fargate machine I don't know how to debug. I tryied to connect NGINX with Loggly however it requires rsyslog and since I'm using Docker it cannot access Ubuntu's core. When I install and try to run it returns:
rsyslogd: imklog: cannot open kernel log (/proc/kmsg): Operation not permitted
Here is my Dockerfile:
FROM ubuntu:latest
ENV BACKEND_PATH=/code/Backend
ENV FRONTEND_PATH=/code/Frontend
## Update
RUN apt-get update -y
## Upgrade
RUN apt-get install -y software-properties-common
RUN add-apt-repository -y ppa:certbot/certbot
RUN apt-get update -y
RUN apt-get upgrade -y
RUN apt-get dist-upgrade -y
RUN apt-get autoremove -y
RUN apt-get update -y
## Nano
RUN apt-get install -y nano
## Timezone
RUN echo "America/Sao_Paulo" > /etc/timezone && \
apt-get install -y tzdata && \
rm /etc/localtime && \
ln -snf /usr/share/zoneinfo/America/Sao_Paulo /etc/localtime && \
dpkg-reconfigure -f noninteractive tzdata && \
apt-get clean
## Git
RUN apt-get install -y git
## NGINX
RUN apt-get install -y nginx
COPY ./nginx/app/sites-available /etc/nginx/sites-available
COPY ./nginx/app/sites-available /etc/nginx/sites-enabled
COPY ./nginx/sites /etc/nginx/sites
COPY ./nginx/ssl /ssl
## PHP
RUN apt-get install -y php-cli php-fpm php-curl php-mbstring
COPY ./php/php.ini /usr/local/etc/php
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Install libs
RUN apt-get install -y php-zip php-mysql php-gd pngquant gifsicle jpegoptim libicu-dev g++ php-intl php-xml
## Crontab
RUN apt-get install -y cron
COPY crontab newcrontab
RUN crontab newcrontab
RUN rm newcrontab
## Supervisor
RUN apt-get install -y supervisor
COPY ./supervisord /etc/supervisor/conf.d
## Certbot
RUN apt-get install -y python-certbot-nginx
## Install apps
COPY ./code/Backend /code/Backend
COPY ./code/Frontend/dist /code/Frontend/dist
RUN cd ${BACKEND_PATH} && chmod +x composer.phar && ./composer.phar self-update && php composer.phar install
RUN chmod -Rf 777 ${BACKEND_PATH}/storage
RUN chmod -Rf 777 ${BACKEND_PATH}/resources
RUN php ${BACKEND_PATH}/artisan config:clear
RUN php ${BACKEND_PATH}/artisan passport:keys
## Run!
EXPOSE 80 443
RUN service php7.2-fpm start
CMD ["/usr/bin/supervisord"]
I think this error has something to do with permissions but without error message it's almost impossible to know what's going on... Does anyone have any ideia how I may find this out?
I figured it out. Really stupid mistake actually. When I created Fargate configurations I used a Security Group without permissions to access some AWS components so the application was unable to boot.
Check out this answer on ServerFault: https://serverfault.com/questions/691048/kernel-log-stays-empty-rsyslogd-imklog-cannot-open-kernel-log-proc-kmsg
Try running the Fargate task with the --privileged flag. You can set this flag in the AWS console per-container in the task definition. It's in the SECURITY section near the end of the container definition. Here's the full reference for container definitions.

facing error while install imagemagick Ubuntu 14.04

I am new to use ubuntu, to install imagemagick I have run below command
sudo apt-get update
but it showing error
I have executed below commands as well but not able to install
sudo -i
cd
apt-get install build-essential checkinstall && apt-get build-dep imagemagick -y
wget http://www.imagemagick.org/download/ImageMagick-6.8.7-7.tar.gz
tar xzvf ImageMagick-6.8.9-1.tar.gz
cd ImageMagick-6.8.9-1/
./configure --prefix=/opt/imagemagick-6.8 && make
checkinstall
https://gist.github.com/rodleviton/74e22e952bd6e7e5bee1
Google has dropped the support for 32-bit version for chrome on Linux and that is the reason you are seeing that error.
Edit /etc/apt/sources.list.d/google-chrome.list - You would need sudo
Replace the existing line with deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main
Run sudo apt-get update now.
And what is the error you are seeing when you are trying to install imagemagick?

Dockerfile php-fpm unmet dependencies

I have a Dockerfile in which to build a container for php-fpm. I pulled in my base ubuntu image and it gets to work but then exits when trying to install php-fpm and php5-intl due to unmet dependencies.
Can anyone check over my file and spot anything obvious please :)
FROM phalcon/ubuntu
MAINTAINER bob <bob#bob.com>
RUN echo "deb http://archive.ubuntu.com/ubuntu/ vivid universe" >> /etc/apt/sources.list
# Install software requirements
RUN apt-get update && \
apt-get install -y software-properties-common && \
add-apt-repository -y ppa:ondrej/php5 && \
add-apt-repository -y ppa:nginx/stable && \
apt-get update -y --force-yes && \
apt-get upgrade -y --force-yes && \
BUILD_PACKAGES="supervisor php5-fpm git php5-mysql php5-curl php5-gd php5-intl php5-mcrypt php5-memcache php5-sqlite php5-tidy php5-xmlrpc php5-xsl php5-pgsql php5-mongo php5-dev pwgen" && \
apt-get -y --force-yes install $BUILD_PACKAGES && \
apt-get remove --purge -y software-properties-common && \
apt-get autoremove -y && \
apt-get clean && \
apt-get autoclean
# Add PHP config.
ADD php-fpm.conf /etc/php-fpm.conf
# Define mountable directories.
VOLUME ["/etc/php-fpm.d", "/var/log/php-fpm", "/srv/http"]
# Define entrypoint.
ENTRYPOINT ["php-fpm"]
# Expose ports.
EXPOSE 9000
Probably some issue regarding the use of the source image phalcon/ubuntu from what I can see.
There's actually no reason to build your own PHP-FPM image, as official ones are supplied: https://hub.docker.com/_/php/ This way you can select the exact PHP version you want to use.
Just for kicks, here is the repository from which the image is built (PHP 5.6): https://github.com/docker-library/php/tree/master/5.6/fpm

Categories