- Docker
- Advantage Of Docker
- Container
- Image
- Registry
- Docker Client
- Docker Daemon
- Docker Architecture
- Docker Commands
- Dockerfile
- Docker Compose
- Docker Swarm
- Kubarnetes
- Docker Commit
- Is a free software, allows users to create isolated environments to launch and deploy its applications.
- These are called containers.
- Is a container management service.
- Lightweight.
- Simple & Fast deployment.
- Portability.
- Start up in milliseconds.
- Performance.
- Multiple containers.
- Keep your workspace clean.
- Runnable instance of an image.
- You can start, stop, or remove.
- Template with instructions for creating docker container.
- You may build your image.
- Stores docker images.
- Docker hub is the default public registry.
- is the primary way that many Docker users interact with Docker.
- listens for Docker API requests and manages Docker objects such as images, containers, networks, and volumes.
-
Docker version
docker --version
docker -v
-
List all containers
docker container ls
List currently running containersdocker container ls -a
List all docker containers (running and stopped)docker ps
docker ps -a
-
Remove a stopped container
docker container rm <container_name>
docker rm <container_name>
-
Delete all containers (only if stopped)
docker rm $(docker ps -a -q)
-
Start or stop an existing container
docker start|stop <container_name> (or <container-id>)
-
Stop all running containers
-
docker stop $(docker ps -a -q)
-
Create and run a container from an image, with a custom name
-
docker run --name <container_name> <image_name>
-
If the image doesn't exist on your local machine, the docker daemon get it from the docker hub (registry).
-
If you don't specify the tag of the image, it pulled the latest version.
-
-
Run a container in the background
docker run -d <image_name>
-
Run a container with and publish a container’s port(s) to the host
docker run -p <host_port>:<container_port> <image_name>
-
List all images
docker images
-
Delete an Image
docker image rm <image_name>
docker rmi <image_name>
-
Delete all existing images
-
docker image rm $(docker images -a -q)
-
Remove all unused images
docker image prune
-
Pull an image from a Docker Hub
docker pull <image_name>
-
Inspect a running container
docker inspect <container_name> (or <container_id>)
-
Fetch the logs of a container:
docker logs <container_name>
-
Display a live stream of container(s) resource usage statistics
docker stats <container_name> (or <container_id>)
docker stats
** all containers**
-
Display system-wide information memory, cpu, version, images, containers count
docker info
-
Run Container with full example
docker run -d -p 80:80 --name n1 --network=networkName -v=pathLocal:/pathContainer ngnix
-
Interact with container
docker exec -it <container_name> (or <container_id>) command
docker exec -it n1 bash
- A Dockerfile must begin with a FROM instruction.
- add comment with
#
. - CMD ["command", "argument"].
- ENTRYPOINT ["command", "argument"].
- To build image with the Dockerfile, which it on the same path:
docker build .
docker build --tag tagName .
-
Tool for running multiple containers with
docker-compose.yml
file on the same host. -
Is very useful to build your env as a one package.
docker-composer -v
- we consider the service as a container.
- we use
docker-compose.yml
ordocker-compose.yaml
to build the env.
-
Docker-compose Commands:
docker-compose start
docker-compose stop
docker-compose pause
docker-compose unpause
docker-compose ps
docker-compose up
docker-compose down
- Container orchestration tool allows you to run & connect containers on multiple hosts.
- Container orchestration tool like docker swarm, but it is more popular and work with large scale.
-
Convert running container to an image.
docker commit <container-name> new-name-img:v1
- docker ps
- docker container ls
- docker ps --all
- docker container ls --all
- docker run nginx
- docker container stop container_id
- docker container kill container_id
- --publish :
- --p :
- docker run --p 8080:80 nginx
- visit localhost:8080
- -d
- --detach
- docker run -d --p 8080:80 nginx
- visit localhost:8080
- --name
- docker run -d --p 8080:80 --name nginx-orcas nginx
- visit nginx-orcas
- docker container rename nginx-orcas nginx-orcas-2
- docker container rm nginx-orcas-2
- docker container create nginx
- docker container start container_id
- docker run --rm -p 8080:80 nginx
- --volume :
- -v :
- docker images
- docker image ls
- docker image rm image_id
- docker rmi image_id
- docker image pull nginx
- docker build .
- The daemon finds any file named Dockerfile within the context.
- docker network ls
- docker network ls
- The default networking driver in Docker. This can be used when multiple containers are running in standard mode and needs to communicate with each other.
- docker network create
- docker network connect
- --network
- docker container run --network orcas --rm alpine
- docker network disconnect
- docker network rm
- Just like the Docker daemon uses a Dockerfile for building images, Docker Compose uses docker-compose.yaml file to read service definitions from.
- docker-compose up
- docker-compose --file docker-compose.yaml up --detach
- docker-compose ps //listing services
- docker-compose exec // Executing Commands Inside a Running Service
- docker-compose down
- docker-compose logs
docker-compose up -d
- create the path for mysql.
- create the path for nginx and conf file.
- create the path for php and conf file.
- create the path for project.
- download app and change .env files. with the host of mysql service name.
- change permissions of storage path.
sudo chmod 777 -R storage/
- exec for php service php artisan migrate.
- default.conf file in nginx
fastcgi_pass php:9000;
php refer to the service name and its port 9000
- nginx - :8070
- mysql - :3309
- php - :9000
- phpmyadmin - :8081