Introduction To Docker Commands
Docker implies OS-level virtualization. Most developer prefers using docker and operating systems are tightly coupled with developers. Optimizing on the platform’s functionality kicks with docker commands mastery. They are very much lightweight VM’.
- docker –version – Display the current version
- docker pull <image> – Docker repository images can be pulled using docker pull command
docker pull ubuntu
- docker run -it -d <image name> – For generating a container from an image
docker run -it -d ubuntu
- docker ps -a – Displays running and exited containers
- docker exec -it <container id> bash – Command for accessing running container
- docker kill <container id> – Command for stopping the execution of a container immediately
docker kill d61153bc
- docker commit <container id> <username/image name> – This command creates a new image of an edited container on the local system
- docker push <username/image name> – This Docker command is used to push an image to docker hub repository
- docker images – Listing all images stored in a docker
- docker rm <container id> – Deleting a container which has stopped execution
Docker Intermediate Commands
- docker checkpoint command – This Docker command used for managing checkpoints
- docker save [OPTIONS] IMAGE [IMAGE…] – Saving more than one images to tar archives
docker save --output testbox.tar textbox
- docker search [OPTIONS] TERM – Searching docker hub for images
docker search textbox
- docker stats [OPTIONS] [CONTAINER…] – Displaying resource usage statistics
- docker system command – It is Used for Managing a docker
|docker system df||Show docker disk usage|
|docker system events||Get real-time events from the server|
|docker system info||Display system-wide information|
|docker system prune||Remove unused data|
- docker tag SOURCE_IMAGE[: TAG] TARGET_IMAGE[: TAG] – Creating a target image referring to a source image
docker tag 0e5574283393 fedora/httpd:version1.0
- docker unpause CONTAINER [CONTAINER…] – Unpause all process within one or more containers
docker unpause test container
- docker import [OPTIONS] file|URL|- [REPOSITORY[: TAG]] – Importing contents from tarball to create a system image of the file
- docker info [OPTIONS] – Display system-wide information
docker info -f
- docker logout [SERVER] – Logging out of a Docker registry
- docker-machine upgrade default – To upgrade the docker to the latest version. How this upgrade happens depends on the underlying distribution used on the created instance.
- docker build –rm=false – Boolean options take the form -d=false. The value you see in the help text is the default value which is set if you do not specify that flag. If you specify a Boolean flag without a value, this will set the flag to true, irrespective of the default value.
Trips and Tricks To Use Docker Commands
- Use -f flag for activating the logging
docker logs <containerid> -f
- JSON split can be achieved in docker by default, single keys can be extracted using jq.
- Package installations have to be taken increased care as those commands are cached as well.
- There are a few places where one can specify commands in your Docker file.
- A cache will be invalidated by add when the files are changed
- At the time of building the image, there is no use of writing to the volumes
- All users are determined from the host hence there is no user namespacing docker.
- Sudo helps to execute the commands
- Starting a docker into execution is a comparatively easy process
- Docker allows the creation of aliases for its own commands in a very effective manner. This helps to manage and handle long and really large commands. Files ~/.bashrcor ~/.bash_aliases holds the alias values.
- For reaching out containers accessed internally on a network there is always a need to withhold the corresponding ID of the container, the command ps -a helps to get this archived.
- When a needed port is occupied on a different service, then for executing a container the host port can be plugged on a specific container port.Eg(host port 8080 to container port 50)
- Docker provides additional support to clean the unnecessary code bits from the deployment container.
- Its always set to pair the docker file associated to its respective run statements. This helps to solve problems as like prescribed excluding unnecessary disk space usage.
- Docker always prefers catching up statements in the docker file that has not faced any change. Time-saving can be achieved by setting the contents depicted in the docker file at an order were least possible change contents are mentioned at the top and more likely change contents are depicted at the bottom of the file.
Though docker seems to be an easy setup it’s actually a complex system to handle when considering its vibrant features into a picture. Definitely, Docker is among the popular virtualization tools and allows extremely coupled with the host operating system.
This has been a guide to Docker Commands. Here we have discussed basic, immediate as well as advanced Docker Commands. You may also look at the following articles to learn more.