Skip to content

Instantly share code, notes, and snippets.

@AhmedHelalAhmed
Last active July 5, 2023 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save AhmedHelalAhmed/cfd425d6fb0be51b4415452f6a8ec553 to your computer and use it in GitHub Desktop.
Save AhmedHelalAhmed/cfd425d6fb0be51b4415452f6a8ec553 to your computer and use it in GitHub Desktop.
docker
APP_NAME="log time status app"
APP_ENV=local
APP_KEY=base64:vwuZxLP3hiI4YbBHZ2pIKOrqdWfmcq3XNFdFqkM4lBs=
APP_DEBUG=true
APP_URL=http://testing.local
LOG_CHANNEL=stack
LOG_LEVEL=debug
DB_CONNECTION=mysql
DB_HOST=database_server
DB_PORT=3306
DB_DATABASE=log-time-status-app
DB_USERNAME=root
DB_PASSWORD=root
BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
MEMCACHED_HOST=127.0.0.1
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=mailhog
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
AWS_USE_PATH_STYLE_ENDPOINT=false
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
DOCKER_NAME="log_time_status_app"
USER=ahmedhelalahmed
UID=1000 # id command in the terminal to get user id of current user
ps aux
id www-data
<VirtualHost *:80>
ServerName localhost
ServerAdmin webmaster@localhost
DocumentRoot /var/www/app/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
https://docker.com/
https://labs.play-with-docker.com/
docker build .
docker run -p 3000:3000 image_id
docker ps # to get container name
docker stop container_name
docker run node
docker ps -a
docker run -it node
ctrl + c #close the terminal shell of the docker
version: '3'
services:
web:
container_name: ${DOCKER_NAME}_web
build:
context: .
args:
user: ${USER}
uid: ${UID}
ports:
- "80:80"
volumes:
- ./:/var/www/app
depends_on:
- database_server
database_server:
container_name: ${DOCKER_NAME}_database
image: mysql:5.7
ports:
- "3306:3306"
restart: always
volumes:
- ./storage/app/mysql:/var/lib/mysql
environment:
- MYSQL_DATABASE=log-time-status-app
- MYSQL_ROOT_PASSWORD=root
- SERVICE_NAME=mysql
phpmyadmin:
container_name: ${DOCKER_NAME}_phpmyadmin
image: phpmyadmin/phpmyadmin
restart: always
ports:
- "8080:80"
depends_on:
- database_server
environment:
PMA_HOST: database_server
PMA_PORT: 3306
PMA_USER: root
PMA_PASSWORD: root
sudo docker-compose up
sudo docker-compose exec web /bin/bash
sudo docker-compose exec fpm /bin/bash
docker volume ls
docker volume inspect volume_name
docker ps
sudo groupadd docker
sudo usermod -aG docker ahmedhelalahmed
docker info
docker --version
sudo usermod -a -G docker ahmedhelalahmed
docker images
docker run hello-world
sudo service docker stop
docker version
docker -v
docker --help
docker login
docker images
docker pull
docker rmi
docker ps
docker run
docker start
docker stop
docker stats
docker system df
docker system prune
docker-compose config
docker-compose ps
docker-compose up -d --scale database=4
sudo docker-compose up --build
docker-compose up -d --force-recreate --no-deps --build
docker-compose up --force-recreate --no-deps --build
FROM php:7.4.24-apache
RUN apt-get update -yqq && \
apt-get install -y apt-utils zip unzip && \
apt-get install -y nano && \
apt-get install -y git && \
apt-get install -y nodejs && \
apt-get install -y npm && \
apt-get install -y libzip-dev && \
a2enmod rewrite && \
docker-php-ext-install mysqli pdo pdo_mysql && \
docker-php-ext-configure zip && \
docker-php-ext-install zip && \
rm -rf /var/lib/apt/lists/*
RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer
COPY /app/Scripts/default.conf /etc/apache2/sites-enabled/000-default.conf
ARG user
ARG uid
RUN useradd -u $uid $user
RUN mkdir /home/$user/
RUN chown -R $user:$user /var/www/html
RUN chown -R $user:$user /home/$user/
USER $user
WORKDIR /var/www/app
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
EXPOSE 80
@AhmedHelalAhmed
Copy link
Author

docker run --rm -i -t -v $PWD:/app composer create-project --prefer-dist laravel/laravel example-app

https://github.com/composer/docker/blob/582c6f4e10b6b8fbf9bc1c5b02d6ec24694fe8d4/2.0/Dockerfile#L60

@AhmedHelalAhmed
Copy link
Author

docker run --rm -i -t -v $PWD:/app composer create-project --prefer-dist laravel/laravel daleel; sudo chown ahmedhelalahmed:ahmedhelalahmed -R daleel

@AhmedHelalAhmed
Copy link
Author

sudo chown -R ahmedhelalahmed:ahmedhelalahmed storage/

@AhmedHelalAhmed
Copy link
Author

@AhmedHelalAhmed
Copy link
Author

@AhmedHelalAhmed
Copy link
Author

composer create-project --prefer-dist laravel/laravel . "6.*"

@AhmedHelalAhmed
Copy link
Author

docker run --rm -i -t -v $PWD:/app composer create-project --prefer-dist laravel/laravel . "6.*"; sudo chown ahmedhelalahmed:ahmedhelalahmed -R daleel

@AhmedHelalAhmed
Copy link
Author

docker install

sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install -y docker-ce
sudo groupadd docker
sudo usermod -aG docker $USER
sudo systemctl enable docker
sudo service docker stop
sudo mv /var/lib/docker /home
sudo ln -s /home/docker /var/lib/
sudo service docker start

@AhmedHelalAhmed
Copy link
Author

Python-PIP (Required for installing docker-compose and login in AWS)
sudo apt-get install -y python3-pip
Docker-compose (Managing containers)
sudo pip install docker-compose
MySQL (Required for importing database dumps)
sudo apt-get install -y mysql-client

@AhmedHelalAhmed
Copy link
Author

Install AWS-CLI (If you have issues with permissions, add sudo to the command)
pip install --upgrade --user awscli
or
sudo apt  install awscli

@AhmedHelalAhmed
Copy link
Author

steps for new project
docker run --rm -i -t -v $PWD:/app composer create-project --prefer-dist laravel/laravel blogging-platform

@AhmedHelalAhmed
Copy link
Author

docker-compose up -d --build

@AhmedHelalAhmed
Copy link
Author

docker-compose run --rm composer require laravel/laravel

@AhmedHelalAhmed
Copy link
Author

AhmedHelalAhmed commented Jan 23, 2023

docker-compose exec php php /var/www/artisan migrate

@AhmedHelalAhmed
Copy link
Author

docker-compose exec php php /var/www/html/project/artisan migrate

@AhmedHelalAhmed
Copy link
Author

docker-compose run artisan queue:work

@AhmedHelalAhmed
Copy link
Author

order_product

order_user

docker-compose run artisan make:migration create_ingredient_product_table

docker-compose run artisan make:migration create_order_product_table

docker-compose run artisan make:seeder UserSeeder




docker-compose run artisan make:seeder UserSeeder
docker-compose run artisan make:seeder IngredientSeeder
docker-compose run artisan make:seeder OrderSeeder

@AhmedHelalAhmed
Copy link
Author

ab -n 2 -c 2 http://localhost:80/

@AhmedHelalAhmed
Copy link
Author

AhmedHelalAhmed commented Jan 24, 2023

    if (\App\Models\Ingredient::lockForUpdate()->first()->stock == 0) {
        \App\Models\Ingredient::first()->increment('stock');
    }

    \Illuminate\Support\Facades\DB::beginTransaction();
    if (\App\Models\Ingredient::first()->stock == 0) {
        \App\Models\Ingredient::first()->increment('stock');
    }
    \Illuminate\Support\Facades\DB::commit();

    if (\App\Models\Ingredient::first()->stock == 0) {
        \App\Models\Ingredient::first()->increment('stock');
    }


@AhmedHelalAhmed
Copy link
Author

AhmedHelalAhmed commented Jan 26, 2023

only docker

run composer

docker run --rm -i -t -v $PWD:/app composer install

run php script

docker container run --rm -v $(pwd):/app/ php php /app/artisan

node & npm

docker container run --rm -v $(pwd):/app/ -w /app node npm install

build

docker container run --rm -v $(pwd):/app/ -w /app node npm run build

@AhmedHelalAhmed
Copy link
Author

AhmedHelalAhmed commented Mar 8, 2023

Installing Docker on Linux
These steps listed below are for Ubuntu Desktop LTS. You can find the full official docs and steps for other Linux distributions here:

Ubuntu: https://docs.docker.com/install/linux/docker-ce/ubuntu/

CentOS: https://docs.docker.com/install/linux/docker-ce/centos/
(Note: Students have encountered issues when using CentOS or RHEL as the host related to Docker container communication. You may need to research some workaround for the errors you run into or search the QA for already posted solutions)

Debian: https://docs.docker.com/install/linux/docker-ce/debian/

Installation Steps
Create Dockerhub account
https://hub.docker.com/signup

Install Docker
The Docker docs suggest setting up a Docker repository to install and update from.
This is where you should start: https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository

Login to the Dockerhub
In order to push and pull images, you will need to login to the Dockerhub. In your terminal, run docker login and then enter your Dockerhub account's username and password.

Test Docker installation
After completing the installation steps, test out Docker by running sudo docker run hello-world. This should download and run the test container printing "hello world" to your console.

Installing Docker Compose
Navigate to the installation page:
https://docs.docker.com/compose/install/#install-compose-as-standalone-binary-on-linux-systems
Click the Linux Standalone Binary Tab:

Then, CTL+F to search for the Install Compose as standalone binary on Linux systems section on the page. Follow the instructions provided there to install the latest Docker Compose binary.

Testing Docker Compose
After completing, test your installation by running docker-compose -v. This should print the version and build numbers to your console.

Run without Sudo
Follow these instructions to run Docker commands without sudo:
https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user

Start on Boot
Follow these instructions so that Docker and its services start automatically on boot:
https://docs.docker.com/install/linux/linux-postinstall/#configure-docker-to-start-on-boot

You may need to restart your system before starting the course material.

https://jumia.udemy.com/course/docker-and-kubernetes-the-complete-guide/learn/lecture/12920904#overview

@AhmedHelalAhmed
Copy link
Author

mysql -h 127.0.0.1 -u root -p

@AhmedHelalAhmed
Copy link
Author

crontab -e

laravel worker

sudo apt-get install supervisor
cd /etc/supervisor/conf.d/

touch fresh_testcron_worker.conf

fresh_communicare_worker.conf

[program:fresh_communicare_worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/fresh_sales/artisan run:worker communicare
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=heba-mahdy
numprocs=8
redirect_stderr=true
stdout_logfile=/var/www/html/fresh_sales/storage/logs/worker.log
stopwaitsecs=3600

sudo supervisorctl reread

sudo supervisorctl update

sudo supervisorctl stop fresh_testcron_worker:*

@AhmedHelalAhmed
Copy link
Author

AhmedHelalAhmed commented Apr 11, 2023

--timeout=0
solve the issue of kill when it put as option to php artisan queue:work

https://stackoverflow.com/questions/45565824/laravel-database-queue-killed-after-a-few-seconds

php artisan queue:work --timeout=0

@AhmedHelalAhmed
Copy link
Author

docker run --rm -i -t -v $PWD:/app composer create-project --prefer-dist laravel/laravel booking.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment