Docker + Windows 10 - windows

I try work with docker on Windows 10 and I have 2 problems.
First:
if i try do
Dockerfile
FROM nginx
MAINTAINER Nikita rassamakhin "nrj.tomsk#gmail.com"
COPY /nginx-conf/nginx.conf /etc/nginx/nginx.conf
COPY /nginx-conf/vhost.conf /etc/nginx/sites-available/default
RUN mkdir -p /var/www/
RUN chown -R www-data:www-data /var/www/
RUN chmod -R 755 /var/www/
and this docker-compose
fpm:
container_name: php7
image: php:7.0.2-fpm
ports:
- "9000:9000"
links:
- mysql
nginx:
container_name: nginx
build: .
restart: always
ports:
- "80:80"
- "443:443"
links:
- fpm
mysql:
container_name: mysql
image: mysql
environment:
MYSQL_ROOT_PASSWORD: root
i have 403 error on try open localhost.
if i try add app section in docker compose like this
app:
container_name: app
image: ubuntu:trusty
volumes:
- www/:/var/www
fpm:
container_name: php7
image: php:7.0.2-fpm
working_dir: "/var/www"
ports:
- "9000:9000"
links:
- mysql
volumes_from:
- app
nginx:
container_name: nginx
build: .
restart: always
ports:
- "80:80"
- "443:443"
links:
- fpm
volumes_from:
- fpm
mysql:
container_name: mysql
image: mysql
environment:
MYSQL_ROOT_PASSWORD: root
app conteiner start and exit with code 0, without logs about error.
How i can fix this? What i doing wrong?

app conteiner start and exit with code 0, without logs about error.
You need to set a command or entrypoint for the app container. The default is probably bash which exits immediately. Exit code 0 means "exited with no error".

Related

Laravel with docker on RPI - Failed to open stream: Permission denied

I am testing deployment with docker on RPI but getting "Failed to open stream: Permission denied"
I tried few solutions but none of them worked for me
Permission Denied Error using Laravel & Docker
Laravel & Docker: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied
my Dockerfile:
FROM php:8.0-fpm-alpine
RUN docker-php-ext-install pdo pdo_mysql
RUN chown -R www-data:www-data /var/www
RUN chmod -R 755 .
and docker-compose.yml
version: "3.7"
networks:
laravel:
services:
nginx:
image: nginx:stable-alpine
restart: unless-stopped
container_name: nginx
ports:
- "80:80"
volumes:
- ./:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- mariadb
networks:
- laravel
mariadb:
image: yobasystems/alpine-mariadb:latest
restart: unless-stopped
container_name: mariadb
tty: true
ports:
- "4306:3306"
volumes:
- ./mariadb:/var/lib/mariadb
environment:
MYSQL_DATABASE: laravel
MYSQL_ROOT_PASSWORD: laravel_dev
MYSQL_USER: laravel_dev
MYSQL_PASSWORD: laravel_dev
SERVICE_TAGS: dev
SERVICE_NAME: mariadb
networks:
- laravel
phpmyadmin:
image: phpmyadmin
container_name: phpmyadmin
restart: unless-stopped
ports:
- 4380:80
environment:
PMA_ARBITRARY: 1
PMA_PORT: 3306
PMA_HOST: mariadb
PMA_USER: laravel_dev
PMA_PASSWORD: laravel_dev
depends_on:
- mariadb
networks:
- laravel
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
volumes:
- ./:/var/www/html
ports:
- "9000:9000"
networks:
- laravel
composer:
image: composer:latest
container_name: composer
volumes:
- ./:/var/www/html
working_dir: /var/www/html
networks:
- laravel
npm:
image: node:current-alpine3.14
container_name: npm
volumes:
- ./:/var/www/html
working_dir: /var/www/html
entrypoint: ['npm']
networks:
- laravel
artisan:
build:
context: .
dockerfile: Dockerfile
container_name: artisan
volumes:
- ./:/var/www/html
depends_on:
- mariadb
working_dir: /var/www/html
entrypoint: ['php', '/var/www/html/artisan']
networks:
- laravel
Only thing that worked was chmod 777 on project root folder but that is not the solution i would be comfortable with using.
So i found a solution on reddit
https://www.reddit.com/r/docker/comments/hjsipd/permission_denied_with_volumes/fwoixqe/
I had to sign project folder to container user, which i found with
less /etc/passwd. In this case name of user was www-data with UID 82. And command chown -R 82:82 .

Problems dockerizing Laravel application - database hosts array is empty

I'm trying to dockerize existing Laravel + Vue.js application, however, when trying to access database getting an error:
Database hosts array is empty.
It looks like that connection fails from PHP to MYSQL (but MySQL image is running and I can connect to it from terminal). Not sure how to proceed with this. It doesn't look to me a misconfiguration. Is there a way to debug it?
Here is what I have:
docker-compose.yml:
version: '3'
networks:
backoffice:
services:
backoffice_nginx:
image: nginx:stable
container_name: backoffice_nginx
restart: unless-stopped
ports:
- "8088:80"
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- backoffice_php
networks:
- backoffice
backoffice_mysql:
image: mysql:8.0.13
container_name: backoffice_mysql
restart: unless-stopped
tty: true
ports:
- "33067:3306"
command: ['mysqld', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci', '--default-authentication-plugin=mysql_native_password']
environment:
MYSQL_DATABASE: my_db
MYSQL_USER: dbuser
MYSQL_PASSWORD: mypass
MYSQL_ROOT_PASSWORD: myrootpass
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- ./mysql/db:/var/lib/mysql
- ./mysql/conf.d:/etc/mysql/conf.d
networks:
- backoffice
backoffice_php:
build:
context: .
dockerfile: php.dockerfile
container_name: backoffice_php
restart: unless-stopped
volumes:
- ./src:/var/www/html
networks:
- backoffice
backoffice_composer:
image: composer:latest
container_name: backoffice_composer
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
depends_on:
- backoffice_php
networks:
- backoffice
backoffice_artisan:
build:
context: .
dockerfile: php.dockerfile
container_name: backoffice_artisan
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
entrypoint: ['php', '/var/www/html/artisan']
networks:
- backoffice
php.dockerfile:
FROM php:7.4-fpm
WORKDIR /var/www/html
RUN docker-php-ext-install bcmath pdo pdo_mysql
RUN pecl install -o -f redis \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable redis
DB configs part in the .env:
DB_CONNECTION=mysql
DB_HOST=backoffice_mysql
DB_PORT=3306
DB_DATABASE=my_db
DB_USERNAME=root
DB_PASSWORD=myrootpass
Here are running containers:
Any ideas?
Thanks.
You are not sharing your .env file with your container. Map your whole . Volume to the container instead of only your ./src directory.

Laravel's the composer.lock file is not updated on docker/ docker-compose

I am working on a Laravel project. I am using docker-compose/ docker as my development environment.
This is my docker-compose.yml file.
version: '3'
services:
apache:
container_name: myaneat_apache
image: webdevops/apache:ubuntu-16.04
environment:
WEB_DOCUMENT_ROOT: /var/www/public
WEB_ALIAS_DOMAIN: myan.localhost
WEB_PHP_SOCKET: php-fpm:9000
volumes: # Only shared dirs to apache (to be served)
- ./public:/var/www/public:cached
- ./storage:/var/www/storage:cached
networks:
- myaneat-network
ports:
- "80:80"
- "443:443"
php-fpm:
container_name: myaneat_php
image: jguyomard/laravel-php:7.3
volumes:
- ./:/var/www/
- ./ci:/var/www/ci:cached
- ./vendor:/var/www/vendor:delegated
- ./storage:/var/www/storage:delegated
- ./node_modules:/var/www/node_modules:cached
- ~/.ssh:/root/.ssh:cached
- ./composer.json:/var/www/composer.json
- ./composer.json:/var/www/composer.lock
- ~/.composer/cache:/root/.composer/cache:delegated
networks:
- myaneat-network
db:
container_name: myaneat_db
image: mariadb:10.2
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: myan
MYSQL_USER: myan
MYSQL_PASSWORD: secret
volumes:
- myaneat-data:/var/lib/mysql
networks:
- myaneat-network
ports:
- "33060:3306"
elasticsearch:
container_name: myaneat_es
image: docker.elastic.co/elasticsearch/elasticsearch:6.5.1
restart: always
volumes:
- es-data:/usr/share/elasticsearch/data
networks:
- myaneat-network
ports:
- "9200:9200"
kibana:
image: docker.elastic.co/kibana/kibana:6.5.1
container_name: myaneat_kibana
environment:
- ./kibana.yml:/usr/share/kibana/config/kibana.yml
ports:
- "5601:5601"
networks:
- myaneat-network
networks:
myaneat-network:
driver: "bridge"
volumes:
myaneat-data:
driver: "local"
es-data:
driver: "local"
I am installing a new package running the following command.
docker-compose exec php-fpm composer require calebporzio/sushi
But only the composer.json is updated but not composer.lock. Also, the package is not downloaded into the vendor folder either. I was working before. Just out of the blue, this happens.
I tried the following:
docker-compose exec php-fpm composer clearcache
docker-compose exec php-fpm composer clear-cache
docker-compose exec php-fpm composer dump-autoload
docker-compose exec php-fpm composer update --lock
What is the possible root cause? How can I fix it?
You may try run update specific to the lock:
docker-compose exec php-fpm composer update --lock
This flag is documented here
As for the updating of .lock file, you may find info about it here, You're interesting in the last clause.
Running composer update will:
Check composer.json
Determine the latest versions to install based on your version specs
Install the latest versions
Update composer.lock to reflect the latest versions installed

Docker-compose for production running laravel with nginx on azure

I have an app that is working but I am getting problems to make it run on Azure.
I have the next docker-compose
version: "3.6"
services:
nginx:
image: nginx:alpine
volumes:
- ./:/var/www/
- ./setup/azure/nginx/conf.d/:/etc/nginx/template
environment:
PORT: ${PORT}
command: /bin/sh -c "envsubst '$${PORT}' < /etc/nginx/template/nginx.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
networks:
- mynet
depends_on:
- app
- worker
app:
image: myimage:latest
build:
context: .
dockerfile: ./setup/azure/Dockerfile
restart: unless-stopped
tty: true
expose:
- 9000
volumes:
- uploads:/var/www/simple/public/uploads
- logos:/var/www/simple/public/logos
networks:
- mynet
worker:
image: my_image:latest
command: bash -c "/usr/local/bin/php artisan queue:work --timeout=0"
depends_on:
- app
networks:
- mynet
volumes:
uploads:
logos:
networks:
mynet:
I am unsure if the volumes in nginx ok, I think that perhaps I should create a new Dockerfile to copy the files. However, this would increase a lot the size of the project.
When using App Services on azure the development is made assigning a randomly port, that's wgy i have the envsubst instruction in command. I appreciate any other suggestion to make it run this project on Azure
I'm assuming you're trying to persist the storage in your app to a volume. Check out this doc issue. Now I don't think you need
volumes:
- ./:/var/www/
- ./setup/azure/nginx/conf.d/:/etc/nginx/template
but for
volumes:
- uploads:/var/www/simple/public/uploads
- logos:/var/www/simple/public/logos
you can create a storage account, mount it to your linux app plan (it's not available for Windows app plans yet), and mount the relative path /var/www/simple/public/uploads to the file path of the storage container.

Docker ENTRYPOINT bash script is executed over and over again

Everything in my docker container initialisation goes well except when I run an ENTRYPOINT script at the end of my Dockerfile with
# ...
ENTRYPOINT ["bash", "./shell_scripts/init.sh"]
which consists of
#!/bin/bash
echo "Init app..."
composer update
composer dump-autoload
php artisan migrate
and when I run docker-compose up --build it keeps running the script over and over again....
docker-compose.yml
version: '3.7'
services:
mysql_db:
image: mysql:8.0.13
container_name: mysql_8.0.13
command: --default-authentication-plugin=mysql_native_password
restart: unless-stopped
tty: true
ports:
- 3307:3306
environment:
SERVICE_TAGS: dev
SERVICE_NAME: mysql
MYSQL_ROOT_PASSWORD: mypass
networks:
- app-network
app_n_php:
build:
context: .
dockerfile: Dockerfile
container_name: app_php_7.3-rc-fpm
volumes:
- type: bind
source: ./app
target: /var/www/app
restart: unless-stopped
tty: true
ports:
- 8001:8000
depends_on:
- mysql_db
environment:
SERVICE_NAME: app_n_php
SERVICE_TAGS: dev
networks:
app-network:
driver: bridge
Any idea what is going on?

Resources