Isn’t documentation really helpul!? Working on multiple DevOps tools, I tend to mistype the commands or confuse one with the other. So here is my Docker cheat sheet –
- docker –help – Displays help menu
- docker –version – Displays docker version
- docker version – Displays docker version for both Docker client and daemon
- docker image ls -a – Displays a list of all Docker images
- docker container ls -a – Display a list of all Docker containers
- docker rm $(docker ps -a -q) – Removes all Docker containers in quiet mode
docker rmi -f $(docker images -q) – Removed all Docker images in quiet mode
docker run -it helloworld/1.0 sh – Propmts a shell to view the contents of Docker image
docker build -t helloworld:1.0 . – Build a docker image with the name “helloworld” and tag ‘1.0’. Pay attention to the ‘dot’ at the end of the command. It implies ‘Dockerfile’ in your local directory be used
docker run -p 8888:5000 helloworld:1.0 – Instantiate the running instance of a Docker image ‘helloworld”. Port 5000 is exposed on the container and is mapped to 8888 on the host machine
- docker login – Authenticates a user to the cloud Docker public/private repository
docker tag helloworld:1.0 username/myrepo:1.0 – Tag a local image to specific docker repository and the user
docker push crkatz/myrepo:1.0 – Pushes the tagged image to the docker public or private repository
docker container logs [OPTIONS] CONTAINERID – Tails the logs of the Docker container
Developing an application in its own virtualenv is vital. Virtual envs help isolate python envrionments and enable you to install dependant packages in this isolated environment rather than globally.
- First find out the version of python you installed. I have python 2.7 default install on MacOS and python 3 via Homebrew package manager for MacOS
- Python packages required – virtualenv, virtualenvwrapper.
pip3 install virtualenv virtualenvwrapper #pip3 is using python3 interpretor
- Virtualenv package enables you to create project/application specific virtual env. Virtualenvwrapper is an extension of Virtualenv. It helps create,manage and delete virtual envs making it easier to work on more than one project at a time eliminating conflicts.
- Add the below lines to the ~/.bash_profile
#tells which interpretor to use. In this case ‘python3’
#set the env variable and assign a path to create projects
#Exports the varible and makes available the previous and the new env to all the processes. All the virtual envs are stored under ‘.virtualenvs’ folder in your home directory
- Save the above file and run these commands
#Load your ~/.bash_profile with the new changes.
- Now that all the paths and directories are created and set, you can create your virtual environments. Simply use –
#This creates a virtual env with the name of the project under ~/.virtualenvs directory and also create the project directory with the same name under $PROJECT_HOME. Since we are using the virtualenvwrapper functions, upon creation, it will activate the virtual env and ‘cd’ into the project folder
- To deactivate the virtualenv type ‘deactivate’ at the prompt
- If you want to know more about the virtualenvwrapper commands go to – http://docs.python-guide.org/en/latest/dev/virtualenvs/