How to edit files inside of docker containers for development? - docker

I'm creating my Typo3 develop instance with docker containers. And in order to understand what I'm doing so I can understand completely my workflow I'm trying to keep it simple and go step by step to a more advanced instance.
This is my docker-compose file.
This mounted volumes are fine, they are being mounter, their permissions are for root.
What I do is to go inside of the container and set users and groups as www-data in order to access these files from the browser and then on the host set my user as the owner so I can edit them from the host.
But is this right? is this the correct approach? Because I have seen some scripts where all you need to do is to set www-data inside of the container, so I wonder why the permissions on my case are root.
version: "3"
services:
typo3:
build: .
ports:
- "80:80"
volumes:
- ./fileadmin:/var/www/html/fileadmin
- ./typo3conf:/var/www/html/typo3conf
- ./uploads:/var/www/html/uploads
networks:
- backend
database:
image: mysql:8.0
command:
- --character-set-server=utf8
- --collation-server=utf8_unicode_ci
environment:
- "MYSQL_USER=${MYSQL_USER}"
- "MYSQL_PASSWORD=${MYSQL_PASSWORD}"
- "MYSQL_DATABASE=${MYSQL_DATABASE}"
- "MYSQL_RANDOM_ROOT_PASSWORD=${MYSQL_ROOT}"
networks:
- backend
volumes:
database:
fileadmin:
typo3conf:
uploads:
networks:
backend:
Dockerfile:
# Docker image for TYPO3 CMS
# Copyright (C) 2016-2020 Martin Helmich <martin#helmich.me>
# and contributors <https://github.com/martin-helmich/docker-typo3/graphs/contributors>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
FROM php:7.4-apache-buster
LABEL maintainer="Martin Helmich <typo3#martin-helmich.de>"
# Install TYPO3
RUN apt-get update && \
apt-get install -y --no-install-recommends \
wget \
# Configure PHP
libxml2-dev libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng-dev \
libpq-dev \
libzip-dev \
zlib1g-dev \
# Install required 3rd party tools
graphicsmagick && \
# Configure extensions
docker-php-ext-configure gd --with-libdir=/usr/include/ --with-jpeg --with-freetype && \
docker-php-ext-install -j$(nproc) mysqli soap gd zip opcache intl pgsql pdo_pgsql && \
echo 'always_populate_raw_post_data = -1\nmax_execution_time = 240\nmax_input_vars = 1500\nupload_max_filesize = 32M\npost_max_size = 32M' > /usr/local/etc/php/conf.d/typo3.ini && \
# Configure Apache as needed
a2enmod rewrite && \
apt-get clean && \
apt-get -y purge \
libxml2-dev libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng-dev \
libzip-dev \
zlib1g-dev && \
rm -rf /var/lib/apt/lists/* /usr/src/*
RUN cd /var/www/html && \
wget -O download.tar.gz https://get.typo3.org/10.4.19 && \
echo "8eb40d02954ffe431c8a41420e4d73d9e0a702714960ecca89162d87ca0e4118 download.tar.gz" > download.tar.gz.sum && \
sha256sum -c download.tar.gz.sum && \
tar -xzf download.tar.gz && \
rm download.* && \
ln -s typo3_src-* typo3_src && \
ln -s typo3_src/index.php && \
ln -s typo3_src/typo3 && \
cp typo3/sysext/install/Resources/Private/FolderStructureTemplateFiles/root-htaccess .htaccess && \
mkdir typo3temp && \
mkdir typo3conf && \
mkdir fileadmin && \
mkdir uploads && \
touch FIRST_INSTALL && \
chown -R www-data. .
# Configure volumes
VOLUME /var/www/html/fileadmin
VOLUME /var/www/html/typo3conf
VOLUME /var/www/html/typo3temp
VOLUME /var/www/html/uploads

There are many ways to do that, for me, I usually use next 2 options:
Enter into the container with docker exec -it $your_container_name /bin/bash, then install vim or nano in container.
Modern IDE/editor provides direct access to container, so you could develop/edit files in container just like you are doing it in local.
E.g. VSCode afford "remote containers plugin", after enable it, you could just in your host pc to development the files in container.
Details refers to Developing inside a Container

Related

Docker: Build fail on another host with same configuration

I'm using Docker in a developement environment. I have two pc, both with same OS (kubuntu 20.04) and same docker version.
In one the dockerfile build without errors, in the other fails with
$ docker build -t letsjump/mydockername -f docker-data/webserver73/Dockerfile .
#...lot of compile output...
configure: error: unrecognized options: --with-freetype, --with-jpeg, --with-freetype, --with-webp
The command '/bin/sh -c curl -sL https://deb.nodesource.com/setup_12.x | bash - && apt-key update && DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" install $CUSTOM_BUILD_DEPS $PHPIZE_DEPS sendmail git mariadb-client openssh-client nano netcat linkchecker nodejs build-essential libzip-dev libz-dev wget unixodbc odbcinst unixodbc-dev gnupg libwebp-dev libonig-dev --no-install-recommends && npm -g install npm#latest && docker-php-ext-configure gd --with-freetype --with-jpeg --with-freetype --with-webp && docker-php-ext-configure bcmath && docker-php-ext-configure calendar && docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr && docker-php-ext-install gd intl pdo_mysql mysqli mbstring opcache zip bcmath calendar soap && pecl install memcached-3.1.5 && echo extension=memcached.so >> /usr/local/etc/php/conf.d/memcached.ini && printf "\n" | pecl -d preferred_state=beta install xdebug' returned a non-zero code: 1
In both hosts I have the same OS (kubuntu 20.04 desktop) and almost the same Docker version.
In this host the dockerfile build succesfully:
$ docker --version
Docker version 19.03.5, build 633a0ea838
In this other not:
$ docker --version
Docker version 19.03.12, build 48a66213fe
This is the dockerfile:
# Dockerfile (c) letsjump 2018
FROM php:7.3-apache
MAINTAINER letsjump <letsjump#xxx>
WORKDIR /
COPY ./docker-data/webserver73/ /
RUN chown -R "$APACHE_RUN_USER:$APACHE_RUN_GROUP" "/usr/local/bin";
RUN chmod -R +xr "/usr/local/bin/";
EXPOSE 80
EXPOSE 443
RUN useradd -ms /dev/null dbmaker
RUN chown -R dbmaker:dbmaker /home/dbmaker
# define build dependency lists
# inherited from PHP base image:
# PHPIZE_DEPS=autoconf dpkg-dev file g++ gcc libc-dev libpcre3-dev make pkg-config re2c
ENV CUSTOM_BUILD_DEPS \
unzip \
libmemcached-dev \
libicu-dev \
libfreetype6-dev \
libjpeg-dev \
libjpeg62-turbo-dev \
libxml2-dev \
zlib1g-dev \
libpng-dev
# list of other packages which could be deinstalled at the end
ENV CUSTOM_REMOVE_LIST cpp \
cpp-4.9 \
g++-4.9 \
gcc-4.9 \
libgcc-4.9-dev \
libhashkit-dev \
libsasl2-dev \
libstdc++-4.9-dev
RUN apt-get update && apt-get install -my gnupg
# Install system packages for PHP extensions recommended for Yii 2.0 Framework
# Install PHP extensions required for Yii 2.0 Framework
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash - && \
apt-key update && \
DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" install \
$CUSTOM_BUILD_DEPS \
$PHPIZE_DEPS \
sendmail \
git \
mariadb-client \
openssh-client \
nano \
netcat \
linkchecker \
nodejs \
build-essential \
libzip-dev \
libz-dev \
wget \
unixodbc \
odbcinst \
unixodbc-dev \
gnupg \
libwebp-dev \
libonig-dev \
--no-install-recommends && \
npm -g install npm#latest && \
docker-php-ext-configure gd --with-freetype --with-jpeg --with-freetype --with-webp && \
docker-php-ext-configure bcmath && \
docker-php-ext-configure calendar && \
docker-php-ext-configure pdo_odbc --with-pdo-odbc=unixODBC,/usr && \
docker-php-ext-install gd \
intl \
pdo_mysql \
mysqli \
mbstring \
opcache \
zip \
bcmath \
calendar \
soap && \
# printf "\n" | pecl -d preferred_state=beta install xdebug
pecl install memcached-3.1.5 && \
echo extension=memcached.so >> /usr/local/etc/php/conf.d/memcached.ini && \
printf "\n" | pecl -d preferred_state=beta install xdebug
# apt-get remove -y $PHPIZE_DEPS $CUSTOM_BUILD_DEPS $CUSTOM_REMOVE_LIST && \
# dpkg --purge $(dpkg -l | awk '/^rc/ { print $2 }') && \
# apt-get clean && \
# rm -rf /usr/src/php* && \
# rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
#set -x \
# && cd /usr/src/php/ext/odbc \
# && phpize \
# && sed -ri 's#^ *test +"\$PHP_.*" *= *"no" *&& *PHP_.*=yes *$##&#g' configure \
# odbc
# docker-php-ext-configure odbc --with-unixODBC=/usr --with-dbmaker=/home/dbmaker/5.2 && \
# docker-php-ext-configure odbc --with-unixODBC=/usr --with-dbmaker=/home/dbmaker/5.2 --with-adabas=no && \
# Install less-compiler
RUN npm install -g \
less \
lesshint \
uglify-js \
uglifycss
ENV PHP_USER_ID=33 \
PHP_ENABLE_XDEBUG=1 \
VERSION_COMPOSER_ASSET_PLUGIN=^1.4.6 \
VERSION_PRESTISSIMO_PLUGIN=^0.3.10 \
PATH=/var/www/:/root/.composer/vendor/bin:$PATH \
TERM=linux \
COMPOSER_ALLOW_SUPERUSER=1 \
GITHUB_API_TOKEN=${GITHUB_API_TOKEN}
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- \
--install-dir=/usr/local/bin \
--filename=composer --version=1.10.16 && \
composer global require --optimize-autoloader \
"fxp/composer-asset-plugin:${VERSION_COMPOSER_ASSET_PLUGIN}" \
"hirak/prestissimo:${VERSION_PRESTISSIMO_PLUGIN}" && \
composer global dumpautoload --optimize && \
composer clear-cache
RUN chown -R 1000:33 /var/www
# Install Yii framework bash autocompletion
RUN curl -L https://raw.githubusercontent.com/yiisoft/yii2/master/contrib/completion/bash/yii \
-o /etc/bash_completion.d/yii
# enabling specific apache2 modules
# enabling specific apache2 modules
RUN a2enmod rewrite && \
service apache2 restart
WORKDIR /var/www
Yes, the dockerfile is probably a mess, with a lot of adds on the fly. But why it compiles in one host and in the other not?
UPDATE
After reading the reasonable answer of aankhen, I emptied the docker-data/webserver73 folder which in any case did not contain any relevant code except one apache virtualhost and one xdebug.ini configuration file in their relative folders.
The build failed again with the same error as above.
I also want to point out that the wevserver73 folder contains the exact same files as the one on the other host with the same owner and rights.
I would expect failures to happen sporadically and periodically with this dockerfile. Why? Because you haven't pinned the versions of the majority of tools you're installing. You implicitly install the latest version of a bunch of GNU/Linux libraries and then explicitly install the latest version of npm and you follow this up by using npm to install the latest version of a bunch of javascript modules. I can see that you pin the versions of some libs, but to guarantee repeatability you have to pin everything.
Also, as #Aankhen said in the comments, you also have a copy command that is copying files from the local filesystem, which could contain anything and again is unlikely to result in a portable repeatable image.
The solution to this is a) pin everything, or b) use a registry to share an image that has been built once and rely on a pinned version of that. Generally, banks and large corporations require the pinning solution, and less regulated industries often go with the registry solution.
I answer to my question:
As Software-engineer said in his answer, pin, pin, pin.
In this case it was the PHP's mantainers (questionable) choice to change the Debian release within a minor version of the docker image (php:7.3-apache). Here they switched from stretch to buster.
So the new pulled php:7.3-apache image had a completely different OS and different dependent library and behaviors.
So, as Software-engineer said, the right and the fastest solution to this problem is to pin the PHP image to a tag related to the distribution: php:7.3-apache-stretch.
The slower and unstable solution, in case you want to use the unpinned version, is to adapt the GD configure options to the new release:
...
docker-php-ext-configure gd --with-gd --with-webp-dir --with-jpeg-dir \
--with-png-dir --with-zlib-dir --with-freetype-dir && \
...
taking care to include the necessary libraries first: libfreetype6-dev, libjpeg-dev and libjpeg62-turbo-dev
But this will require a manual pull from the server for any host that has a non recent build of the same image.

VS code remote containers - connect to a database either on host machine or one in a separate docker-compose file

I have started using VS code remote containers, specifically the GO one thats generated for you via the options. It provides a devcontainer.json file and a Dockerfile which works fine.
My problem is trying to connect to a database from within this remote container.
I have tried spinning up a separate postgres database using docker-compose and have also tried connecting to a database installed on my base machine.
However each time I try to connect either via db, err := sqlx.Connect("postgres", dsn) or using soda soda migrate up if just hangs for a while before saying its unable to connect.
Has anyone got a solution to connecting to a DB?
This is my dockerfile for go:
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
FROM golang:1
# This Dockerfile adds a non-root user with sudo access. Use the "remoteUser"
# property in devcontainer.json to use it. On Linux, the container user's GID/UIDs
# will be updated to match your local UID/GID (when using the dockerFile property).
# See https://aka.ms/vscode-remote/containers/non-root-user for details.
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID
# Configure apt, install packages and tools
RUN apt-get update \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \
#
# Verify git, process tools, lsb-release (common in install instructions for CLIs) installed
&& apt-get -y install git openssh-client less iproute2 procps lsb-release \
#
# Build Go tools w/module support
&& mkdir -p /tmp/gotools \
&& cd /tmp/gotools \
&& GOPATH=/tmp/gotools GO111MODULE=on go get -v golang.org/x/tools/gopls#latest 2>&1 \
&& GOPATH=/tmp/gotools GO111MODULE=on go get -v \
honnef.co/go/tools/...#latest \
golang.org/x/tools/cmd/gorename#latest \
golang.org/x/tools/cmd/goimports#latest \
golang.org/x/tools/cmd/guru#latest \
golang.org/x/lint/golint#latest \
github.com/mdempsky/gocode#latest \
github.com/cweill/gotests/...#latest \
github.com/haya14busa/goplay/cmd/goplay#latest \
github.com/sqs/goreturns#latest \
github.com/josharian/impl#latest \
github.com/davidrjenni/reftools/cmd/fillstruct#latest \
github.com/uudashr/gopkgs/v2/cmd/gopkgs#latest \
github.com/ramya-rao-a/go-outline#latest \
github.com/acroca/go-symbols#latest \
github.com/godoctor/godoctor#latest \
github.com/rogpeppe/godef#latest \
github.com/zmb3/gogetdoc#latest \
github.com/fatih/gomodifytags#latest \
github.com/mgechev/revive#latest \
github.com/go-delve/delve/cmd/dlv#latest 2>&1 \
#
# Build Go tools w/o module support
&& GOPATH=/tmp/gotools go get -v github.com/alecthomas/gometalinter 2>&1 \
#
# Build gocode-gomod
&& GOPATH=/tmp/gotools go get -x -d github.com/stamblerre/gocode 2>&1 \
&& GOPATH=/tmp/gotools go build -o gocode-gomod github.com/stamblerre/gocode \
#
# Install Go tools
&& mv /tmp/gotools/bin/* /usr/local/bin/ \
&& mv gocode-gomod /usr/local/bin/ \
#
# Install golangci-lint
&& curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/local/bin 2>&1 \
#
# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
&& groupadd --gid $USER_GID $USERNAME \
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
# [Optional] Add sudo support
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME \
#
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/* /tmp/gotools
# Update this to "on" or "off" as appropriate
ENV GO111MODULE=auto
This is the devcontainer.json file:
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.122.1/containers/go
{
"name": "Go",
"dockerFile": "Dockerfile",
"runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],
// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
"go.gopath": "/go"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"golang.Go"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [3000],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "go version",
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
// "remoteUser": "vscode"
}
This is the docker-compose file I am using for the DB
version: "3.1"
services:
db:
image: postgres:10.10
environment:
POSTGRES_PASSWORD: pass
POSTGRES_USER: user
POSTGRES_DB: my_db
container_name: test_db
ports:
- 1234:5432
restart: "no"
volumes:
- ../postgres-data:/var/lib/postgresql/data
Soda uses a .yml file to connect to the database and its as follows:
development:
dialect: postgres
database: my_db
user: user
password: pass
host: 174.24.0.1
port: 1234
Thanks in advance
Great answer here if anyone is still looking:
If your database is running on host machine, you can use this:
development:
dialect: postgres
database: my_db
user: user
password: pass
host: host.docker.internal
port: 1234

ERROR creating Service web with unrecognized option '--with-freetype-dir=/usr/include/'

After reinstall of Kubuntu 18 I run my docker project with command to run my first project:
docker-compose up -d --build
and got long output (it worked more 1 hour I suppose) and errors at end :
...
touch /var/www/html/node/out/Release/obj.host/tools/icu/icuuc.stamp
rm db5d6824c8b1d399378961ab1ba16292d5634a89.intermediate f918c1ef7e60ac5e25deb232838dc8c14a3b995e.intermediate 5402e94e215186eb33df16aff0cea7aca9a8f025.intermediate bda11aa586dd22c5cb705c71141e3087a79c526a.intermediate
if [ ! -r node -o ! -L node ]; then ln -fs out/Release/node node; fi
make: unrecognized option '--with-freetype-dir=/usr/include/'
make: unrecognized option '--with-webp-dir=/usr/include/'
make: unrecognized option '--with-jpeg-dir=/usr/include/'
Usage: make [options] [target] ...
Options:
-b, -m Ignored for compatibility.
-B, --always-make Unconditionally make all targets.
-C DIRECTORY, --directory=DIRECTORY
Change to DIRECTORY before doing anything.
-d Print lots of debugging information.
--debug[=FLAGS] Print various types of debugging information.
-e, --environment-overrides
Environment variables override makefiles.
--eval=STRING Evaluate STRING as a makefile statement.
-f FILE, --file=FILE, --makefile=FILE
Read FILE as a makefile.
-h, --help Print this message and exit.
-i, --ignore-errors Ignore errors from recipes.
-I DIRECTORY, --include-dir=DIRECTORY
Search DIRECTORY for included makefiles.
-j [N], --jobs[=N] Allow N jobs at once; infinite jobs with no arg.
-k, --keep-going Keep going when some targets can't be made.
-l [N], --load-average[=N], --max-load[=N]
Don't start multiple jobs unless load is below N.
-L, --check-symlink-times Use the latest mtime between symlinks and target.
-n, --just-print, --dry-run, --recon
Don't actually run any recipe; just print them.
-o FILE, --old-file=FILE, --assume-old=FILE
Consider FILE to be very old and don't remake it.
-O[TYPE], --output-sync[=TYPE]
Synchronize output of parallel jobs by TYPE.
-p, --print-data-base Print make's internal database.
-q, --question Run no recipe; exit status says if up to date.
-r, --no-builtin-rules Disable the built-in implicit rules.
-R, --no-builtin-variables Disable the built-in variable settings.
-s, --silent, --quiet Don't echo recipes.
-S, --no-keep-going, --stop
Turns off -k.
-t, --touch Touch targets instead of remaking them.
--trace Print tracing information.
-v, --version Print the version number of make and exit.
-w, --print-directory Print the current directory.
--no-print-directory Turn off -w, even if it was turned on implicitly.
-W FILE, --what-if=FILE, --new-file=FILE, --assume-new=FILE
Consider FILE to be infinitely new.
--warn-undefined-variables Warn when an undefined variable is referenced.
This program built for x86_64-pc-linux-gnu
Report bugs to <bug-make#gnu.org>
ERROR: Service 'web' failed to build: The command '/bin/sh -c apt-get update && apt-get install -y python libfreetype6-dev libwebp-dev libjpeg62-turbo-dev libpng-dev nano git-core curl build-essent
ial openssl libssl-dev libgmp-dev libldap2-dev netcat sqlite3 libsqlite3-dev && git clone https://github.com/nodejs/node.git && cd node && ./configure && make && make install docke
r-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-webp-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && docker-php-ext-install gd pdo pdo_mysql pdo_sqlite zip gmp bcmath pcntl ldap sysvmsg exif && a2enmod rewrite' re
turned a non-zero code: 2
docker-compose.yml :
version: '3.1'
services:
web:
build:
context: ./web
dockerfile: Dockerfile.yml
environment:
- APACHE_RUN_USER=www-data
volumes:
- ${APP_PATH_HOST}:${APP_PTH_CONTAINER}
ports:
- 8081:80
working_dir: ${APP_PTH_CONTAINER}
db:
image: mysql:5.7.24
restart: always
environment:
MYSQL_ROOT_PASSWORD: 1
volumes:
- ${DB_PATH_HOST}:/var/lib/mysql
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 8082:80
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: 1
composer:
image: composer:1.8
volumes:
- ${APP_PATH_HOST}:${APP_PTH_CONTAINER}
working_dir: ${APP_PTH_CONTAINER}
command: composer install --ignore-platform-reqs
web/Dockerfile.yml :
FROM php:7.2-apache
RUN apt-get update && \
apt-get install -y \
python \
libfreetype6-dev \
libwebp-dev \
libjpeg62-turbo-dev \
libpng-dev \
nano \
git-core \
curl \
build-essential \
openssl \
libssl-dev \
libgmp-dev \
libldap2-dev \
netcat \
sqlite3 \
libsqlite3-dev \
&& git clone https://github.com/nodejs/node.git \
&& cd node \
&& ./configure \
&& make \
&& make install \
docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-webp-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && \
docker-php-ext-install gd pdo pdo_mysql pdo_sqlite zip gmp bcmath pcntl ldap sysvmsg exif \
&& a2enmod rewrite
COPY virtualhost.conf /etc/apache2/sites-enabled/000-default.conf
Why error? Is something is not installed on my hosting Kubuntu 18 ?
It seems to me that this project was working ok before reinstall of Kubuntu 18 ...
Old
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/
New
RUN docker-php-ext-configure gd --with-freetype=/usr/include/
N.B: You neet just to remove -dir
Charles Duffy, thanks!
That was misspelling from my side. I splitted web/Dockerfile.yml into 3 parts :
FROM php:7.2-apache
RUN apt-get update && \
apt-get install -y \
python \
libfreetype6-dev \
libwebp-dev \
libjpeg62-turbo-dev \
libpng-dev \
nano \
git-core \
curl \
build-essential \
openssl \
libssl-dev \
libgmp-dev \
libldap2-dev \
netcat \
sqlite3 \
libsqlite3-dev \
&& git clone https://github.com/nodejs/node.git \
&& cd node \
&& ./configure \
&& make \
&& make install
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-webp-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install gd pdo pdo_mysql pdo_sqlite zip gmp bcmath pcntl ldap sysvmsg exif \
&& a2enmod rewrite
COPY virtualhost.conf /etc/apache2/sites-enabled/000-default.conf
and it was complied ok !

docker The DSN string could not be parsed with CakePHP

I'm configuring CakePHP application with Docker.
I'm new to Docker and this is my first docker-compose.
Dockerfile
FROM php:7.2-apache
LABEL maintainer="Anuj Sharma <contact#anujsh.in>"
# Enable Apache Rewrite + Expires Module
RUN a2enmod rewrite expires
# Install dependencies
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libyaml-dev \
zlib1g-dev \
libicu-dev \
libpq-dev \
libmcrypt-dev \
mysql-client \
g++ \
git \
libzip-dev \
zip \
unzip \
&& rm -r /var/lib/apt/lists/* \
&& pecl install mcrypt-1.0.1 \
&& docker-php-ext-install opcache \
&& docker-php-ext-configure intl \
&& docker-php-ext-install intl \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install zip \
&& docker-php-ext-configure pdo_mysql --with-pdo-mysql=mysqlnd \
&& docker-php-ext-install -j$(nproc) gd \
&& docker-php-ext-install mbstring pcntl pdo_mysql pdo_pgsql pgsql \
&& docker-php-ext-enable mcrypt \
&& docker-php-ext-enable intl
# Install composer
#RUN curl -sS https://getcomposer.org/installer | php -- --install -dir=/usr/bin/ --filename=composer
RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer
# set recommended PHP.ini settings
# see https://secure.php.net/manual/en/opcache.installation.php
RUN { \
echo 'opcache.memory_consumption=128'; \
echo 'opcache.interned_strings_buffer=8'; \
echo 'opcache.max_accelerated_files=4000'; \
echo 'opcache.revalidate_freq=2'; \
echo 'opcache.fast_shutdown=1'; \
echo 'opcache.enable_cli=1'; \
echo 'upload_max_filesize=128M'; \
echo 'post_max_size=128M'; \
echo 'extension=intl.so'; \
} > /usr/local/etc/php/conf.d/php-recommended.ini
RUN pecl install apcu \
&& pecl install yaml \
&& docker-php-ext-enable apcu yaml
# Set our application folder as an environment variable
ENV APP_HOME /var/www/html
# Change uid and gid of apache to docker user uid/gid
RUN usermod -u 1000 www-data && groupmod -g 1000 www-data
# Change the web_root to cakephp /var/www/html/webroot folder
RUN sed -i -e "s/html/html\/webroot/g" /etc/apache2/sites-enabled/000-default.conf
# Copy source files and run composer
COPY . $APP_HOME
# Install all PHP dependencies
RUN composer install --no-interaction
# Change ownership of our applications
RUN chown -R www-data:www-data $APP_HOME
NOTE: I have copied commands from different sources to generate above Dockerfile.
docker-compose.yml
version: "3.1"
# Define all services
services:
# Our service is called CakePHP ;-)
cakephp:
# We want to use the image which is build from our Dockerfile
build: .
# Apache is running on port 80 but we want to expose this to port 4000 on our local machine
ports:
- "4000:80"
# We depending on the mysql backend
depends_on:
- mysql
volumes:
- .:/var/www/html/
environment:
- SECURITY_SALT=070q78he40qfw475q0q7v0wt7vfqw7vw87qw8dpowe7rfpwq437
- DATABASE_URL=mysql
- MYSQL_USERNAME=root
- MYSQL_PASSWORD=root
- MYSQL_DATABASE=cakephp
mysql:
# We use the mysql base image, version 5.7
image: mysql:5.7
# We mount a datavolume to make sure we don't loose data
volumes:
- cap_mysql_data:/var/lib/mysql
# Setting some env vars to create the DB
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=cakephp
volumes:
cap_mysql_data:
When I run
docker-compose build
It all goes well. But when I run to migrate the migrations
docker-compose run cakephp bin/cake migrations migrate
It gives error as
Exception: The DSN string 'mysql' could not be parsed. in [/var/www/html/vendor/cakephp/cakephp/src/Core/StaticConfigTrait.php, line 292]
The app.php file of CakePHP have configuration for datasource
'username' => env('MYSQL_USERNAME', 'root'),
'password' => env('MYSQL_PASSWORD', ''),
'database' => env('MYSQL_DATABASE', 'cakephp'),
'url' => env('DATABASE_URL', null),
The DATABASE_URL environment variable is expected to hold a DSN (data source name) string, mysql isn't such a string, this is what a DSN looks like:
mysql://user:pass#localhost:3306/database?encoding=utf8&timezone=UTC&cacheMetadata=true
The parts are basically as follows:
<driver>://<username>:<password>#<host>:<port>/<database>?<options>
If you don't actually want to use a DSN, then do not specify the DATABASE_URL variable.
See also
Cookbook > Database Access & ORM > Database Basics > Configuration
API > \Cake\Datasource\ConnectionManager::parseDsn()

Build Project inside docker container and share folder in mounted

I use docker-compose to build my containers and on a state I checkout private repository and I build the project inside container with composer.
I have the following structure
- docker-project
-- docker //here I keep the containers
--- apache
---- Dockerfile // the content what I posted
-- docker-compose.yml
-- src //this is the mounted folder where I can work on project
After build I would expect that the build project would show up in the mounted folder but instead I get empty folders here is my compose yml
apache:
container_name: apache2
build:
context: ./docker/apache
ports:
- 80:80
- 443:443
links:
- database
restart: always
volumes:
- ./src:/var/www/
- ./docker/logs/apache2/:/var/log/apache2/
- ~/.ssh/id_rsa:/root/.ssh/id_rsa
- ./docker/apache/sites/:/etc/apache2/sites-enabled
and here I have the docker file
FROM php:7.1-apache
ENV APACHE_DOCUMENT_ROOT /var/www
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
curl \
openssl \
openssh-server \
sendmail \
sendmail-bin \
mailutils \
libicu-dev \
libmemcached-dev \
libz-dev \
libpq-dev \
libjpeg-dev \
libfreetype6-dev \
libssl-dev \
libmcrypt-dev \
libxml2-dev \
libbz2-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
zlib1g-dev \
libicu-dev \
g++ \
libxml2-dev \
git \
&& rm -rf /var/lib/apt/lists/*
# Install various PHP extensions which are required to build project
RUN docker-php-ext-configure bcmath --enable-bcmath \
&& docker-php-ext-configure pcntl --enable-pcntl \
&& docker-php-ext-configure pdo_mysql --with-pdo-mysql \
&& docker-php-ext-configure pdo_pgsql --with-pgsql \
&& docker-php-ext-configure mbstring --enable-mbstring \
&& docker-php-ext-configure soap --enable-soap \
&& docker-php-ext-install \
bcmath \
json \
intl \
mbstring \
mcrypt \
mysqli \
pcntl \
pdo_mysql \
pdo_pgsql \
soap \
sockets \
zip \
&& docker-php-ext-configure gd \
--enable-gd-native-ttf \
--with-jpeg-dir=/usr/lib \
--with-freetype-dir=/usr/include/freetype2 && \
docker-php-ext-install gd
##install xdebug and enable it. We need this for php unit coverage
RUN yes | pecl install xdebug \
&& docker-php-ext-enable xdebug
RUN yes | pecl install mongodb \
&& docker-php-ext-enable mongodb
RUN update-ca-certificates
# install composer to can install dependencies
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer \
&& php -r "unlink('composer-setup.php');"
RUN mkdir /root/.ssh
RUN rm -rf /var/www/project
WORKDIR /var/www/
RUN git checkout path/to/repo
RUN ls -l /var/www
WORKDIR /repo
RUN composer install
RUN ls -l
on docker-compose build I see that the project will be builded but on
docker-compose upthe folder is empty
What I'm missing in this case?
You are mounting a volume on /var/www when starting the container.
/var/www will be the same as ./src/www on the host machine, replacing anything that was added to /var/www during the build of the image.
Consider using the composer docker image or make sure to install the dependencies to another directory. Check out the vendor_dir key in composer.json
Example:
composer.json
{
"require": {
},
"config": {
"vendor-dir": "/var/www/vendor/"
}
}
Docker image build:
...
RUN mkdir -p /var/www/vendor/
COPY composer.json /var/www/vendor/
RUN cd /var/www/vendor/ && composer install
RUN mkidr -p /var/www/app
...
docker-compose.yml
volumes:
- ./src:/var/www/app
I could give a way of currently we are working. Rather cloning the repo like this what we do, we clone the repo in the local machine.
You have standard docker image that you have created from
php:7.1-apache with required softwares that you need to run the project.
Then you clone your project to you host machine.(think into src folder)
You run the composer install locally.
Then as you have defined the docker-compose.yml mount your src folder into /var/www/

Resources