When I want to rebuild docker image it generates an error - docker

I made docker images and built them using docker-compose.yml, everything works fine for the first time but when I add/update some configurations on the Dockerfiles and rebuild the images an error regarding the group or the user I am creating inside the image generates:
> [ 2/11] RUN addgroup -g 1000 laravel && adduser -G laravel -g laravel -s /bin/sh -D laravel:
#5 0.396 addgroup: group 'laravel' in use
Here I am adding laravel as user and group.
The only work around I make is to delete all the built images: docker system prune -a
Below are Docker files and docker-compose.yml file configuration:
.env file:
PROJECT_NAME=myproject
DEV_DOMAIN=docker.local
USERNAME=laravel
UID=1000
PHP_VERSION=7.4-fpm-alpine
MYSQL_VERSION=latest
MYSQL_DATABASE=local_db
MYSQL_USER=homestead
MYSQL_PASSWORD=secret
XDEBUG_REMOTE_HOST=172.31.33.213
XDEBUG_IDE_KEY=VSCODE
XDEBUG_PORT=7765
docker-compose.yml:
version: "3.5"
services:
nginx:
build:
args:
user: ${USERNAME}
uid: ${UID}
context: .
dockerfile: ./docker/nginx/Dockerfile
image: "nginx:stable-alpine"
container_name: ${PROJECT_NAME}-nginx
ports:
- 80:80
volumes:
- "./code:/var/www/html"
- "./docker/nginx/vhost:/etc/nginx/conf.d/default.conf"
- "./docker/nginx/nginx.conf:/etc/nginx/nginx.conf"
depends_on:
- php
- mysql
networks:
- devproject
php:
build:
args:
PHP_VERSION: ${PHP_VERSION}
user: ${USERNAME}
uid: ${UID}
XDEBUG_REMOTE_HOST: ${XDEBUG_REMOTE_HOST}
XDEBUG_IDE_KEY: ${XDEBUG_IDE_KEY}
XDEBUG_PORT: ${XDEBUG_PORT}
context: .
dockerfile: ./docker/php/Dockerfile
image: php:${PHP_VERSION}
container_name: ${PROJECT_NAME}-php
volumes:
- "./code:/var/www/html"
- "./docker/php/www.conf:/usr/local/etc/php-fpm.d/www.conf"
ports:
- 9000:9000
networks:
- devproject
mysql:
image: mysql:${MYSQL_VERSION}
container_name: ${PROJECT_NAME}-mysql
restart: unless-stopped
tty: true
ports:
- 3306:3306
environment:
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_ROOT_PASSWORD: ${MYSQL_PASSWORD}
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- devprojectmysql:/var/lib/mysql
networks:
- devproject
networks:
devproject:
driver: bridge
volumes:
devprojectmysql:
driver: local
docker/php/Dockerfile:
ARG PHP_VERSION
FROM php:$PHP_VERSION
ARG XDEBUG_REMOTE_HOST
ARG XDEBUG_IDE_KEY
ARG XDEBUG_PORT
ARG user
ARG uid
ENV XDEBUG_REMOTE_HOST $XDEBUG_REMOTE_HOST
ENV XDEBUG_IDE_KEY $XDEBUG_IDE_KEY
ENV XDEBUG_PORT $XDEBUG_PORT
RUN addgroup -g $uid $user && adduser -G $user -g $user -s /bin/sh -D $user
RUN mkdir -p /var/www/html
RUN chown $user:$user /var/www/html
WORKDIR /var/www/html
RUN apk add --no-cache --update icu-dev gettext gettext-dev git curl libpng-dev libzip-dev \
libmcrypt-dev libpng-dev libjpeg-turbo-dev libxml2-dev icu-dev postgresql-dev curl-dev \
libmemcached-dev build-base autoconf zip unzip oniguruma-dev &&\
apk add --update --virtual build-dependencies build-base gcc wget autoconf
RUN pecl install xdebug-3.0.4
RUN docker-php-ext-install gd ctype fileinfo mysqli pdo pdo_mysql mbstring exif pcntl bcmath xml curl json intl gettext tokenizer zip simplexml
RUN docker-php-ext-configure intl &&\
docker-php-ext-configure gettext &&\
docker-php-ext-enable xdebug
RUN apk del build-dependencies &&\
rm -rf /var/cache/apk/* &&\
rm -rf /var/lib/apt/lists/*
RUN echo "xdebug.remote_autostart=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_handler=dbgp" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_connect_back=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_log=/tmp/xdebug_remote.log" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_port=$XDEBUG_PORT" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.idekey=$XDEBUG_IDE_KEY" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_host=$XDEBUG_REMOTE_HOST" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
docker/nginx/Dockerfile:
FROM nginx:stable-alpine
# Arguments defined in docker-compose.yml
ARG user
ARG uid
RUN mkdir -p /var/www/html
RUN addgroup -g $uid $user && adduser -G $user -g $user -s /bin/sh -D $user
RUN chown $user:$user /var/www/html

The image field in the compose file, e.g.
image: php:${PHP_VERSION}
Is the image you are creating. You have named your created images the same as your base images in the Dockerfile, overwriting the upstream names. This is a bug in your compose file, and confusing to others since running an image with that name does different things depending on whether you pull the upstream image or run your locally built image.
Instead your compose file should name images with something in your own registry namespace to avoid collisions. In Hub that involves prepending your Hub username:
image: <hubuser>/<appname>:<tag>

Related

Database is not created on docker compose up -d

I'm following the docs of mariadb. It says that the db should be created if it find a .sql in /docker-entrypoint-initdb.d.
I'm working on a Ubuntu Server in a Oracle Virtual BOX VM.
My docker-compose.yml looks like this:
version: "3.9"
services:
db:
image: mariadb:10
container_name: mariadb
ports:
- 3306:3306
environment:
- MYSQL_USER=user
- MYSQL_ROOT_PASSWORD=password
- MYSQL_PASSWORD=password
- MARIADB_DATABASE=database // tried with MYSQL_DATABASE and without this line
volumes:
- "db_data:/var/lib/mysql"
- ".database/initdb/dump.sql:/docker-entrypoint-initdb.d/initdb.sql"
# networks:
# - network
volumes:
db_data:
My initdb.sql looks like this (the one that should work in the end looks different but out of simplicity I reduced it to the max and could not even this simple one working):
CREATE DATABASE NEWDB;
I honestly don't know where to look or what to do now because everywhere I looked for a possible solution I found that this is the bare minimum example that should work.
I tried to restarted docker, deleted all containers, images and volumes, modified the initdb.sql into:
CREATE USER user WITH PASSWORD 'password';
CREATE DATABASE IF NOT EXISTS database;
GRANT ALL PRIVILEGES ON DATABASE database TO user;
but the database is not initialized when I docker compose up.
I looked up the container and the initdb.sql was there.
EDIT: It somehow worked, when I docker compose up with MARIADB_DATABASE=database but the script initdb.sql still doesn't work and it's the most important thing because it set's up the whole database.
(NOTE: On top of that I want to set up another PHP-container that runs a PHP-script in order to collect data that is being stored in the above MariaDB-container. The MariaDB is connected with a website that calls data from the container)
Well I'm using the following stack and it works fine for me.
php-apache:
This is an Apache server that runs all my php scripts. You can place your scripts in ./src directory and it will automatically be mounted to DocumentRoot directory of the Apache server.
db:
This the latest docker container of MariaDb
adminer:
This is the lite-weight database browser which I use for creating and altering my databases. You can just visit localhost:8081 and then enter the following credentials. It becomes simpler to manage the databases this way.
username: root
password: example
version: '3.8'
services:
php-apache:
container_name: php-apache
build:
context: .
dockerfile: Dockerfile
image: php:8.0-apache
volumes:
- ./src:/var/www/html/
ports:
- 8080:80
db:
image: mariadb
restart: always
environment:
MARIADB_ROOT_PASSWORD: example
adminer:
image: adminer
restart: always
ports:
- 8081:8080
Dockerfile:
This is a simple docker container which is extended from the base php:8.0-apache image, with mysql extensions installed in it for PDO support.
FROM php:8.0-apache
RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
RUN apt-get update && apt-get upgrade -y
P.S:
Here you'll have to create all your databases manually via GUI of Adminer. But if you prefer SQL queries via initdb.sql then be my guest. I've just provided this configuration as a suggestion.
I came up with a solution. I used a base image of laravel (installed the laravel project with <curl -s "https://laravel.build/project-name?with=mariadb" | sudo bash> and modified it a little bit. So here's the docker-compose.yml:
# For more information: https://laravel.com/docs/sail
version: '3'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.1
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
image: sail-8.1/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '${APP_PORT:-80}:80'
- '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
volumes:
- '.:/var/www/html'
networks:
- sail
depends_on:
- mariadb
mariadb:
image: 'mariadb:10'
container_name: 'mariadb-10'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_ROOT_HOST: "%"
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
volumes:
- 'sail-mariadb:/var/lib/mysql'
- './vendor/laravel/sail/database/mysql/create-testing-database.sh:/docker-entrypoint-initdb.d/10-create-testing-database.sh'
networks:
- sail
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}"]
retries: 3
timeout: 5s
networks:
sail:
driver: bridge
volumes:
sail-mariadb:
driver: local
Here you can see that the "10-create-testing-database.sh" is executed on startup. I tested this container and it created a database, so I just had to modify it a little bit and now the container creates a database and tables on container startup. Here's the "10-create-testing-database.sh":
#!/usr/bin/env bash
mysql --user=root --password="$MYSQL_ROOT_PASSWORD" <<-EOSQL
CREATE DATABASE IF NOT EXISTS database_name;
GRANT ALL PRIVILEGES ON \`testing%\`.* TO '$MYSQL_USER'#'%';
USE database_name;
CREATE TABLE IF NOT EXISTS table_name(
table_entries ...
);
EOSQL
I still don't know why my initial setup did not work. The only difference I see is that this working file is a .sh and the not working one is a .sql (this does not make sence to me but it what it is).
Dockerfile:
FROM ubuntu:22.04
LABEL maintainer="Taylor Otwell"
ARG WWWGROUP
ARG NODE_VERSION=16
ARG POSTGRES_VERSION=14
WORKDIR /var/www/html
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update \
&& apt-get install -y gnupg gosu curl ca-certificates zip unzip git supervisor sqlite3 libcap2-bin libpng-dev python2 \
&& mkdir -p ~/.gnupg \
&& chmod 600 ~/.gnupg \
&& echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \
&& echo "keyserver hkp://keyserver.ubuntu.com:80" >> ~/.gnupg/dirmngr.conf \
&& gpg --recv-key 0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c \
&& gpg --export 0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c > /usr/share/keyrings/ppa_ondrej_php.gpg \
&& echo "deb [signed-by=/usr/share/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
&& apt-get update \
&& apt-get install -y php8.1-cli php8.1-dev \
php8.1-pgsql php8.1-sqlite3 php8.1-gd \
php8.1-curl \
php8.1-imap php8.1-mysql php8.1-mbstring \
php8.1-xml php8.1-zip php8.1-bcmath php8.1-soap \
php8.1-intl php8.1-readline \
php8.1-ldap \
php8.1-msgpack php8.1-igbinary php8.1-redis php8.1-swoole \
php8.1-memcached php8.1-pcov php8.1-xdebug \
&& php -r "readfile('https://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& curl -sLS https://deb.nodesource.com/setup_$NODE_VERSION.x | bash - \
&& apt-get install -y nodejs \
&& npm install -g npm \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /usr/share/keyrings/yarn.gpg >/dev/null \
&& echo "deb [signed-by=/usr/share/keyrings/yarn.gpg] https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
&& curl -sS https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /usr/share/keyrings/pgdg.gpg >/dev/null \
&& echo "deb [signed-by=/usr/share/keyrings/pgdg.gpg] http://apt.postgresql.org/pub/repos/apt jammy-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
&& apt-get update \
&& apt-get install -y yarn \
&& apt-get install -y mysql-client \
&& apt-get install -y postgresql-client-$POSTGRES_VERSION \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN setcap "cap_net_bind_service=+ep" /usr/bin/php8.1
RUN groupadd --force -g $WWWGROUP sail
RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail
COPY start-container /usr/local/bin/start-container
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY php.ini /etc/php/8.1/cli/conf.d/99-sail.ini
RUN chmod +x /usr/local/bin/start-container
EXPOSE 8000
ENTRYPOINT ["start-container"]

Docker sync files

im not familiar with docker at all. im trying to use symfony with docker (windows). for docker i use (without changes, only +mysql)
https://github.com/dunglas/symfony-docker
it works well
problem that when i change files or create new files changes not sync, only after new build.
Please tell how to write proper dockerfile so files from host (and from docker) will be in sync
i need to use docker volumes, but idk how 😁
dockerfile
ARG PHP_VERSION=8.1
ARG CADDY_VERSION=2
# "php" stage
FROM php:${PHP_VERSION}-fpm-alpine AS symfony_php
# persistent / runtime deps
RUN apk add --no-cache \
acl \
fcgi \
file \
gettext \
git \
;
ARG APCU_VERSION=5.1.21
RUN set -eux; \
apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
icu-data-full \
icu-dev \
libzip-dev \
zlib-dev \
; \
\
docker-php-ext-configure zip; \
docker-php-ext-install -j$(nproc) \
intl \
zip \
; \
pecl install \
apcu-${APCU_VERSION} \
; \
pecl clear-cache; \
docker-php-ext-enable \
apcu \
opcache \
; \
\
runDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
| tr ',' '\n' \
| sort -u \
| awk 'system("[ -e /usr/local/lib/" $1 " ]") == 0 { next } { print "so:" $1 }' \
)"; \
apk add --no-cache --virtual .phpexts-rundeps $runDeps; \
\
apk del .build-deps
RUN docker-php-ext-install mysqli pdo pdo_mysql && docker-php-ext-enable pdo_mysql
COPY docker/php/docker-healthcheck.sh /usr/local/bin/docker-healthcheck
RUN chmod +x /usr/local/bin/docker-healthcheck
HEALTHCHECK --interval=10s --timeout=3s --retries=3 CMD ["docker-healthcheck"]
RUN ln -s $PHP_INI_DIR/php.ini-production $PHP_INI_DIR/php.ini
COPY docker/php/conf.d/symfony.prod.ini $PHP_INI_DIR/conf.d/symfony.ini
COPY docker/php/php-fpm.d/zz-docker.conf /usr/local/etc/php-fpm.d/zz-docker.conf
COPY docker/php/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
RUN chmod +x /usr/local/bin/docker-entrypoint
VOLUME /var/run/php
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER=1
ENV PATH="${PATH}:/root/.composer/vendor/bin"
WORKDIR /srv/app
# Allow to choose skeleton
ARG SKELETON="symfony/skeleton"
ENV SKELETON ${SKELETON}
# Allow to use development versions of Symfony
ARG STABILITY="stable"
ENV STABILITY ${STABILITY}
# Allow to select skeleton version
ARG SYMFONY_VERSION=""
ENV SYMFONY_VERSION ${SYMFONY_VERSION}
# Download the Symfony skeleton and leverage Docker cache layers
#RUN composer create-project "${SKELETON} ${SYMFONY_VERSION}" . --stability=$STABILITY --prefer-dist --no-dev --no-progress --no-interaction; \
# composer clear-cache
###> recipes ###
###> doctrine/doctrine-bundle ###
#RUN apk add --no-cache --virtual .pgsql-deps postgresql-dev; \
# docker-php-ext-install -j$(nproc) pdo_pgsql; \
# apk add --no-cache --virtual .pgsql-rundeps so:libpq.so.5; \
# apk del .pgsql-deps
###< doctrine/doctrine-bundle ###
###< recipes ###
COPY . .
RUN set -eux; \
mkdir -p var/cache var/log; \
composer install --prefer-dist --no-dev --no-progress --no-scripts --no-interaction; \
composer dump-autoload --classmap-authoritative --no-dev; \
composer symfony:dump-env prod; \
composer run-script --no-dev post-install-cmd; \
chmod +x bin/console; sync
VOLUME /srv/app/var
ENTRYPOINT ["docker-entrypoint"]
CMD ["php-fpm"]
FROM caddy:${CADDY_VERSION}-builder-alpine AS symfony_caddy_builder
RUN xcaddy build \
--with github.com/dunglas/mercure \
--with github.com/dunglas/mercure/caddy \
--with github.com/dunglas/vulcain \
--with github.com/dunglas/vulcain/caddy
FROM caddy:${CADDY_VERSION} AS symfony_caddy
WORKDIR /srv/app
COPY --from=dunglas/mercure:v0.11 /srv/public /srv/mercure-assets/
COPY --from=symfony_caddy_builder /usr/bin/caddy /usr/bin/caddy
COPY --from=symfony_php /srv/app/public public/
COPY docker/caddy/Caddyfile /etc/caddy/Caddyfile
docker-compose
version: "3.4"
services:
db:
image: mysql
# NOTE: use of "mysql_native_password" is not recommended: https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password
# (this is just an example, not intended to be a production configuration)
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
adminer:
image: adminer
restart: always
ports:
- 8080:8080
php:
build:
context: .
target: symfony_php
args:
SYMFONY_VERSION: ${SYMFONY_VERSION:-}
SKELETON: ${SKELETON:-symfony/skeleton}
STABILITY: ${STABILITY:-stable}
restart: unless-stopped
volumes:
- php_socket:/var/run/php
healthcheck:
interval: 10s
timeout: 3s
retries: 3
start_period: 30s
environment:
MERCURE_URL: ${CADDY_MERCURE_URL:-http://caddy/.well-known/mercure}
MERCURE_PUBLIC_URL: https://${SERVER_NAME:-localhost}/.well-known/mercure
MERCURE_JWT_SECRET: ${CADDY_MERCURE_JWT_SECRET:-!ChangeMe!}
caddy:
build:
context: .
target: symfony_caddy
depends_on:
- php
environment:
SERVER_NAME: ${SERVER_NAME:-localhost, caddy:80}
MERCURE_PUBLISHER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET:-!ChangeMe!}
MERCURE_SUBSCRIBER_JWT_KEY: ${CADDY_MERCURE_JWT_SECRET:-!ChangeMe!}
restart: unless-stopped
volumes:
- php_socket:/var/run/php
- caddy_data:/data
- caddy_config:/config
ports:
# HTTP
- target: 80
published: ${HTTP_PORT:-80}
protocol: tcp
# HTTPS
- target: 443
published: ${HTTPS_PORT:-443}
protocol: tcp
# HTTP/3
- target: 443
published: ${HTTP3_PORT:-443}
protocol: udp
volumes:
php_socket:
caddy_data:
caddy_config:
This is not something you declare on the dockerfile level, the dockerfile is a layer you tell the container (or the host) to add the container in it's run time. (Installations, copies..)
this a flag on the docker API `docker run -v vol:vol .... ```
Or inside of the docker-compose file
I see your docker-compose file has a declaration of volumes for service caddy.
Try to init the volume as an empty one
# bottom of the docker-compose file
volumes:
php_socket: {}
Docker is built upon layers, every change you'll make, will create a new layer and will be saved on the volume.

Docker-compose "no such service"

I have an error launching docker-compose up -d with this docker-compose.yml file: no such service: php-c
It used to work and I didn't change anything. I didn't have any docker update in the meantime either.
If I remove container_name key then I have the same error displayed with the name which is auto-generated.
I am using wsl2 and docker 20.10.8.
version: '3'
services:
db:
image: mysql:5.7
container_name: db-c
ports:
- 3307:3306
volumes:
- "./.data/db:/var/lib/mysql"
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
php:
build:
context: php7-fpm
args:
TIMEZONE: ${TIMEZONE}
username: ${username}
container_name: php-c
volumes:
- ${SYMFONY_APP_PATH}:/var/www/symfony
- ./logs/symfony/:/var/www/symfony/var/logs
environment:
- XDEBUG_REMOTE_HOST=host.docker.internal
- PHP_IDE_CONFIG=serverName=symfony.local
user: 1000:1000
nginx:
build: nginx
container_name: nginx-c
ports:
- 80:80
volumes_from:
- php
volumes:
- ./logs/nginx/:/var/log/nginx
Here is the Dockerfile.
# See https://github.com/docker-library/php/blob/master/7.1/fpm/Dockerfile
FROM php:7.3-fpm
ARG TIMEZONE
ARG username=bastien
MAINTAINER Maxence POUTORD <maxence.poutord#gmail.com>
RUN apt-get update && apt-get install -y \
openssl \
git \
unzip \
libicu-dev \
sudo \
lsof \
zlib1g-dev \
libzip-dev \
iputils-ping
# Install GD
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version
# Set timezone
RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone
RUN printf '[PHP]\ndate.timezone = "%s"\n', ${TIMEZONE} > /usr/local/etc/php/conf.d/tzone.ini
RUN "date"
# Type docker-php-ext-install to see available extensions
RUN docker-php-ext-install pdo pdo_mysql zip
# install xdebug
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug
RUN cd /usr/local/etc/php/conf.d/ && \
echo 'memory_limit = 1G' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini
COPY xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
#RUN echo "error_reporting = E_ALL" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
# & echo "display_startup_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
# & echo "display_errors = On" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
# & echo "xdebug.remote_enable=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
# & echo "xdebug.remote_connect_back=1" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
# & echo "xdebug.idekey=\"PHPSTORM\"" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
# & echo "xdebug.remote_port=9001" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
# CREATE USER FOR $username
RUN useradd --create-home --shell /bin/bash -u 1000 $username
USER $username
RUN mkdir /home/$username/.ssh \
&& chmod 700 /home/$username/.ssh
COPY .bashrc /home/$username/.bashrc
COPY config /home/$username/.ssh/config
WORKDIR /var/www/symfony
[EDIT]
When I use restart, this works... I really don't understand what's going on.
docker-compose restart
I had the same problem.
It seems that the volumes_from configuration is the source of the problem. (might be a docker-compose bug)
Replacing volumes_from with volumes did the trick for me.
Try to use the following for your nginx service configuration:
nginx:
build: nginx
container_name: nginx-c
ports:
- 80:80
volumes:
- ${SYMFONY_APP_PATH}:/var/www/symfony
- ./logs/symfony/:/var/www/symfony/var/logs
- ./logs/nginx/:/var/log/nginx
[EDIT] : better answer
Please : replace php7-form by ./php7-form
context: ./php7-fpm
it worked for me locally using docker-compose up --build with the following example:
version: '3'
services:
php:
build:
context: ./php7-form
environment:
- XDEBUG_REMOTE_HOST=host.docker.internal
- PHP_IDE_CONFIG=serverName=symfony.local
user: 1000:1000
[previous answer]
At the moment no image exists for your service.
You don't have an image in the "php" service.
you need to add an image in your docker-compose file bellow php: as you did for your db service :
php:
image: <your_image_name>
Btw you will have the same problem with the nginx service...

Container up and running - unable to serve files in web-browser - Docker

My container is up an running successfully - i'm on a MacOS Catalina;
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
487b211c7300 laravel-demo_laravel-app "docker-php-entrypoi…" 6 seconds ago Up 5 seconds 9000/tcp, 9021/tcp, 0.0.0.0:8021->80/tcp laravel-app
My docker-compose.yml looks like;
version: '3'
services:
#Laravel App
laravel-app:
build:
context: .
dockerfile: ./Dockerfile
container_name: laravel-app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: laravel-app
SERVICE_TAGS: dev
working_dir: /var/www/html
ports:
- 8021:80
volumes:
- ./:/var/www/html
and my Dockerfile
FROM php:7.2-fpm-alpine
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/html/
# Set working directory
WORKDIR /var/www/html
# Install Additional dependencies
RUN apk update && apk add --no-cache \
build-base shadow vim curl \
php7 \
php7-fpm \
php7-common \
php7-pdo \
php7-pdo_mysql \
php7-mysqli \
php7-mcrypt \
php7-mbstring \
php7-xml \
php7-openssl \
php7-json \
php7-phar \
php7-zip \
php7-gd \
php7-dom \
php7-session \
php7-zlib
# Add and Enable PHP-PDO Extenstions
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-enable pdo_mysql
# Install PHP Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --
filename=composer
# Remove Cache
RUN rm -rf /var/cache/apk/*
# Add UID '1000' to www-data
RUN usermod -u 1000 www-data
RUN usermod -u 501 www-data
# Copy existing application directory permissions
COPY --chown=www-data:www-data . /var/www/html
# Change current user to www
USER www-data
These two files are both on the root of my fresh Laravel install.
Internal/external ports look fine in my config and with docker ps reporting success - my app should launch in a browser no? In theory - I should see the Laravel splash-screen;-
Well, unfortunately it doesn't and it's kicking my ass.
Things I've tried;
EXPOSE 9000
CMD ["php-fpm", "--host", "http://localhost"]
and
#CMD ["php-fpm", "--host", "0.0.0.0"]
Plus, various implementations of docker-compose.yml - like removing the environment: parameter - but no joy.
By comparing my Dockerfile & docker-compose.yml - are you able to offer some clues?
Thanks
If you cant beat em - join em;-
https://hub.docker.com/r/bitnami/laravel

docker-compose: How can I pass ARG as variable to docker-compose?

I have this docker-compose file
version: "3.7"
services:
develop:
build:
args:
user: sineverba
uid: 1000
context: ./
container_name: tpaw-develop
image: tpaw-develop:0.1.0
volumes:
- ./:/home/sineverba/app
networks:
- develop-tpaw
networks:
develop-tpaw:
driver: bridge
I can launch it with docker-compose run --rm develop.
I want pass that args as variable from docker-compose command and not hard-coding it.
Is it possible?
I did try with
version: "3.7"
services:
develop:
build:
args:
user: ${CURRENT_USER}
uid: 1000
context: ./
And launch
CURRENT_USER=$(whoami) docker-compose build app
But Docker created a container with user $user inside
PS this is the main Dockerfile
FROM php:7.4-cli
# Arguments defined in docker-compose.yml
ARG user
ARG uid
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip
# Setup PHPXDebug
RUN pecl install xdebug
RUN docker-php-ext-enable xdebug
# 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
# 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 -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
# Set working directory
#WORKDIR /var/www
WORKDIR /home/$user/app
USER $user
ENTRYPOINT /bin/bash

Resources