Commands which are available to use in Docker to play with images or containers
## Download/Pull an image
docker pull alpine ## alpine is an images located in local or docker hub repository
## List Docker images available locally
docker images
## Run Docker images
docker run alpine ls -l #run command will look for image alpine locally if does not exist it will pull from docker hub, creates container and start/run a command in that container
docker run alpine echo "hello from alpine"
docker run alpine /bin/sh
Wait, nothing happened! Is that a bug? Well, no. These interactive shells will exit after running any scripted commands, unless they are run in an interactive terminal - so for this example to not exit, you need to
## List running containers
docker ps
## List all containers we ran
docker ps -a
## Run a container with attached tty
docker run -it alpine /bin/sh
This will drop you at /bin/sh shell in container (with tty) where you can run any command as similar to on OS
docker run -it alpine /bin/sh
/ # df -h
## Download/Pull an image
docker pull alpine ## alpine is an images located in local or docker hub repository
## List Docker images available locally
docker images
## Run Docker images
docker run alpine ls -l #run command will look for image alpine locally if does not exist it will pull from docker hub, creates container and start/run a command in that container
docker run alpine echo "hello from alpine"
docker run alpine /bin/sh
Wait, nothing happened! Is that a bug? Well, no. These interactive shells will exit after running any scripted commands, unless they are run in an interactive terminal - so for this example to not exit, you need to
docker run -it alpine /bin/sh
## List running containers
docker ps
## List all containers we ran
docker ps -a
## Run a container with attached tty
docker run -it alpine /bin/sh
This will drop you at /bin/sh shell in container (with tty) where you can run any command as similar to on OS
docker run -it alpine /bin/sh
/ # df -h
Filesystem Size Used Available Use% Mounted on
none 18.1G 1.8G 15.3G 11% /
tmpfs 496.2M 0 496.2M 0% /dev
tmpfs 496.2M 0 496.2M 0% /sys/fs/cgroup
/dev/mapper/dockertest--vg-root
18.1G 1.8G 15.3G 11% /etc/resolv.conf
/dev/mapper/dockertest--vg-root
18.1G 1.8G 15.3G 11% /etc/hostname
/dev/mapper/dockertest--vg-root
18.1G 1.8G 15.3G 11% /etc/hosts
shm 64.0M 0 64.0M 0% /dev/shm
tmpfs 496.2M 0 496.2M 0% /proc/kcore
tmpfs 496.2M 0 496.2M 0% /proc/timer_list
tmpfs 496.2M 0 496.2M 0% /proc/timer_stats
tmpfs 496.2M 0 496.2M 0% /proc/sched_debug
tmpfs 496.2M 0 496.2M 0% /sys/firmware
## Inspect any image/container. INSPECT will Return low-level information on a container or image in JSON format
docker inspect alpine
Terminologies
- Images - The file system and configuration of our application which are used to create containers
- Containers - Running instances of Docker images — containers run the actual applications. A container includes an application and all of its dependencies. It shares the kernel with other containers, and runs as an isolated process in user space on the host OS
- Docker daemon - The background service running on the host that manages building, running and distributing Docker containers
- Docker client - The command line tool that allows the user to interact with the Docker daemon
- Docker Hub - A registry of Docker images. You can think of the registry as a directory of all available Docker images
No comments:
Post a Comment