Skip to content

Instantly share code, notes, and snippets.

@ealipio
Last active August 19, 2019 04:15
Show Gist options
  • Save ealipio/f875ac0286e0962560816c931e529b63 to your computer and use it in GitHub Desktop.
Save ealipio/f875ac0286e0962560816c931e529b63 to your computer and use it in GitHub Desktop.

docker

docker run ubuntu # download the image and run it
docker pull ubuntu # download the image only
# ----------------------------------------------------
docker ps   # list all running containers only     
docker ps -a  # list all containers
# ----------------------------------------------------
docker stop <container ID | name> # stops docker container
docker kill <container ID | name>
# ----------------------------------------------------
docker rm <container ID | name> # remove container from disk
docker images # list of images
docker image ls # list of images
docker rmi <imageID> # remove image if no dependent containers
 
## appending commands
docker run ubuntu sleep 100 # sleep for 100 seconds
docker exec <container ID | name> cat /etc/hosts

$ find /etc -iname "*release*"

# i: interactive, t: terminal
docker run -ti ubuntu /bin/bash
# for ubuntu only, by default include CMD["/bin/bash"]
docker run -ti ubuntu 

attach or detach

docker run -d ubuntu sleep 500 # sleep for 5s in detach mode
docker attach <container ID>   # attaching back to terminal

docker run -p 49160:8080 -d eisson/node-app 

# then go http://localhost:49160 in your host.
# the container will keep that configuration until you do
# docker rm <containerID>
----------------------------------------------------------
docker exec -it <container id> /bin/bash

eisson@eisson:~$ docker run -p 80:8080 -d eisson/node-app
92612fd1086dd197e8c480358e88a56f78b38d86a91
eisson@eisson:~$ docker exec -it 92612 /bin/bash
root@92612fd1086d:/usr/src/simple-node-app#

logs

docker logs <containerID>

remove container after run

docker run --rm ubuntu cat /etc/hosts

stats and process

docker stats [container id or name]
docker top [container id or name]

docker volumes mapping

docker run -v /opt/datadir:/var/lib/mysql mysql

:::::: docker compose :::::

docker-compose up
docker-compose down

kubernetes:

kubectl run hello-minukube
kubectl cluster-info
kubectl get nodes
kubectl get services

pod-definition.yml

apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
    type: front-end
spec:
  containers:
  - name: nginx-container
    image: nginx
eisson@master:~ $ kubectl create -f pod-definition.yml

After create pods, let's dive into it

eisson@master:~$ kubectl get pods
NAME                    READY   STATUS    RESTARTS   AGE
myapp-pod               1/1     Running   0          2m31s
nginx-dbddb74b8-wsvdh   1/1     Running   0          26m
eisson@master:~$ kubectl describe pods
eisson@master:~$ kubectl describe pod myapp-pod
docker run -d --name=redis redis
docker run -d --name=db postgres:9.4
docker run -d --name=vote -p 5000:80 --link redis:redis voting-app
docker run -d --name=result -p 5001:80 --link db:db result-app
docker run -d --name=worker --link db:db --link redis:redis worker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment