Safdar Mirza @ Cloud

Stack

Services

Containers:

Dockerfile:

Dockerfile defines what goes on in the environment inside your container. Access to resources like networking interfaces and disk drives is virtualized inside this environment, which is isolated from the rest of your system, so you need to map ports to the outside world, and be specific about what files you want to “copy in” to that environment. However, after doing that, you can expect that the build of your app defined in this Dockerfile behaves exactly the same wherever it runs.

 

$ docker --version

Docker version 18.03, build c97c6d6

$ docker-compose --version

docker-compose version 1.21.0, build 8dd22a9

$ docker-machine --version

docker-machine version 0.14.0, build 9ba6da9

 

## List Docker CLI commands
docker
docker container --help

## Display Docker version and info
docker --version
docker version
docker info

## Execute Docker image
docker run hello-world

## List Docker images
docker image ls

## List Docker containers (running, all, all in quiet mode)
docker container ls
docker container ls --all
docker container ls -aq

## Stop a container
docker container ls # get CONTAINER ID
docker container stop <CONTAINER ID>

## Remove all containers
docker rm $(docker ps -a -q)


Docker Cheat Sheet

Here is a list of some basic Docker Commands to help you get started with Docker. This helped me a lot and still does from time to time. Note, this not meant to be a complete Docker reference. For complete list, please visit docs.docker.com

Containers

Pull a base image.
docker pull ubuntu

Start a container
docker run --name docker-nginx -p 80:80 -d nginx
docker run --name docker-nginx -p 80:80 -d -v /app/html:/usr/share/nginx/html nginx

For list of running containers
docker ps

For list of all containers
docker ps - a

Restart a Container.
docker restart container_id

Show all running process in a Container.
docker top container_id

Stop container
docker stop container_id

Remove container
docker rm container_id>

Kill containers and remove them
docker stop $(docker ps -aq)
docker rm $(docker ps -aq)
docker rm $(docker kill $(docker ps -aq))

Clean up old containers that are weeks old (via Stackoverflow)
docker ps --filter "status=exited" | grep 'weeks ago' | awk '{print $1}' | xargs --no-run-if-empty docker rm

Print the last 100 lines of a container’s logs 
docker logs --tail 100 container_id

Create a new bash process inside the container and connect it to the terminal
docker exec -it container_id bash

Docker Container link
Docker run -d -p 5000:5000 --link redis dockerapp:v0.3

Docker Images

Remove all images
docker rmi $(docker images -q) -f
docker rmi $(docker images -qf "dangling=true")

Remove all images except “my-image”
You could use grep to remove all except my-image and ubuntu
docker rmi $(docker images | grep -v ‘ubuntu\|my-image’ | awk {‘print $3’})

Save a running container as an image
docker commit -m "commit message" -a "author" container_id username/image_name:tag

Other Docker Commands

Run commands inside an existing container
docker exec -it [containerID] bash

Push to Images to Docker
docker tag 2f98ca2e63ab docker-nginx:1.01
docker login --username muralibala
docker push docker-nginx:1.01

To find Ip address
docker machine ls

List the networks
docker network ls

List the volumes
docker volume ls



Google - GCP Tricks - How to ... 

 

Setup VPN connectivity via the Direct Connect to GCP (Firewalled one way initiated traffic from on-prem to GCP)

Folder / Project structure create via best practice.

2 factor authentication to GCP console.

Enable SSO to local AD or NIS. 

Disable API access via chrome to Google storage.

Secure GCP org, internet via firewall.  Shared VPC for most projects, that disables direct internet access. Setup proxy for permitted internet access by ip / port / dest URL.

Setup an example of syncing a GCP storage bucket to an internal filesystem

Help in editing an existing condor template to customize a condor pool startup. Advise on an autobuild of OS image via internal puppet setup.

 


https://cloud.google.com/sdk/docs/quickstart-linux

 

Tutorials

Here are some links to help you get started with Google Cloud Platform services.

 

Read the Google Cloud Platform documentation on Google Compute Engine.

Read about Google Cloud Platform Virtual Private Cloud (VPC).

 

 

Docker Container: 

  • Container can start in seconds.
  • Container use few resources space/memory.
  • Container is a running instance of an image.
  • Image is a template.
  • Image contains OS, Software, Application all bundle up in a file.
  • Image is define using a docker file which is just a text file that contains list of step that are required to create the image. For example: configure OS install software, copy project files. 

Docker File -> Image -> Container

 

Install Docker 

Downlaod Docker for Mac:
https://docs.docker.com/docker-for-mac/

Download Docker for Windows:
https://docs.docker.com/docker-for-windows/

https://store.docker.com

check if docker is installed. 

$ docker --version

$ docker-compose --version

$ docker-machine --version

 

Open a command-line terminal and test that your installation works by running the simple Docker image, hello-world:

$ docker run hello-world

 

Check Version:

 

To try something more ambitious, you can run an Ubuntu container with:

 $ docker run -it ubuntu bash

 

 

Docker Related Links:

https://docs.docker.com