Mới chuyển qua dùng docker thay vì dùng vagrant, cảm giác là docker chạy rất nhanh và ko làm chậm hệ thống. Dưới đây là một số lệnh hay dùng trong Docker:
Docker cơ bản
Pull một image từ Docker Hub
docker pull {image_name}
Liệt kê các images hiện có
docker images
Xóa một image
docker rmi {image_id/name}
Liệt kê các container đang chạy
docker ps
docker ps -a #Liệt kê các container đã tắt
Xóa một container
docker rm -f {container_id/name}
Đổi tên một container
docker rename {old_container_name} {new_container_name}
Khởi động một container
docker start {new_container_name}
docker exec -it {new_container_name} /bin/bash
Tạo mới một container, đồng thời khởi động với tùy chọn cổng và volume
docker run --name {container_name} -p {host_port}:{container_port} -v {/host_path}:{/container_path} -it {image_name} /bin/bash
Xem các thay đổi trên container
docker diff {container_name}
Commit các thay đổi trên container và image
docker commit -m "message" {container_name} {image_name}
Save image thành file .tar
docker save {image_name} > {/host_path/new_image.tar}
Tạo một image mới từ file .tar
cat musashi.tar | docker import - {new_image_name}:latest
Xem lịch sử các commit trên image
docker history {image_name}
Khôi phục lại images từ IMAGE_ID
docker tag {iamge_id} {image_new_name}:{tag}
Build một image từ container
docker build -t {container_name} .
//Dấu . ở đây ám chỉ Dockerfile đang nằm trong thư mục hiện tại.
Docker nâng cao
List all containers (only IDs)
docker ps -aq
Stop all running containers
docker stop $(docker ps -aq)
Remove all containers
docker rm $(docker ps -aq)
Remove all images
docker rmi $(docker images -q)
docker rmi -f $(docker images -q)
Docker và laravel
Thực thi lệnh php artisan
docker-compose exec app php artisan key:generate
docker-compose exec app php artisan cache:clear
docker-compose exec app php artisan config:cache
Nếu chạy với lệnh php artisan clear... sẽ bị lỗi không tìm thấy view
Tham khảo cách cài môi trường
https://kipalog.com/posts/Cai-dat-moi-truong-cho-laravel-dung-docker