Skip to content

Latest commit

 

History

History
182 lines (125 loc) · 4.47 KB

docker_essentials.md

File metadata and controls

182 lines (125 loc) · 4.47 KB

Docker

Install

  1. Download
  2. (Opt) Install visual studio code, bash-completion (can be installed with brew then link installing bash completion given in docker doc)
  3. Dockers automated script to add repository and install all dependencies in Linux
$ curl -sSL https://get.docker.com/ | sh
$ sudo usermod -aG docker $UserName
  1. Install docker-machine, docker-compose
  2. Install docker in visual studio code (in mac put the application/visual.../bin in your .bash_profile)
  3. Do code . from the folder of docker user folder (i.e. place with your codes that you want to create an image file)
  4. For windows 10 pro/ent you can use docker (go to 1, use powershell, use docker version) otherwise only Docker Toolbox available (see 5)
  5. You can install posh-docker (see docker docs for details, this is just auto-completion for docker commands, extra tools: Cmder.net, download and extract to run (unblock before zipping)-->docker machine env default--> copy and paster last line)
  6. Win7/8/10 home: Runs tiny linux VM in virtualBox via docker-machine (go to store and click on Dockertoolbox --> check all options)
  7. You can shutdown VM and then change settings (like memory) or docker-machine ls (/start/stop etc...)
  8. Make sure the code in C:\Users only (Bind Mounts)
  9. docker run hello-world

Container and image

  • Image: build in binaries that we want to run -
  • Container: is an instance of the image running as a process (can be many of the same image)
  • Docker Hub (hub.docker.com): default image registry (a remote image repository)
  • Docker is actually a process in host machine rather than a Virtual Machine

Example

Using image ngnix

$ docker container run --publish 80:80 nginx
  • once running, open your browser and type: localhost and enter
  • To run in background
$ docker container run --publish 80:80  --detach --name $yourpreferredName nginx
$ docker container logs $yourpreferredName`
$ docker top $yourpreferredName
To stop: 
$ docker container stop first 3 nos of containerID (docker container ls -a should show exited)
To remove container:
$ docker container rm -f 3digits

write your container file (Dockerfile Link)

	FROM ubuntu:14.04
    RUN apt-get update
    RUN apt-get install -y curl

build

$ docker build -t myfirstdocker:latest . 

---> Create image using this directory's Dockerfile

See the list of containers

$ docker container ls -a

bind volumes link

	$ docker run -d \
  		--name=nginxtest \
 		-v nginx-vol:/usr/share/nginx/html \
  		myFirstDocker:latest

run

$ docker run -p 4000:80 myfirstdocker:latest 

--> Run "myfirstdocker:latest" mapping port 4000 to 80

$ sudo docker run -ti --rm myfirstdocker:latest  /bin/bash

register and run `

$ docker push username/repository:tag  
  • Upload tagged image to registry
$ docker run username/repository:tag  
  • Run image from a registry

Docker push step-by-step

see here

remove/stop

$ docker container rm <hash>
$ docker image rm <image id> 
  • Removes all:
$ docker container rm $(docker container ls -a -q) 
$ docker image rm $(docker image ls -a -q)
  • Forcefull:
$ docker container rm -f $(docker container ls -a -q) 
  • stop
$ docker stop $(docker ps -a -q)

GUI

open -a XQuartz

In the XQuartz preferences, go to the “Security” tab and make sure you’ve got “Allow connections from network clients” ticked:

ip=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}') xhost + $ip

-e DISPLAY=$ip:0 -v /tmp/.X11-unix:/tmp/.X11-unix

plugins

docker run -it -v /tmp/.X11-unix:/tmp/.X11-unix:rw -e DISPLAY=unix$DISPLAY --device /dev/dri --privileged ubuntu

Then

apt update && apt install --no-recommends -y nvidia-340 mesa-utils && glxgears

Dockerhub

$ docker tag firstimage YOUR_DOCKERHUB_NAME/firstimage
$ docker push YOUR_DOCKERHUB_NAME/firstimage
$ docker login 
username: xxx (e.g, sharibox)
password: xxxxx