I used Laradock on an EC2 instance of AWS to create a local development environment for Laravel.
After building the Laradock environment, start the container with docker-compose up -d nginx mysql
. When I try to generate Laravel by connecting to "laradock_workspace_1" with docker-compose exec workspace bash
, the following error occurs.
The instance type of EC2 is "t2.micro" (RAM 1GB), and the AMI is Amazon Linux 2.
$ root@4e964ed4f2ce: composer create-project --prefer-dist laravel/laravel ./
Installing laravel/laravel (v7.0.0)
- Installing laravel/laravel (v7.0.0): Downloading (100%)
proc_open(): fork failed - Cannot allocate memory
The archive may contain identical file names with different capitalization (which fails on case insensitive filesystems)
Unzip with unzip command failed, falling back to ZipArchive class
The following exception is caused by a lack of memory or swap, or not having swap configured
Check https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors for details
PHP Warning: proc_open(): fork failed - Cannot allocate memory in phar:///usr/local/bin/composer/vendor/symfony/console/Application.php on line 952
Warning: proc_open(): fork failed - Cannot allocate memory in phar:///usr/local/bin/composer/vendor/symfony/console/Application.php on line 952
[ErrorException]
proc_open(): fork failed - Cannot allocate memory
create-project [-s|--stability STABILITY] [--prefer-source] [--prefer-dist] [--repository REPOSITORY] [--repository-url REPOSITORY-URL] [--dev] [--no-dev] [--no-custom-installers] [--no-scripts] [--no-progress] [--no-secure-http] [--keep-vcs] [--remove-vcs] [--no-install] [--ignore-platform-reqs] [--] [<package>] [<directory>] [<version>]
I've seen it before so I tried to create a swap file but it didn't work.
The running container looks like this.
[ec2-user@ip-172-31-47-6 laradock]$ sudo docker-compose ps
Name Command State Ports
-----------------------------------------------------------------------------------------------------------------------------------
laradock_docker-in-docker_1 dockerd-entrypoint.sh Up 2375/tcp, 2376/tcp
laradock_mysql_1 docker-entrypoint.sh mysqld Up 0.0.0.0:3306->3306/tcp, 33060/tcp
laradock_nginx_1 /bin/bash /opt/startup.sh Up 0.0.0.0:443->443/tcp, 0.0.0.0:80->80/tcp, 0.0.0.0:81->81/tcp
laradock_php-fpm_1 docker-php-entrypoint php-fpm Up 9000/tcp
laradock_workspace_1 /sbin/my_init Up 0.0.0.0:2222->22/tcp, 0.0.0.0:8001->8000/tcp,
0.0.0.0:8080->8080/tcp
Try creating a swap file normally.
Memory usage (MB display) Swap space is not currently allocated.
$ root@4e964ed4f2ce:/var/www# free -m
total used free shared buff/cache available
Mem: 983 566 217 3 200 232
Swap: 0 0 0
Create a file for swap space
$ root@4e964ed4f2ce:/var/www# /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 14.8802 s, 72.2 MB/s
Set the created file called swap.1 in the swap area
$ root@4e964ed4f2ce:/var/www# /sbin/mkswap /var/swap.1
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
no label, UUID=450a4e24-3455-4466-a6e0-5daf190cdad3
Enable swap space
root@4e964ed4f2ce:/var/www# /sbin/swapon /var/swap.1
swapon: /var/swap.1: insecure permissions 0644, 0600 suggested.
swapon: /var/swap.1: swapon failed: Operation not permitted
Then, the error swapon failed: Operation not permitted
appears and the activation of the swap area fails.
It's a permission issue, so I tried it with sudo, but the result didn't change.
It seems that it can be solved by tampering with the OS permission settings listed in docker, but I do not want to mess with what I do not understand so much ...
In the first place, the cause of swapping is insufficient physical memory. Instead of creating a swap file and adding virtual memory, we scaled up EC2. Instance type: t2.micro-> t2.small I think that there is no problem because the hourly charge changes only about 1 yen.
Instance type | RAM(GB) | Online Linux Fees |
---|---|---|
t2.micro | 1 | 0.0116 USD per hour |
t2.small | 2 | 0.023 USD per hour |
Countermeasures when Cannot allocate memory appears in Laravel [Corresponds to the error Docker Operation not permitted](https://bmf-tech.com/posts/Docker%E3%81%AEOperation%20not%20permitted%E3%81%A8%E3%81%84%E3 % 81% 86% E3% 82% A8% E3% 83% A9% E3% 83% BC% 08% E3% 81% AB% E5% AF% BE% E5% BF% 9C% E3% 81% 99% E3 % 82% 8B)
Recommended Posts