Notes
Problems that Docker Solve
Docker
- Container → Single unit that contains app + dependencies.
- Properties :
- Portable → Shared as “Images”
- Light weight
- Image → Executable file that have instructions to build multiple containers.
- Tags → versions of the image
- Docker Image “Layers”
- Port Binding → Map host port with container port
- Troubleshoot commands
Docker Commands
docker run -it <image_name> {Interactive mode -it }
docker run -d <image_name> {Detached mode -d }
docker run --name <user_defined_container_name> <image_name> → To give custom name for any container
docker run -p8080:3306 <image_name> → To bind the port { -pHostPort:ContainerPort }
- To create a container from the image.
- This command can also pull image and create a container from it directly if the image is not available locally.
- Ex:
docker run -it ubuntu
docker → To check if docker is installed
docker -v → To check the version of docker
docker pull <image_name>:tag
- To download any docker image
- Default tag is “latest”
- Ex:
docker pull mysql:8.0
docker images → To list images
docker ps -a → To list all the containers
docker ps → To list all the running containers
docker start <container_name OR container_id> → To start the existing container
docker stop <container_name OR container_id> → To stop the running container
docker rmi <image_name OR image_id> → Delete the image [First remove the container of that image]
docker rm <container_name OR container_id> → Delete the container
docker exec -it <container_id> /bin/bash
docker exec -it <container_id> /bin/sh
docker network ls
docker network create <network_name>
References