Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
Docker is a great tool for building microservices, allowing you to create cloud-based applications and systems. To make the most of it via your terminal, here is a run down of the top 10 Docker commands for your terminal.
A container is launched by running an image. An image is an executable package that includes everything needed to run an application–the code, a runtime, libraries, environment variables, and configuration files.A container is a runtime instance of an image–what the image becomes in memory when executed (that is, an image with state, or a user process). You can see a list of your running containers with the command, docker ps, just as you would in Linux. — from Docker Concepts
- docker ps — Lists running containers. Some useful flags include: -a / -all for all containers (default shows just running) and —-quiet /-q to list just their ids (useful for when you want to get all the containers).
- docker pull — Most of your images will be created on top of a base image from the Docker Hub registry. Docker Hub contains many pre-built images that you can pull and try without needing to define and configure your own. To download a particular image, or set of images (i.e., a repository), use docker pull.
- docker build — The docker build command builds Docker images from a Dockerfile and a “context”. A build’s context is the set of files located in the specified PATH or URL. Use the -t flag to label the image, for example docker build -t my_container . with the . at the end signalling to build using the currently directory.
- docker run — Run a docker container based on an image, you can follow this on with other commands, such as -it bash to then run bash from within the container. docker run my_image -it bash
- docker logs — Use this command to display the logs of a container, you must specify a container and can use flags, such as --follow to follow the output in the logs of using the program. docker logs --follow my_container
- docker volume ls — This lists the volumes, which are the preferred mechanism for persisting data generated by and used by Docker containers.
- docker rm — Removes one or more containers. docker rm my_container
- docker rmi — Removes one or more images. docker rmi my_image
- docker stop — Stops one or more containers. docker stop my_container A more direct way is to use docker kill my_container , which does not attempt to shut down the process gracefully first.
- Use them together, for example to clean up all your docker images and containers:
- kill all running containers with docker kill $(docker ps -q)
- delete all stopped containers with docker rm $(docker ps -a -q)
- delete all images with docker rmi $(docker images -q)
For more on how you remove specific containers and images see my post:- How I filter and grep Docker containers, images, and volumes and how you can tooFor even more suggestions on cleaning up after using docker- Yohan Liyanage’s blog post Docker — Clean Up After Yourself!
There are lots more docker commands, flags and combinations to learn and use. Keep trying them out and they should become second nature.
This is just the start though, docker-compose is a tool to define multiple docker containers that work together in an application. To continue reading about docker-compose commands see my post: The ups and downs of docker-compose — how to run multi-container applications
Read more from Ryan Davidson
- Published in Hackernoon — To boldly log: debug Docker apps effectively using logs options, tail and grep
- Published in Hackernoon — Clean out your Docker images, containers and volumes with single commands
- Posts on: Docker
- My software development posts by topic
Read more on Medium
- Adnan Rahić in blog.sourcerer.io — A crash course on Docker — Learn to swim with the big fish
- Preethi Kasireddy in medium.freecodecamp.org — A Beginner-Friendly Introduction to Containers, VMs and Docker
- Praveen Durairaj in blog.hasura.io — An Exhaustive Guide to Writing Dockerfiles for Node.js Web Apps
Read more from the web
- Docker’s homepage
- Docker concepts
- Docker’s docs on command line commands
- More on microservices from Pivotal
- Docker — Clean Up After Yourself!
Top 10 Docker commands you can’t live without was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.