1. MacOS Docker-related commands are automatically completed
Non-mac users can skip to the next tip.
Now that you’ve installed Docker for MAC, you’ll need to install bash-Completion first
brew install bash-completion
Copy the code
Then configure.bashrc
if [ -f $(brew --prefix)/etc/bash_completion ]; then. $(brew --prefix)/etc/bash_completionfi
Copy the code
Finally, soft link is good, restart the shell, feel the pleasure brought by two TAB auto-completion.
cd /usr/local/etc/bash_completion.dln -s /Applications/Docker.app/Contents/Resources/etc/docker.bash-completionln -s /Applications/Docker.app/Contents/Resources/etc/docker-machine.bash-completionln -s /Applications/Docker.app/Contents/Resources/etc/docker-compose.bash-completion
Copy the code
2. View the docker build Context
When constructing Docker images, we can improve the speed of image construction by reasonably controlling the context during construction. Of course first we’re going to say.dockerignore to restrict what’s in the context. But sometimes we want to see what the context actually has, and if there’s room to squeeze it. Create an image using the following docker file in the directory where the context resides, and then run the image to view the contents of the current context.
FROM busyboxCOPY . /tmp
Copy the code
But every time you always need to write such a dockerfile is also quite troublesome, you can do the following alias, will be more pleasant. Execute context-image if necessary.
alias context-image='printf "FROM busybox \nCOPY . /tmp\n" | docker build -t context -f - .'
Copy the code
Please accept the last thing at the bottom of the box
Finally, I want to share a few things about the bottom of the Docker box. Although the installation of autocomplete is convenient, but there is always lazy to steal.
Run a Docker Image quickly
function dockerimageshell(){ docker run --rm -it $@ /bin/sh}
Copy the code
For example, the context image created by the previous Tip can be quickly viewed using this function; Add parameters such as -v -p to control the mapping
dockerimageshell context
Quickly enter a container shell.
function dockercontainershell(){ docker exec -it $1 /bin/sh}
Copy the code
Either the hash or the name of the container can be used to quickly enter the shell of the container.
Clear docker resources
And one last clean up, like the context image that we just created, don’t waste space in the system after you look at it. The following functions not only clean up the image, but also the various volumes and networks.
function dockercls(){ docker system prune}
Copy the code
END
Just three tips that I hope you found useful.