[LINUX] What to do if you get angry with swapon failed: Operation not permitted

Status

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                       

What I tried

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 ...

solution

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

The page that I used as a reference

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

What to do if you get angry with swapon failed: Operation not permitted
What to do if you get Could not fetch URL 443 with pip
What to do if you get a UnicodeDecodeError with pip install
What to do if you get lost in file reference with FileNotFoundError
What to do if you get angry in TensorFlow v2 without attribute'app'
What to do if you get a TypeError with numpy min, max
What to do if you get an error when installing python with pyenv
What to do if you get "Python not configured." Using PyDev in Eclipse
What to do if you get angry with "Value Error: unknown local: UTF-8" in python manage.py syncdb
What to do when you get angry that libxml / xmlversion.h does not exist when you put lxml with pip
What to do if you get "coverage unknown" in Coveralls
What to do if you can't sort files with subscripts
What to do if you get an OpenSSL error when installing Python 2 with pyenv
What to do if you get an Import Error when importing matplotlib with Jupyter
What to do if you can't install pyaudio with pip #Python
What to do if you get a minus zero in Python
What to do if you can't build your project with Maven
What to do if you get an Undefined error when trying to use pip with pyenv
What to do if you get angry with'vertices' must be a 2D list ... in matplotlib arrow
What to do if you get angry if you don't have libxml / xmlversion.h when installing lxml on CentOS
What to do if you can't find well with grep's -f option
What to do if you couldn't send an email to Yahoo with Python.
What to do if you get stuck during Anaconda installation on Linux
What to do if pyenv install does not proceed with an error
What to do if you get an error when trying to load mnist
What to do if you can't install with pip in babun environment
What to do if you get an error when installing Dlib (Ubuntu)
What to do if you can't pipenv shell
What to do if you get angry with "Gtk * backend requires pygtke to be installed" even though pygtk is included in matplotlib
What to do if you get "The session could not be opened" when installing CentOS on VirtualBox
What to do if you get a "Wrong Python Platform" warning when using Python with the NetBeans IDE
What to do if you get a "No versions found" error in pipenv
What to do if you can't pip install mysqlclient
No module named What to do if you get'libs.resources'
ModuleNotFoundError: No module What to do if you get'tensorflow.contrib'
Links to do what you want with Sublime Text
What to do if sys / cdefs.h does not exist
What to do if pyenv is not enabled (zsh)
What to do if you get an "unknown service" error from your gRPC server
What to do if you get `No kernel for language python found` in Hydrogen
What to do if you get a memory error when converting from PySparkDataFrame to PandasDataFrame
What to do if you get "(35,'SSL connect error')" in pycurl (one of them)
What to do if you get an error when importing matplotlib in Python (Mac)
What to do if you get the error ʻERR_FEATURE_UNAVAILABLE_ON_PLATFORM` when using ts-node-dev on Linux
What to do if you run python in IntelliJ and end with an error
What to do if you get a Call with too many input arguments error at DoAndReturn in a golang test
What to do if you get the error "Error: opencv3: Does not support building both Python 2 and 3 wrappers" when installing openCV 3
[AWS] What to do when you want to pip with Lambda
What to do if you are addicted to Windows character code
What to do if you can't log in as root
What to do if you can't use WiFi on Linux
What to do if you lose your EC2 key pair
What to do when you get an error saying "Name resolution temporarily failed" on linux
[Development environment] If you cannot migrate php artisan with Operation not permitted, check the permissions!
What to do if you get Swagger-codegen in python and Import Error: No module named
What to do if you get a Cannot retrieve metalink for repository error in yum
What to do if you get an Undefined error:'Module_six_moves_urllib_parse' object has no attribute'urlencode' on MacOS
What to do if you get an error when running "certbot renew" in CakePHP environment
What to do if yum breaks
What to do with Magics install
What to do with PYTHON release?