Category: Uncategorized

Docker Cheat Sheet

No Comments

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 –

  1. docker –help – Displays help menu
  2. docker –version  –  Displays docker version
  3. docker version –  Displays docker version for both Docker client and daemon
  4. docker image ls -a – Displays a list of all Docker images
  5. docker container ls -a – Display a list of all Docker containers
  6. docker rm $(docker ps -a -q)  – Removes all Docker containers in quiet mode
  7. docker rmi -f $(docker images -q) – Removed all Docker images in quiet mode

  8. docker run -it helloworld/1.0 sh – Propmts a shell to view the contents of Docker image

  9. 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

  10. 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

  11. docker login – Authenticates a user to the cloud Docker public/private repository
  12. docker tag helloworld:1.0  username/myrepo:1.0 – Tag a local image to specific docker repository and the user

  13. docker push crkatz/myrepo:1.0 – Pushes the tagged image to the docker public or private repository

  14. docker container logs [OPTIONS] CONTAINERID – Tails the logs of the Docker container

 

 

Categories: Containerization, DevOps, Uncategorized Tags: Tags:

Set up Python Virtual Envs

No Comments

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.

  1. 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
  2. Python packages required – virtualenv, virtualenvwrapper.
    pip3 install virtualenv virtualenvwrapper  #pip3 is using python3 interpretor
  3. 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.
  4. Add the below lines to the ~/.bash_profile


    #tells which interpretor to use. In this case ‘python3’

    VIRTUALENVWRAPPER_PYTHON=’/usr/local/bin/python3′
    #set the env variable and assign a path to create projects

    PROJECT_HOME=’/Users/chetanak/Box Sync/Projects’

    #reload script
    source /usr/local/bin/virtualenvwrapper.sh

    #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
    export WORKON_HOME=$HOME/.virtualenvs

  5. Save the above file and run these commands

    mkdir ~/.virtualenvs

    #Load your ~/.bash_profile with the new changes.
    source ~/.bash_profile

  6. Now that all the paths and directories are created and set, you can create your virtual environments. Simply use –

    mkproject <projectname>

    #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

  7. To deactivate the virtualenv type ‘deactivate’ at the prompt
  8. If you want to know more about the virtualenvwrapper commands go to – http://docs.python-guide.org/en/latest/dev/virtualenvs/

Read More