Running out of memory when executing composer inside a docker container - docker

I'm running composer on docker container and I'm trying to install predis so I run the command
docker-compose run --rm composer require predis/predis
But I get this error
Can someone explain me how to fix?
that's my dockerfile
FROM php:7.2-fpm-alpine
RUN docker-php-ext-install pdo pdo_mysql
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer --version
and that's my docker-compose
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
ports:
- "8088:80"
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- mysql
- php
networks:
- laravel
mysql:
image: mysql:5.7.22
container_name: mysql
restart: unless-stopped
tty: true
ports:
- "4306:3306"
environment:
MYSQL_DATABASE: homestead
MYSQL_USER: homestead
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: secret
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- laravel
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
volumes:
- ./src:/var/www/html
ports:
- "9000:9000"
networks:
- laravel
redis:
image: redis:5.0.0-alpine
restart: always
container_name: redis
ports:
- "6379:6379"
networks:
- laravel

In your docker-compose file, add an environment entry with COMPOSER_MEMORY_LIMIT: -1 to your php service
So your php services look like -
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
volumes:
- ./src:/var/www/html
environment:
COMPOSER_MEMORY_LIMIT: -1
ports:
- "9000:9000"
networks:
- laravel

Related

Docker compose Unable to connect

I've created docker-compose.yml file with the following content. My docker service runs ok, docker run hello-world works just fine and after running command
docker-compose build && docker-compose up -d
I see no errors but in the browser I'm getting an error Unable to connect when I go to localhost:8000
version: '3'
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
ports:
- "8000:80"
depends_on:
- php
- mysql
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
volumes:
- ./src:/var/www/html
ports:
- "9000:9000"
mysql:
image: mysql:8.0
container_name: mysql
restart: unless-stopped
ports:
- "3306:3306"
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_DATABASE: db
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: root
SERVICE_NAME: mysql
When I run command
docker-compose exec php ls
I can see the list of files and folders

Docker - Unauthorized in MariaDB

I want to create a simply LAMP with docker. The code is
Dockerfile
FROM php:8.0.0-apache
ARG DEBIAN_FRONTEND=noninteractive
RUN docker-php-ext-install mysqli
RUN apt-get update \
&& apt-get install -y libzip-dev \
&& apt-get install -y zlib1g-dev \
&& rm -rf /var/lib/apt/lists/* \
&& docker-php-ext-install zip
RUN a2enmod rewrite
Docker Compose
version: "3.8"
services:
www:
build: .
container_name: 'www'
hostname: 'laravelvue.com'
restart: 'always'
ports:
- "80:80"
networks:
- default
volumes:
- ./www:/var/www/html
database:
image: mariadb:10.7.1
container_name: 'mariadb'
command: --default-authentication-plugin=mysql_native_password
restart: 'always'
ports:
- "3306:3306"
volumes:
- persistent:/var/lib/mysql
environment:
MARIADB_DATABASE: laravelvue
MARIADB_USER: root
MARIADB_PASSWORD: test
MARIADB_ROOT_PASSWORD: test
networks:
- default
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: 'phpmyadmin'
links:
- database
environment:
MYSQL_USER: root
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
ports:
- 8000:80
volumes:
persistent:
When i launch docker compose up -d works, but when i try to enter in database (localhost:8000) with username root and password test returns
mysqli::real_connect(): (HY000/2002): php_network_getaddresses:
getaddrinfo failed: Temporary failure in name resolution
I´m new with docker so i don´t know exactly what´s is wrong ¿Anybody see what´s wrong?
Docker networking works with the name of your service as hostname. So in your database service you can connect with your phpmyadmin via http://phpmyadmin:8000. The same is for the other services. In your phpadmin service you connect with your database via http://database:3306.
And remove the networks: default and links: database in your docker-compose.yml it is not needed, as you use version 3.8 in docker-compose.yml. And make sure your phpadmin service depends_on your database service.
Correct docker-compose.yml:
version: "3.8"
services:
www:
build: .
container_name: 'www'
restart: 'always'
ports:
- "80:80"
volumes:
- ./www:/var/www/html
database:
image: mariadb:10.7.1
container_name: 'mariadb'
command: --default-authentication-plugin=mysql_native_password
restart: 'always'
ports:
- "3306:3306"
volumes:
- persistent:/var/lib/mysql
environment:
MARIADB_DATABASE: laravelvue
MARIADB_USER: root
MARIADB_PASSWORD: test
MARIADB_ROOT_PASSWORD: test
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
depends_on:
- database
environment:
MYSQL_USER: root
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
ports:
- 8000:80

Docker: container state exit 0

i have a problem with docker container.
That's my docker-compose file with 5 services
version: '3'
networks:
laravel:
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
ports:
- "8088:80"
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- mysql
- php
networks:
- laravel
mysql:
image: mysql:5.7.22
container_name: mysql
restart: unless-stopped
tty: true
ports:
- "4306:3306"
environment:
MYSQL_DATABASE: homestead
MYSQL_USER: homestead
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: secret
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- laravel
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
volumes:
- ./src:/var/www/html
ports:
- "9000:9000"
networks:
- laravel
redis:
image: redis:5.0.0-alpine
restart: always
container_name: redis
ports:
- "6379:6379"
networks:
- laravel
composer:
image: composer:latest
container_name: composer
volumes:
- ./src:/var/www/html
tty: true
working_dir: /var/www/html
networks:
- laravel
then i run
docker-compose up -d
and then
docker-compose ps
to see my container and i always get the composer contaier down with code 0. that's the screenshot
:
can someone explain me why i can't put this container up. Thanks a lot
composer isn't a program that stays alive. It's a program that does specific some work and then exits.
There's not much purpose in keeping it "up", since it's not going to do anything like the other processes do (nginx intercepts web traffic and writes response, mysql accepts database connections and reads/writes from a database, php serves web content, redis can be connected to as a cache).

Multiple services with different ports and the same domain using jwilder/nginx-proxy

I have some services in docker-compose:
version: "3"
services:
site:
volumes:
- .:/app
build:
dockerfile: Dockerfile.dev
context: docker
ports:
- "80:80"
webpack:
image: node:6.12.0
ports:
- "8080:8080"
volumes:
- .:/app
working_dir: /app
command: bash -c "yarn install; yarn run gulp server"
db:
image: mysql:5.7.20
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: ${DB_NAME}
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
And I can connect to exposed ports of services:
Site -- localhost:80
Webpack -- localhost:8080
MySQL: -- localhost:3306
How can I use nginx-proxy to expose multiple ports of different servers on the same domain (?):
Site -- example.dev:80
Webpack -- example.dev:8080
MySQL: -- example.dev:3306
This works:
services:
nginx-proxy:
image: jwilder/nginx-proxy
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
site:
volumes:
- .:/app
build:
dockerfile: Dockerfile.dev
context: docker
expose:
- 80
environment:
VIRTUAL_HOST: ${VIRTUAL_HOST}
But this is not:
services:
nginx-proxy:
image: jwilder/nginx-proxy
ports:
- "80:80"
- "8080:8080"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
site:
volumes:
- .:/app
build:
dockerfile: Dockerfile.dev
context: docker
expose:
- 80
environment:
VIRTUAL_HOST: ${VIRTUAL_HOST}
webpack:
image: node:6.12.0
expose:
- 8080
environment:
VIRTUAL_HOST: ${VIRTUAL_HOST}
VIRTUAL_PORT: 8080
volumes:
- .:/app
working_dir: /app
command: bash -c "yarn install; yarn run gulp server"
What am I do wrong? How can I solve this problem?
//Sorry for my worst English. Hope you'll understand me
Update:
This is just an example. In the future I'll make proxy as external network and will connect services to it. And I wont to run two docker-compose "files" on the same host (VPS). Purpose: production and test versions on the same host, that use same ports BUT different domains. For example:
example.com -- Web Site
example.com:81 -- PhpMyAdmin
test.example.com -- Web Site for testing
test.example.com:81 -- PhpMyAdmin for testing

Docker connect database from a container (laravel) to other container (wordpress)

I have two project using docker, in first project is laravel, and second is wordpress. In laravel I want to connect both database (to convert laravel database to wordpress database).
but I don't know how to connect it:
here is two docker-compose.yml file:
in laravel:
version: '2'
services:
# The Application
app:
build:
context: ./
dockerfile: app.dockerfile
working_dir: /var/www
volumes:
- ./:/var/www
environment:
- "DB_PORT=3306"
- "DB_HOST=database"
# The Web Server
web:
build:
context: ./
dockerfile: web.dockerfile
working_dir: /var/www
volumes_from:
- app
ports:
- 8081:80
# The Database
database:
image: mysql:5.6
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_DATABASE=homestead"
- "MYSQL_USER=homestead"
- "MYSQL_PASSWORD=secret"
- "MYSQL_ROOT_PASSWORD=secret"
ports:
- "33061:3306"
volumes:
dbdata:
and my docker-compose.yml file in wordpress:
version: '2'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: 123456
MYSQL_DATABASE: wpshop
MYSQL_USER: root
MYSQL_PASSWORD: 123456
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- ./:/var/www/html
ports:
- "8080:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: 123456
volumes:
db_data:
I cd to each project and run docker-compose up -d
Please help me!
Create an external network and use that network as default network for all your containers. This way you'll be able to reach all container by its name.
Take a look to Docker container networking: https://docs.docker.com/engine/userguide/networking/

Resources