- virtual file system
- port binded: talk to application running inside of container
- application image: postgres, redis mongo, nginx, python (etc)
- how to search a docker image in hub.docker.com from CLI
- docker search httpd
- Download a docker image from hub.docker.com
- docker image pull <image_name>:<image_version/tag>
- List out docker images from your local system
- docker images or
- docker image ls
- Create/run/start a docker container from image
- docker run -d --name <container_Name> <image_name>:<image_version/tag>
- d - run your container in back ground (detached)
- Expose your application to host server
- docker run -d -p <host_port>:<container_port> --name <container_Name> <image_name>:<Image_version/tag>
- docker run -d -p 8080:80 -p 3000:80 --name starwars httpd:2.3
if the above command isn't working use the following
- docker run -d --restart unless-stopped -p <host_port>:<container_port> --name <container_Name> <image_name>:<Image_version/tag>
- EXAMPLE: docker run -d --name httpd_server -p 8080:80 httpd:2.2
- List out running containers
- docker ps
- List out all docker container (running, stpooed, terminated, etc...)
- docker ps -a
- run a OS based container which interactive mode (nothing but login to container after it is up and running)
- docker run -i -t --name centos_server centos:latest
- i - interactive
- t - Terminal
- Stop a container
- docker stop <container_id>
- Start a container which is in stopped or exit state
- docker start <container_id>
- Remove a container (Can not remove a running container)
- docker rm <container_id>
- login to a docker container
- docker exec -it <container_Name> /bin/bash
- Pull only Container Ids
- docker ps -aq
- Delete multiple containers
- docker rm $(docker ps -aq)
- docker rmi $(docker images -aq)
- Format Container
- docker ps --format="ID\t{{.ID}}\nNAME\t{{.Names}}\nIMAGE\t{{.Image}}\nPORTS\t{{.Ports}}\nCOMMAND\t{{.Command}}\nCREATED\t{{.CreatedAt}}\nSTATUS\t{{.Status}}\n"
- Run Dockerfile to create image (Dockerfile - Contains a series of steps that define how your image is build.)
- docker build . -t httpd:latest
- "t" tag
- Docker run
- docker run -p 8080:8080 httpd:latest
- Docker Volumes (allow sharing of data between files, folders & containers)
- (example to share files between local and container run) docker run -d --name website -v $(pwd):/usr/share/nginx/html:ro -p 8080:80 nginx:latest
- "ro" read only. If we want to write then we need to remove "ro"
- (example to share files between containers)
- docker run -d --name website-copy --volumes-from website -p 8081:80 nginx
- Docker compose up & down commands
- docker-compose -f docker-compose.yaml up -d
- docker-compose -f docker-compose.yaml down
- Docker network
- docker network ls
- docker network create <network_name>