I am using docker images for running web-app on PHP and MongoDB. Docker container is running perfectly on my local machine (Windows10) but it is not updating on AWS Elastic Beanstalk. I have made a zipped file consist of run.sh, Dockerfile, and Dockerrun.aws.json which can be found from here.
On AWS Elastic Beanstalk I am using single docker container and instance type is Linux Docker Version 1.11.2 . after deploying I am getting following error:
It looks like your run.sh needs to be executable, based on this inspection of the files:
ls
total 16K
drwxr-xr-x 7 adam 238 Jan 11 11:04 .
drwxr-xr-x+ 139 adam 4.7K Jan 11 11:04 ..
drwxr-xr-x 12 adam 408 Jan 11 11:04 .git
-rw-r--r-- 1 adam 1.9K Jan 11 11:04 Dockerfile
-rw-r--r-- 1 adam 248 Jan 11 11:04 Dockerrun.aws.json
-rw-r--r-- 1 adam 544 Jan 11 11:04 index.php
-rw-r--r-- 1 adam 72 Jan 11 11:04 run.sh
It's possible that you have other issues, but running chmod +x run.sh before you recreate the zip file should fix that specific problem.
Related
I'm trying to achieve execute shell scripts create a new folder /var/www/html/ in this path using by shell_execin php, web server Apache Server and Ubuntu 16.04
I've tried a list of files in the path /var/www/html in php file using web browser
<?php
$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";
?>
The Output is
total 68
-rw-rw-r-- 1 ubuntu gitpulluser 573 Jan 6 12:50 .gitignore
drwxrwxr-x 2 ubuntu gitpulluser 4096 Jan 6 12:50 .vscode
drwxrwxr-x 11 ubuntu gitpulluser 4096 Jan 6 12:51 Backendfiles
-rw-rw-r-- 1 ubuntu gitpulluser 27 Jan 6 12:51 package-lock.json
-rw-rw-r-- 1 ubuntu gitpulluser 17 Jan 6 17:01 pk.sh
-rw-rw-r-- 1 ubuntu gitpulluser 243 Jan 6 17:02 myfilename.php
-rw-rw-r-- 1 ubuntu gitpulluser 120 Jan 6 17:05 run.php
-rw-rw-r-- 1 ubuntu gitpulluser 5 Jan 6 17:06 date.sh
-rw-rw-r-- 1 ubuntu gitpulluser 148 Jan 7 11:41 hi.php
-rwxr-xr-x 1 root root 23 Jan 7 11:48 gitpull.sh
drwxrwxr-x 16 ubuntu gitpulluser 4096 Jan 7 12:25 UIfiles
-rw-rw-r-- 1 ubuntu ubuntu 16 Jan 7 12:25 test
-rwxr-xr-x 1 root root 20 Jan 7 12:27 cgi-test.sh
drwxrwxr-x 8 ubuntu gitpulluser 4096 Jan 7 12:39 .git
-rw-r--r-- 1 root root 144 Jan 7 15:09 shell.php
drwxr-xr-x 15 ubuntu ubuntu 4096 Jan 7 15:09 ..
drwxrwxr-x 6 ubuntu gitpulluser 4096 Jan 7 15:09 .
This works fine with no issues, Here I'm facing the challenge not able to create a folder in the path /var/www/html/.
my code is:
<?php
shell_exec('sudo mkdir mynewfolder');
?>
I'm executing the file from the browser but the folder is not creating. Please help me out from this.
Thanks for advance
Changed the permission user group and owner permission for the path
$sudo chown www-data:www-data -R /var/ww/html
After that restart the apache service.
$suho service apache2 restart
I don't know what I am missing. I have a docker image, and a docker compose file.
My goal is to execute PHP Unit tests in Jenkins
I guess this
volumes:
- .:/var/www/html
is the source of the problems, but shouldn't the container last image have already the vendor directory?
Dockerfile
FROM quay/php-base:7.2.
COPY . /var/www/html
RUN curl -sS https://getcomposer.org/installer | php
RUN php composer.phar install
RUN rm composer.phar
EXPOSE 9000
CMD ["php-fpm"]
build.testing.yml
version: "3"
services:
phpfpm:
build:
context: .
dockerfile: Dockerfile
image: xxx-phpfpm:${GIT_COMMIT}
environment:
- APP_ENV=testing
volumes:
- .:/var/www/html
Jenkins build shell command
printenv
echo $GIT_BRANCH
echo $GIT_COMMIT
docker-compose -f build.testing.yml up -d --build --remove-orphans
docker-compose -f build.testing.yml exec -T phpfpm bash build/phpunit.sh
phpunit.sh
#!/usr/bin/env bash
cd /var/www/html;
ls -la;
ls -la vendor;
ls -la vendor/bin;
php vendor/bin/phpunit;
exit $?
Build log (last lines)
phpunit/php-code-coverage suggests installing ext-xdebug (^2.6.0)
phpunit/phpunit suggests installing ext-soap (*)
phpunit/phpunit suggests installing ext-xdebug (*)
phpunit/phpunit suggests installing phpunit/php-invoker (^2.0)
Generating optimized autoload files
Removing intermediate container 56245736b26b
---> 818e587ac18a
Step 6/8 : RUN rm composer.phar
---> Running in 5ccbffc37e05
Removing intermediate container 5ccbffc37e05
---> 086e88f369fc
Step 7/8 : EXPOSE 9000
---> Running in 1c10e32ba134
Removing intermediate container 1c10e32ba134
---> 84eb9cbc3477
Step 8/8 : CMD ["php-fpm"]
---> Running in b6381d9b0f9a
Removing intermediate container b6381d9b0f9a
---> 40b32fa81d5f
Successfully built 40b32fa81d5f
Successfully tagged xxx-phpfpm:aa01355d1e8ab6d0f3daf87fb8f1f3b1be3e45be
Recreating xxxmicroservicetesting_phpfpm_1 ...
Recreating xxxmicroservicetesting_phpfpm_1 ... done
+ docker-compose -f build.testing.yml exec -T phpfpm bash build/phpunit.sh
total 224
drwxrwxr-x 13 1002 1002 4096 Jul 29 19:35 .
drwxr-xr-x 1 root root 18 May 5 2018 ..
-rw-rw-r-- 1 1002 1002 213 Jul 26 15:38 .editorconfig
-rw-rw-r-- 1 1002 1002 388 Jul 26 15:38 .env.example
drwxrwxr-x 8 1002 1002 162 Jul 29 19:41 .git
-rw-rw-r-- 1 1002 1002 55 Jul 26 15:38 .gitignore
-rw-rw-r-- 1 1002 1002 71 Jul 26 15:38 .styleci.yml
-rw-rw-r-- 1 1002 1002 232 Jul 26 15:38 Dockerfile
-rw-rw-r-- 1 1002 1002 895 Jul 29 18:25 Jenkinsfile
drwxrwxr-x 16 1002 1002 240 Jul 26 15:38 app
-rw-rw-r-- 1 1002 1002 1094 Jul 26 15:38 artisan
drwxrwxr-x 2 1002 1002 21 Jul 26 15:38 bootstrap
drwxrwxr-x 2 1002 1002 24 Jul 29 19:41 build
-rw-rw-r-- 1 1002 1002 250 Jul 29 19:35 build.testing.yml
-rw-rw-r-- 1 1002 1002 1256 Jul 26 15:38 composer.json
-rw-rw-r-- 1 1002 1002 179335 Jul 26 15:38 composer.lock
drwxrwxr-x 2 1002 1002 45 Jul 26 15:38 config
drwxrwxr-x 5 1002 1002 54 Jul 26 15:38 database
-rw-rw-r-- 1 1002 1002 193 Jul 26 15:38 phpcs.xml
-rw-rw-r-- 1 1002 1002 924 Jul 26 15:38 phpunit.xml
drwxrwxr-x 2 1002 1002 40 Jul 26 15:38 public
drwxrwxr-x 3 1002 1002 19 Jul 26 15:38 resources
drwxrwxr-x 2 1002 1002 40 Jul 26 15:38 routes
drwxrwxr-x 5 1002 1002 46 Jul 26 15:38 storage
drwxrwxr-x 4 1002 1002 113 Jul 26 15:38 tests
ls: vendor: No such file or directory
ls: vendor/bin: No such file or directory
Could not open input file: vendor/bin/phpunit
Build step 'Execute shell' marked build as failure
Finished: FAILURE
When you have a volumes: directive in a docker-compose.yml like you show, it tells Docker to completely ignore the contents of the Docker image and use whatever's in the local filesystem. You should remove that.
If you're running this in Jenkins or another continuous integration (CI) system, this behavior would mean that the image that comes out of the build system hasn't actually been tested. You've run tests on whatever local source tree Jenkins has checked out, glued over the top of the built image. If the host system and the image have any sort of incompatibility around library versions or a vendored library tree, you can easily wind up in a situation where you're shipping a completely broken image, that happens to pass this artificial test environment.
In this context I'd suggest a sequence like this:
Check out your source tree.
Run any build steps and unit-test steps. Jenkins has a path to run these inside a Docker container, which can be more convenient than maintaining a Jenkins image with the language runtime you need, but this isn't "building and running the image". You can do this totally without Docker too.
Actually build the Docker image. I'd do this with the Jenkins Docker workflow plugin, or a manual sh "docker build" step.
Run integration tests against the built image. This could use a docker-compose.yml file like you show above, but without the build: or volumes: blocks. The test itself wouldn't be built into the image, but it would make external calls into the image's published API.
Push the built image to a registry. Trigger an automated deployment sequence, if that's appropriate.
I'm having a problem with the final steps of a ZeroMQ installation after running this command to install ZeroMQ with MAMP...
sudo pecl install zmq-beta
Build complete.
Don't forget to run 'make test'.
running: make INSTALL_ROOT="/private/tmp/pear/temp/pear-build-rootIN0Z6M/install-zmq-1.1.3" install
Installing shared extensions: /private/tmp/pear/temp/pear-build-rootIN0Z6M/install-zmq-1.1.3/usr/lib/php/extensions/no-debug-non-zts-20131226/
running: find "/private/tmp/pear/temp/pear-build-rootIN0Z6M/install-zmq-1.1.3" | xargs ls -dils
10893452 0 drwxr-xr-x 3 root wheel 102 21 Apr 11:29 /private/tmp/pear/temp/pear-build-rootIN0Z6M/install-zmq-1.1.3
10893999 0 drwxr-xr-x 3 root wheel 102 21 Apr 11:29 /private/tmp/pear/temp/pear-build-rootIN0Z6M/install-zmq-1.1.3/usr
10894000 0 drwxr-xr-x 3 root wheel 102 21 Apr 11:29 /private/tmp/pear/temp/pear-build-rootIN0Z6M/install-zmq-1.1.3/usr/lib
10894001 0 drwxr-xr-x 3 root wheel 102 21 Apr 11:29 /private/tmp/pear/temp/pear-build-rootIN0Z6M/install-zmq-1.1.3/usr/lib/php
10894002 0 drwxr-xr-x 3 root wheel 102 21 Apr 11:29 /private/tmp/pear/temp/pear-build-rootIN0Z6M/install-zmq-1.1.3/usr/lib/php/extensions
10894003 0 drwxr-xr-x 3 root wheel 102 21 Apr 11:29 /private/tmp/pear/temp/pear-build-rootIN0Z6M/install-zmq-1.1.3/usr/lib/php/extensions/no-debug-non-zts-20131226
10894005 168 -rwxr-xr-x 1 root wheel 82396 21 Apr 11:29 /private/tmp/pear/temp/pear-build-rootIN0Z6M/install-zmq-1.1.3/usr/lib/php/extensions/no-debug-non-zts-20131226/zmq.so
Build process completed successfully
Installing '/usr/lib/php/extensions/no-debug-non-zts-20131226/zmq.so'
ERROR: failed to write /usr/lib/php/extensions/no-debug-non-zts-20131226/zmq.so (copy(/usr/lib/php/extensions/no-debug-non-zts-20131226/zmq.so): failed to open stream: Operation not permitted)
I've been through a bunch of issues to get this far, but am really not sure what could be the cause of this "operation not permitted". Any ideas would be greatly appreciated.
You need install pecl on PHP from MAMP first(not on PHP CLI) and then run command bellow:
sudo /Applications/MAMP/bin/php/php7.0.0/bin/pecl install zmq-beta
I have a fresh install of laravel. I setup the host to point to the public directory through mamp. Nothing serves however after restarting the local server.
I replicated all of this on windows through WAMP and laravel serves correctly. Redoing my steps on mac, the page just spins until the browser times it out.
Nothing fancy is happening, just trying to get the core laravel landing page to serve on a fresh laravel 5.4 install through mamp.
I went so far as to add a vhosts entry in the /Applications/MAMP/conf/apache/extra file. Restarted the servers and still no dice.
Any suggestions or nudges in the right direction would be super helpful. I just dont know what could be the difference at this point. I can do it successfully on windows...
Nothing happens in the logs. Browser just spins until it times out I'm guessing. Nothing serves, not even a timeout error.
ls -l reveals:
-rw-r--r-- 1 kstanley staff 1050 Feb 3 16:49 package.json
-rw-r--r-- 1 kstanley staff 1055 Feb 3 16:49 phpunit.xml
drwxr-xr-x 10 kstanley staff 340 Feb 26 09:23 public
-rw-r--r-- 1 kstanley staff 2906 Feb 3 16:49 readme.md
drwxr-xr-x 6 kstanley staff 204 Feb 26 09:23 resources
drwxr-xr-x 6 kstanley staff 204 Feb 26 09:18 routes
-rw-r--r-- 1 kstanley staff 563 Feb 3 16:49 server.php
drwxr-xr-x 6 kstanley staff 204 Feb 26 09:23 storage
drwxr-xr-x 7 kstanley staff 238 Feb 26 09:23 tests
drwxr-xr-x 33 kstanley staff 1122 Feb 26 09:23 vendor
Ok this was a non issue with laravel. The issue was mamp. None of my other hosts worked either. After doing a hard reboot of my computer and restarting mamp, everything worked. This is not the first time this has happened with mamp.
Remember always to set 777 permisions to storage folder chmod -R 777 storage.
It is common to get a blank screen or a "Log error" while the main error is just a permission one.
Is there any good way (faster) to launch phpunit on docker? Here what I used to do :
docker-compose build
docker-compose up
docker ps
docker exec <container_id> phpunit --configuration /myproject/src/Tests/phpunit.xml --testsuite testAllSuites
Note: I don't want to use Volume to sync files, so right now everytime I have to rebuild the project .. and I am trying to figure out how to launch test on a specific container without specifing the containe_id .. is it possible to launch it using the build name instead ?
No need to do a complicated lookup of the container id, here's an example of how you can do it within docker-compose:
$ cat docker-compose.yml
version: '2'
volumes:
testvol:
driver: local
services:
testapp:
image: busybox
entrypoint: "top"
volumes:
- testvol:/data
testapp2:
image: busybox
entrypoint: "top"
volumes:
- testvol:/data
$ ../bin/docker-compose up -d
Creating test_testapp_1
Creating test_testapp2_1
$ ../bin/docker-compose ps
Name Command State Ports
-----------------------------------------
test_testapp2_1 top Up
test_testapp_1 top Up
$ ../bin/docker-compose exec testapp ls -l
total 40
drwxr-xr-x 2 root root 12288 Mar 18 16:39 bin
drwxr-xr-x 2 root root 4096 Jun 11 11:07 data
drwxr-xr-x 5 root root 360 Jun 13 11:50 dev
drwxr-xr-x 2 root root 4096 Jun 13 11:50 etc
drwxr-xr-x 2 nobody nogroup 4096 Mar 18 16:38 home
dr-xr-xr-x 224 root root 0 Jun 13 11:50 proc
drwxr-xr-x 2 root root 4096 Mar 18 16:38 root
dr-xr-xr-x 13 root root 0 Jun 13 11:50 sys
drwxrwxrwt 2 root root 4096 Mar 18 16:38 tmp
drwxr-xr-x 3 root root 4096 Mar 18 16:39 usr
drwxr-xr-x 4 root root 4096 Mar 18 16:39 var
You can also take advantage of the consistent container naming by docker-compose (it prepends the directory name and appends a number for scaling) to run the exec on the individual containers with docker exec:
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
069d40e3b6c7 busybox "top" 2 minutes ago Up 2 minutes test_testapp2_1
60e6d34d3b5a busybox "top" 2 minutes ago Up 2 minutes test_testapp_1
$ docker exec test_testapp_1 ls -l
total 40
drwxr-xr-x 2 root root 12288 Mar 18 16:39 bin
drwxr-xr-x 2 root root 4096 Jun 11 11:07 data
drwxr-xr-x 5 root root 360 Jun 13 11:50 dev
drwxr-xr-x 2 root root 4096 Jun 13 11:50 etc
drwxr-xr-x 2 nobody nogroup 4096 Mar 18 16:38 home
dr-xr-xr-x 226 root root 0 Jun 13 11:50 proc
drwxr-xr-x 2 root root 4096 Mar 18 16:38 root
dr-xr-xr-x 13 root root 0 Jun 13 11:50 sys
drwxrwxrwt 2 root root 4096 Mar 18 16:38 tmp
drwxr-xr-x 3 root root 4096 Mar 18 16:39 usr
drwxr-xr-x 4 root root 4096 Mar 18 16:39 var
I just figure out an easiest way to launch phpunit tests on my php-fpm container, here the command :
docker exec -it $(docker ps -n=-1 -q --filter name=my_php_container_name --format="{{.ID}}") phpunit --configuration /myproject/src/Tests/phpunit.xml --testsuite testAllSuites
so now whenever I change anything on my code here what I do :
docker-compose build
docker-compose up
docker exec -it $(docker ps -n=-1 -q --filter name=my_php_container_name --format="{{.ID}}") phpunit --configuration /myproject/src/Tests/phpunit.xml --testsuite testAllSuites
So this means I don't have to display all docker containers (docker ps) to get the id and update the command manually to launch phpunit on the new container id.
Runing this command wil return only the container_id :
docker ps -n=-1 -q --filter name=my_php_container_name --format="{{.ID}}"
here some explanations :
-n=-1 : show n last ceated containers
-q : only display numeric IDs
for more details about options here the docker documentation
Note: Just for instance, if we move phpunit.xml file just under /myproject/ root the phpunit command can be even smaller and if we run phpunit it will automatically load phpunit.xml and run all tests under your /Tests/... folder and the command will be :
docker exec -it $(docker ps -n=-1 -q --filter name=my_php_container_name --format="{{.ID}}") phpunit
Hope this can help someone ...