elidiazgt
12/5/2016 - 6:39 PM

cheatsheet - docker

DOCKER

#inside docker
#create cache for install
apt-get -qq update
#install curl
apt-get -qq -y install curl






#instalar docker-compose
pip install -U docker-compose
#dar permisos
chmod +x /usr/local/bin/docker-compose
#correr archivo dentro de carpeta
sudo docker-compose up


Docker run <image> <command> ---start a new container
-i -- interactive
-t -- pseudo tty
-v <hostdir>:<dockerdir> -- mount host volume
-p <h-port>:<d-port> -- forward host port tot docker port

Stop, start, restart, rm, logs, top, diff, port

Docker ps -- show running containers
Docker inspect -- show all info on a container
nsenter -- attach tot container

Docker images --- list images
Docker build -- create from dockerfile
Docker commit -- create from container

Big cheatsheet: https://github.com/wsargent/docker-cheat-sheet




Commands:

**attach**
    Attach to a running container

**build**
    Build an image from a Dockerfile

**commit**
Create a new image from a containers changes

**cp**        Copy files/folders from a container's filesystem to the host path
**diff**      Inspect changes on a container's filesystem
**events**    Get real time events from the server
**export **   Stream the contents of a container as a tar archive
**history  ** Show the history of an image
**images    **List images
**import    **Create a new filesystem image from the contents of a tarball
**info      **Display system-wide information
**inspect   **Return low-level information on a container
**kill **     Kill a running container
**load**      Load an image from a tar archive
**login **    Register or log in to a Docker registry server
**logout  **  Log out from a Docker registry server
**logs**      Fetch the logs of a container
**port  **    Lookup the public-facing port that is NAT-ed to PRIVATE_PORT
**pause   **  Pause all processes within a container
**ps**        List containers
**pull**      Pull an image or a repository from a Docker registry server
**push**      Push an image or a repository to a Docker registry server
**restart**   Restart a running container
**rm**        Remove one or more containers
**rmi **      Remove one or more images
**run**       Run a command in a new container
**save **     Save an image to a tar archive
**search **   Search for an image on the Docker Hub
**start **    Start a stopped container
**stop**      Stop a running container
**tag **      Tag an image into a repository
**top **      Lookup the running processes of a container
**unpause**   Unpause a paused container
**version**   Show the Docker version information
**wait **     Block until a container stops, then print its exit code



Docker Pull

sudo docker pull :

download a docker image from the docker registry
###Docker Images (List Images)


sudo docker images :

list all of the locally downloaded images

##Docker Run

sudo docker run –i –t repo_name command_to_run : run a docker image interactively with a certain command and jump into the running container.

Repo_name = [docker_username]/[docker_image_name]. Command_to_run = the command to be run in the interactive docker container, commonly we use the /bin/bash command.

Docker ps -a (List Containers)
sudo docker ps –a : list all of the local Docker containers (that were previously executed with a Run command)
Docker Commit (Save Changes Locally)
sudo docker commit container_id image_name : commit changes made to a local docker container to save any changes made locally.
The container_id can be found from the above sudo docker ps –a command. The image_name is the name of the local image where this change should be applied, this is the same format as the repo_name above.

Docker Push (Save Updated Image in Docker Registry)
sudo docker push repo_name : push all locally committed changes to the docker registry and update the docker image specified by the repo_name with the changes.
Repo_name = [docker_username]/[docker_image_name]

Docker Stop
sudo docker stop $(sudo docker ps –a -q) : stop all locally running docker containers
Docker rm (Remove/Delete Docker Containers or Images)
sudo docker rm $(sudo docker ps –a -q) : remove/delete all local docker containers
sudo docker rm $(sudo docker images -q) : remove all docker images from your local machine



#levantar imagen
sudo docker run -i -t 0dce125def8f

#iniciar contenedor
sudo docker start -a ae02195b07e0
sudo docker start -a │e2a5f065415d

#container id
7cd272f70cff

#maquinas corriendo
sudo docker ps

#todas las maquinas
sudo docker ps -a

#port
7cd272f70cff
image
0dce125def8f:latest
desperate_wright


#save changes locally
sudo docker commit 7cd272f70cff ant_installed

sudo docker images --tree

#create compress image file
sudo docker save e2a5f065415d > /home/developer/Documents/docker_save_(date +"%Y-%m-%d_%H.%M.%S").tar

#minimize
sudo docker export e2a5f065415d > /home/developer/Documents/docker_export_(date +"%Y-%m-%d_%H.%M.%S").tar

dockerbase/android:latest
sudo docker run -i -t dockerbase/android
sudo docker commit e2a5f065415d native_installed