docker run <image_name | container_id,container_name>
docker run image:version
docker run python:3.6 cat /etc/*release*docker run --name webapp nginx:1.14-alpine
docker run -i <container>
docker run -it <container> // interactive mode with promptsdocker ps
docker ps -a //to list all non-running and exited ones
docker ps -aq // list only ids of containersdocker stop <container_id|name> <container_id2|name> ...
docker stop $(docker ps -aq)docker images
docker rmi <image id>
docker rmi $(docker images -aq) //remove all images, adding q will return only ids in list
docker push username/iamge_name
docker pull
docker pull nginx:1.14-alpinedocker inspect containernamedocker run -p <mapPort>:docker_image_port <container | image>
docker run -v <volumemappedtoPath>:docker_path_volume <container | image>
docker run -d image // Running in detached mode terminal can be closed
docker attach container_id //re attaches to terminal(stops om closing terminal)docker build Dockerfile -t sample_build_name
docker build .
docker build . -t username/image_name
docker image prune -a
docker image tag test x/yFROM ubuntu // image
RUN apt-get update // RUNS commands
RUN apt-get install python
EXPOSE 8080 //used to expose port
WORKDIR ./app //sets CWD same as cd
COPY . /opt/code //copies code from host directory to another inside container
ENTRYPOINT script
CMD ["Default param for entry point"]
docker run -d -e MYSQL_ROOT_PASSWORD=db_pass123 --name mysql-db mysql
docker exec -it mysql-db env //to check env detailsFROM ubuntu
CMD ["sleep","5"] // whole command
OR
FROM UBUNTU
ENTRYPOINT ["Sleep"] //docker run ubuntu-sleeper 10
CMD ["5"] //ifparam not passed default 5 from command is taken
//uses the entry point command and appends the param passed in run command
docker run --entrypoint sleep2.0 ubuntu-sleeper 10 //to override entrypoint command
cat Dockerfile-wordpress | grep CMD
cat Dockerfile-wordpress | grep 'CMD\|ENTRYPOINT'
Links: used to link multiple containers
docker run -p 80:8080 --link image2:image2 image1
//**V1**
image1:
build: ./vote //builds a image from the location Dockerfile and adds
image: node:alpine
links:
- image2
image3:
image: redis
links:
- image1
- image2
ports:
- 80: 8080
//**V2**
version:2
services:
image1: image: node:alpine
networks:
- front-end
image3:
image: redis
networks:
- front-end
- back-end
ports:
- 80: 8080
networks:
- front-end
- back-enddocker run --cpu=.5 --memory=100m ubuntu
**Limits the container to use a max of 50% of cpu**Docker user storage driver based on OS
docker volume create data_volume // Creates A volume folder under /var/lib/docker/*
docker run -v /data/test:/var/lib/* image //mount binding of any host location too
docker run -v data_volume:/var/lib/* image //volume binding in dockerDocker has embedded DNS server for images/containers to interact. By default each container has a default isolated network and users can create networks and attach
Host : link host network, so container and host share same network
none
bridge: port mapping method
docker network ls
docker network inspect bridge
docker network inspect wp-mysql-network
docker run --name alpine-2 --network=none alpine //no network
docker network create --driver \
bridge --subnet 182.18.0.1/24\
--gateway 182.18.0.1 wp-mysql-networkperforms load balancing ,auto-scaling and monitoring
Docker swarm
Kubernetes
MESOs
docker service create --replicas=100 nodejs