How to change files ownership in laravel via docker using powershell - laravel

I'm using docker on windows. After I created image from Dockerfile docker build -t my-laravel-image in my laravel project I tried to run it docker run -p 8000:8000 my-laravel-image but got the error in the browser ERR_ADDRESS_INVALID
After some digging I found that it is because /storage and /vendor doesn't have right permissions to write. However, I red on linux forum, that to to give permissions to everyone with chmod 777 is bad so I should change owner with chown, however, I could find command which would do the job on Powershell, so I'm asking you for help
the tutorial I am following is https://www.techiediaries.com/docker-compose-laravel/
EDIT
Tried this ICACLS "C:\Users\Dominykas\Projects\laravel" /setowner "administrator" it succeded, but I get the same error

docker exec -it <your container> chown -R myuser:mygroup laraveldir

Related

Laravel on ElasticBeanstalk 'log file permission denied' error keeps coming up even the permission is set in the .ebextensions config file

I am deploying my Laravel application to the ElasticBeanstalk environment. But I am having issue with laravel.log file permissions.
I deployed my application using "eb deploy" command. After I deployed, I access my application. But it is throwing the following error.
The stream or file "/var/app/current/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied
To solve the issue, I ssh into the server and run the following command.
sudo -u root chmod 777 -R /var/app/current/storage/logs
The problem is solved. Now my application is working. But I deploy my application again running "be deploy" command. After the deployment, the issue popped up again. To solve the issue in a consistent way. I tried to run the command in the .ebextensions config file as follow.
container_commands:
01-migrations:
command: "php artisan migrate --force"
02-log-storage-permissions:
command: "sudo -u root chmod -R 777 /var/app/current/storage/logs/"
I could deploy my application. But the issue still persists. It seems like the command is not working. What is wrong with my configuration and how can I fix it?
I believe that this is because container_commands run when your application is in the staging folder. Thus, after you run 02-log-storage-permissions, your /var/app/current will be replaced anyway with the staging folder. So your chmod wont persist.
To rectify the issue, you can try one of the two options:
Use
02-log-storage-permissions:
command: "sudo -u chmod -R 777 ./storage/logs/"
to change the logs in staging folder.
use postdeploy hook to run your script:
after the Elastic Beanstalk platform engine deploys the application and proxy server.

How to configure as Docker volume a directory on the Desktop in Windows?

I started to work with Docker and I have a problem when I set a volume.
I use windows OS with virtual box.
I would like to create a directory and use the as directory for the volume for a specific image.
The image is Jenkins and I would like to set as volume a directory on the desktop called volume.
I have tried a lot of commands but for the last one I tried on this:
docker run --name MyJenkins1 -v /C/Users/Alessandro/Desktop/volume:/var/jenkins_home -p 9191:8080 -p 40000:50000 jenkins
But I receive the follow result:
'touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied
Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?'
I have also tried to set the shared virtual machine directory as follow:
DIRECTORY PATH: C:\Users\Alessandro\Desktop\volume
DIRECTORY NAME: volume
Read_only: no
Auto-mount: yes
Make Permanent: yes
Can somebody help me, please?
Best Regards
Alessandro
Does the user running Docker have permission to write to the "C:\Users\Alessandro\Desktop\volume" directory?
If not, run this from a command line:
set DOCKER_SHARED_DRIVE_USER=...put in the name of the OS user for docker or shared drive if using Docker Desktop...
icacls "C:\Users\Alessandro\Desktop\volume" /grant %DOCKER_SHARED_DRIVE_USER%:(OI)(CI)F

Connecting folder in a Docker container with a folder on local machine - Permission Denied

I'm new to docker and am trying to bind mount a folder in my docker container with a folder on my local machine. Using the code below, I was able to create the container with no issue.
docker run -it -v /Users/bdbot/Documents/mount_demo/:/mount_demo nycdsa/linux-toolkits bash
However, when I tried to create a txt file within the container folder, I got this error:
bash: demo.txt: Permission denied
Seeing that it was an access issue, I ran
sudo chmod 777 ../mount_demo
This allowed me to create the file, however when I checked the folder on my local machine it was not there. So the folders are not syncing.
I've also made sure the docker settings "Shared Drives" had the correct credentials. I'm not familiar enough with Docker to know how to trouble shoot further and have not been able to find anything online. I am using Windows, and everything is up to date.
The answer ended up being a really simple fix. The combination of using unix on a windows machine required that I add an additional slash(/) before the folder path. The below fixed this issue for me:
docker run -it -v //Users/bdbot/Documents/mount_demo/:/mount_demo nycdsa/linux-toolkits bash

Unable to find docker image locally

I was following this post - the reference code is on GitHub. I have cloned the repository on my local.
The project has got a react app inside it. I'm trying to run it on my local following step 7 on the same post:
docker run -p 8080:80 shakyshane/cra-docker
This returns:
Unable to find image 'shakyshane/cra-docker:latest' locally
docker: Error response from daemon: pull access denied for shakyshane/cra-docker, repository does not exist or may require 'docker login'.
See 'docker run --help'.
I tried login to docker again but looks like since it belongs to #shakyShane I cannot access it.
I idiotically tried npm start too but it's not a simple react app running on node - it's in the container and containers are not controlled by npm
Looks like docker pull shakyshane/cra-docker:latest throws this:
Error response from daemon: pull access denied for shakyshane/cra-docker, repository does not exist or may require 'docker login'
So the question is how do I run this docker image on my local mac machine?
Well this is illogical but still sharing so future people like me don't get stuck.
The problem was that I was trying to run a docker image which doesn't exist.
I needed to build the image:
docker build . -t xameeramir/cra-docker
And then run it:
docker run -p 8080:80 xameeramir/cra-docker
In my case, my image had TAG specified with it and I was not using it.
REPOSITORY TAG IMAGE ID CREATED SIZE
testimage testtag 189b7354c60a 13 hours ago 88.3MB
Unable to find image 'testimage:latest' locally for this command docker run testimage
So specifying tag like this - docker run testimage:testtag worked for me
Posting my solution since non of the above worked.
Working on macbook M1 pro.
The issue I had is that the image was built as arm/64. And I was running the command:
docker run --platform=linux/amd64 ...
So I had to build the image for amd/64 platform in order to run it.
Command below:
docker buildx build --platform=linux/amd64 ...
In conclusion your docker image platform and docker run platform needs to be the same from what I experienced.
In my case, the docker image did exist on the system and still I couldn't run the container locally, so I used the exact image ID instead of image name and tag, like this:
docker run myContainer c29150c8588e
I received this error message when I typed the name/character wrong. That is, "name1\name2" instead of "name1/name2" (wrong slash).
In my case, I saw this error when I had logged in to the dockerhub in my docker desktop. The repo I was pulling was local to my enterprise. Once i logged out of dockerhub, the pull worked.
This just happened to me because my local docker vm on macos ran out of disk space.
I just deleted some old images using docker image prune and it started working correctly again.
shakyshane/cra-docker Does not exist in that user's repo https://hub.docker.com/u/shakyshane/
The problem is you are trying to run an imagen that does not exists. If you are executing a Dockerfile, the image was not created until Dockerfile pass with no errors; so when Dockerfile tries to run the image, it can't find it. Be sure you have no errors in the execution of your scripts.
The simplest answer can be the correct one!.. make sure you have permissions to execute the command, use:
sudo docker run -p 8080:80 shakyshane/cra-docker
In my case, I didn't realise there was a difference between docker run and docker start, and I kept using the run command when I should've been using the start command.
FYI, run is for building and creating the docker container, start is to just start a stopped container
Use -d
sudo docker run -d -p 8000:8000 rasa/duckling
learn about -d here
sudo docker run --help
At first, i build image on mac-m1-pro with this command docker build -t hello_k8s_world:0.0.1 ., when is run this image the issue appear.
After read Master Yi's answer, i realize the crux of the matter and rebuild my images like this docker build --platform=arm64 -t hello_k8s_world:0.0.1 .
Finally,it worked.

How can I find initial password for jenkins?

I already searched the related questions like here;
How do I get initial admin password for jenkins on Mac?
and here;
How to recover Jenkins password
However, I cannot find a solution for my problem.
I am following the instructions to install jenkins on this link;
https://jenkins.io/doc/book/installing/
and I have run the following commands to install and tried to make it run on my local machine (mac os);
docker run \
-u root \
--rm \
-d \
-p 8080:8080 \
-p 50000:50000 \
-v jenkins-data:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
jenkinsci/blueocean
It installs it properly but when I get to the login screen it asks for the initial admin password. Because the installation runs in (-d mode) backend, I cannot see the initial password after the installation completes. When I remove -d for the installation, then the installation does not work.
I also checked the shared folder (User/Shared/Jenkins/Home) directory and there was no secrets folder in it. So I created one manually and followed the instructions (in the answers) on this link again;
How do I get initial admin password for jenkins on Mac?
Afterwards, I removed the related docker process and restarted all the installation process from the beginning but I got the same result.
In this case, how can I find this initial admin password or how can I generate it again?
BTW: I am also checking the logs (where in /var/log/jenkins) but it seems that it stopped writing there after my first install attempt and I also couldn't find the initial password there).
docker exec <container_name> cat /var/jenkins_home/secrets/initialAdminPassword
I tried looking into the container's filesystem, but there's no secrets folder in it. But I found the solution in the jenkins documentation here
Docker outputs the initial secret to the console
To view the console use the command
docker logs <container id of jenkins>
output is somemthing like this:
If you are using Mac and Docker installation for Jenkins follow bellow steps to get initial administer password to start authentication in Jenkins Console. Type below command in Terminal.
(Note: This is working, if you have follow default steps in Jenkins documentation to install Jenkins in Docker environment)
Find the running containers
: docker ps
Copy the running containerID
: docker exec -it <containerID> bash
: cd /var/jenkins_home/secrets
: cat initialAdminPassword
Use secret password showing in terminal and used as initial password for Jenkins Console.
If you have installed Jenkins via docker, then the following command can give you the initial admin password. Assuming your container name/docker image name is jenkins
docker exec `docker ps | grep jenkins | awk '{ print $1}' ` cat /var/jenkins_home/secrets/initialAdminPassword
docker exec $(docker ps -q) cat /var/jenkins_home/secrets/initialAdminPassword
For me username was: admin
and you can find password by:
docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
my container name is jenkins
Can you install docker-compose and docker toolbox on your Mac?
https://docs.docker.com/compose/install/
Try to execute this docker-compose.yml file:
version: '3.1'
services:
blue-ocean:
image: jenkinsci/blueocean:latest
container_name: blue-ocean
restart: always
environment:
TZ: America/Mexico_City
ports:
- 8080:8080
- 50000:50000
tty: true
volumes:
- ./jenkins-data:/var/jenkins_home
- ./sock:/var/run/docker.sock
Only you need to create a folder with a docker-compose.yml file inside and execute the docker-compose up -d command in terminal, then the folders jenkins-data and sock will be created and inside of jenkins-data appear the directory ./jenkins-data/secrets/initialAdminPassword, open this file and copy the content and paste on the input of web view that requires it.

Resources