Simplifying Docker Interactions with BASH Aliases
Is My Docker Environment Setup?
When working with Docker through Docker Machine, you first have to set up your environment with various DOCKER_* variables, such as these: https://gist.github.com/dtest/9d23ae5f539f0a37db44#file-docker-env-out The first alias is an easy way to check that the Docker environment is setup. https://gist.github.com/dtest/9d23ae5f539f0a37db44#file-de_alias-sh Now, all I have to type is de, and I get the Docker environment output: https://gist.github.com/dtest/9d23ae5f539f0a37db44#file-de-outSetting up My Docker Environment
But how do you set up the environment with Docker Machine? The docker-machine command provides the details: https://gist.github.com/dtest/9d23ae5f539f0a37db44#file-docker_machine_env-out Notice that the comments indicate you have to run the command through eval to get the terminal setup correctly. I don't want to type that out each time I open a new terminal. The docker-machine command requires the name of the VM to set up as an argument, so I've created a function to accept the argument: https://gist.github.com/dtest/9d23ae5f539f0a37db44#file-dm-env_alias-sh Each time I open a terminal I can setup the environment: https://gist.github.com/dtest/9d23ae5f539f0a37db44#file-dm-env-out If you only use one Docker VM for local development, you can hardcode the name of it to execute the command to automatically setup the docker environment when a new terminal is created.Cleaning Out Docker Images
The last helpful alias I have comes from building and re-building containers that have left old images on my VM. https://gist.github.com/dtest/9d23ae5f539f0a37db44#file-dangling_images-out The docker-clean command cleans up all dangling images: https://gist.github.com/dtest/9d23ae5f539f0a37db44#file-docker-clean_alias-sh And running the docker-clean command yields: https://gist.github.com/dtest/9d23ae5f539f0a37db44#file-docker-clean-out I put all of these aliases and functions together in my ~/.bash_profile* script, which is executed anytime I open a terminal window: https://gist.github.com/dtest/9d23ae5f539f0a37db44#file-aliases-sh *Note: Instead of putting these aliases and functions in ~/.bash_profile, other distributions would look for them in ~/.bashrc or ~/.bash_aliases to ensure they are available for all types of interactive shells. If you have any other commands to simplify Docker interactions, please share them in the comments! Discover more about our expertise with DevOps.On this page
Share this
Share this
More resources
Learn more about Pythian by reading the following blogs and articles.
Docker Orientation
Docker Orientation
Jul 1, 2020 12:00:00 AM
9
min read
Using Docker to provide self-service database patching
Using Docker to provide self-service database patching
Nov 20, 2018 12:00:00 AM
12
min read
What you should know about Docker Containers for Oracle Data Integrator
What you should know about Docker Containers for Oracle Data Integrator
Aug 1, 2017 12:00:00 AM
12
min read
Ready to unlock value from your data?
With Pythian, you can accomplish your data transformation goals and more.
