Learn to build and deploy your distributed applications easily to the cloud with Docker.
Installation
This is optional in docker docs, but I recommend not skipping this step
List of useful docker commands
If you are a complete beginner, then I recommend this website.
Note: First go through the article above, it will make these commands more understandable
docker pull busybox
: The pull command fetches the busybox image from the Docker registry and saves it to our system.docker images
: See a list of all docker images on your system.docker run busybox
: Run a Docker container based on the image.docker ps
: Shows you all containers that are currently running.docker ps -a
:List of all containers that we ran.docker run -it busybox sh
: Attaches us to an interactive tty in the container.docker run --help
: See a list of all flags run command supports.docker rmi <image_id>
: Remove a docker image.docker rm $(docker ps -a -q -f status=exited)
: Deleting a bunch of stoped containers.docker container prune
:Deleting bunch of stopped containers (Similar to above - Supports later versions).docker run -d -P --name static-site prakhar1989/static-site
: -d will detach our terminal, -P will publish all exposed ports to random ports, and finally --name corresponds to a name we want to give.docker port static-site
: List the ports of static-site container.docker run -p 8888:80 prakhar1989/static-site
: Specify a custom port to which the client will forward connections to the container. You can access it at localhost:8888 on your browser.docker stop static-site
: Stop a detached container.docker pull ubuntu:18.04
: You can pull a specific version of the ubuntu image.docker build -t yourusername/catnip .
: The docker build command does the heavy lifting of creating a Docker image from a Dockerfile. It is quite simple - it takes an optional tag name with -t and a location of the directory containing the Dockerfile.docker login
: Provide the same credentials that you used for logging into Docker Hub.docker push yourusername/catnip
:To publish, just type the below command remembering to replace the name of the image tag above with yours. It is important to have the format of yourusername/image_name so that the client knows where to publish.docker search elasticsearch
: Search for an image.docker container ls
: Similar to docker ps.docker network ls
: List of networks in docker.docker network inspect bridge
: To inspect the network.docker network create foodtrucks-net
: The network create command creates a new bridge network, which is what we need at the moment. In terms of Docker, a bridge network uses a software bridge which allows containers connected to the same bridge network to communicate, while providing isolation from containers that are not connected to that bridge network.docker container stop es
: Stop a container.docker container rm es
: Remove a container.docker run -d --net foodtrucks-net -p 5000:5000 --name foodtrucks-web prakhar1989/foodtrucks-web
: We can launch our containers inside the custom network using the --net flag.docker-compose up
: Compose is a tool that is used for defining and running multi-container Docker apps in an easy way. It provides a configuration file called docker-compose.yml that can be used to bring up an application and the suite of services it depends on with just one command.docker-compose down -v
: To destroy the cluster and the data volumes. Otherwise, you would have used: docker stop and docker rm.docker-compose up -d
: docker-compose up in detached mode.docker-compose run web bash
: Opens the shell inside the web service.